File: distribution.h

package info (click to toggle)
simrisc 16.06.00-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,568 kB
  • sloc: cpp: 6,889; fortran: 669; makefile: 112; ansic: 112; sh: 107
file content (80 lines) | stat: -rw-r--r-- 2,942 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#ifndef INCLUDED_DISTRIBUTION_
#define INCLUDED_DISTRIBUTION_

#include <iosfwd>
#include <cmath>

#include "../typedefs/typedefs.h"

    // The Distribution receives the spread value and distribution name,
    // Either both or none most be specified. If none is specified then
    // spread = 0, and calling vary() simply returns the received argument

class Distribution
{
    enum
    {
        MAX_VARY_TRIES = 10, // max #attempts to obtain a valid varied value
    };

    friend std::istream &operator>>(std::istream &in, Distribution &dist);
    friend std::ostream &operator<<(std::ostream &out,
                                             Distribution const &dist);

    double      d_confValue = 0;                // configured (e.g., SD) value
    DistType    d_distType = N_DISTRIBUTIONS;   // with, e.g., vectors

                                            // points to the function handling
                                            // the random value variation (the
                                            // vary*/accept functions below)
    double (Distribution::*d_value)(double orgValue) const;

    bool d_exp;

    static StringVect s_name;
    static unsigned s_width;
    static unsigned s_precision;

    static double (Distribution::*s_varyParam[])(double orgValue) const;

    public:
        Distribution(VaryType varyType);

                                                // returns N_DISTRIBUTIONS if
                                                // an undefined name is used
        static DistType find(std::string const &distName);

                                                // intWidth: width of the
                                                // integral part
        static void fmt(unsigned intWidth, unsigned precision);

        void ln();                              // ln(d_confValue)          .f

        DistType type() const;                                          //  .f

        double value(double orgValue) const;    // return varied value (if  .f
                                                // s_vary) or orgValue or
                                                // throw an exception

                                                // must succeed or err
        static DistType xlat(LineInfo const &lineInfo,
                         std::string const &distName);

        static std::string const &name(DistType dist);

    private:
        std::istream &extract(std::istream &in);
        std::ostream &insert(std::ostream &out) const;

        void prepareVary(std::istream &in);         // -> extract()

        double varyMean(double orgValue) const;     // these members are
        double varyNonNeg(double orgValue) const;   // called via d_value
        double varyProb(double orgValue) const;
        double varyBeta(double orgValue) const;
        double accept(double orgValue) const;       // if not s_vary
};

#include "distribution.f"

#endif