-
Notifications
You must be signed in to change notification settings - Fork 2
/
params.cpp
57 lines (49 loc) · 1.49 KB
/
params.cpp
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
#include "params.h"
#include <iterator>
#include <algorithm>
using namespace std;
std::ostream & operator<<(std::ostream & ost, Test const & o) {
return ost << "Test(ps=" << o.ps << ", pi=" << o.pi << ", pr=" << o.pr << ")";
}
Params::Params(shared_ptr<Proba> const & pi,
shared_ptr<Proba> const & pr,
real_t pseed,
real_t psus,
real_t pautoinf,
real_t learn_rate) :
prob_i(pi),
prob_r(pr),
pseed(pseed),
psus(psus),
pautoinf(pautoinf),
learn_rate(learn_rate)
{
if (pseed + psus > 1)
throw std::domain_error("pseed and psus are exclusive events but pseed+psus>1");
if (!pi || !pr)
throw std::invalid_argument("invalid probability definition");
}
PriorDiscrete::PriorDiscrete(Proba const & pr, int T) : Proba(T)
{
for (int t = 0; t < T; ++t) {
theta[t] = pr(t);
}
}
std::ostream & operator<<(std::ostream & ost, Params const & p)
{
return ost << "Params("
<< "prob_i=" << *p.prob_i
<< ",prob_r=" << *p.prob_r
<< ",pseed=" << p.pseed
<< ",psus=" << p.psus
<< ",pautoinf=" << p.pautoinf << ")"
<< ",learn_rate=" << p.learn_rate << ")";
}
std::ostream & operator<<(std::ostream & ost, Proba const & p) { p.print(ost); return ost; }
std::ostream & operator<<(std::ostream & ost, RealParams const & p)
{
ost << "RealParams([";
for (size_t i = 0; i < p.size(); ++i)
ost << (i ? ",":"") << p[i];
return ost << "])";
}