File: extract.cc

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 (62 lines) | stat: -rw-r--r-- 2,106 bytes parent folder | download
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
#define XERR
#include "distribution.ih"

    // So far the extraction has extracted the mean. Next comes the stddev and
    // dist, but stddev may not be present -> dist is not present
    //     #               mean    stddev  dist
    //     specificity:    99.2    .076    Normal
    //
    // for Beta destributions, used with LC, the name and parameters of the
    // Beta distribution are provided, which are used when parameter spread
    // is configured
    //
    // # LC:    eta   beta     dist    constant factor   aParam    bParam
    // male:    -1.4   .32     Beta    .234091  1.72727  2.664237  5.184883
    // female:  -1.4  1.40     Beta    .744828   .818966 3.366115  4.813548

    // the Distribution is extracted if d_confValue is present.
    // if present it must be >= 0

istream &Distribution::extract(istream &in)
{
    if (not Globals::vary())        // no parameter variation -> no
        return in;                  // distribution extraction

    string next;                    // inspect the next field on 'in'

                                    // try extracting the SD parameter
    if (not (in >> next))           // nothing is extracted, so this is not
    {                               // a Beta dist. spec, or a dist. w/o SD
        d_distType = NORMAL_VARY;
        prepareVary(in);            // in: unused here
        in.clear();
        return in;
    }

    if (next == "Beta")             // this is a Beta distribution
    {
        d_distType = BETA_VARY;
        Random::instance().prepareBeta(in);
        d_value = &Distribution::varyBeta;
        return in;
    }

    d_confValue = stod(next);       // no beta, so it must be a value
    if (d_confValue < 0)
    {
        Err::msgTxt(Err::NEGATIVE);
        in.setstate(ios::failbit);
        return in;
    }
                // value was extracted: the distribtion name must be next
    if (in >> next and (d_distType = find(next)) != N_DISTRIBUTIONS)
    {
        prepareVary(in);
        return in;
    }

    Err::msgTxt(Err::UNDEFINED_DIST);
    in.setstate(ios::failbit);

    return in;
}