-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPartialModel.cpp
More file actions
95 lines (87 loc) · 2.07 KB
/
PartialModel.cpp
File metadata and controls
95 lines (87 loc) · 2.07 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "PartialModel.hpp"
#include "aux.hpp"
#include "odds.hpp"
using namespace std;
namespace PoissonFactorization {
namespace Partial {
string to_string(Variable variable) {
switch (variable) {
case Variable::Feature:
return "Feature";
break;
case Variable::Mix:
return "Mix";
break;
case Variable::Spot:
return "Spot";
break;
case Variable::Experiment:
return "Experiment";
break;
default:
throw std::logic_error("Implementation of to_string(Kind) incomplete!");
break;
}
}
string to_string(Kind kind) {
switch (kind) {
case Kind::Constant:
return "Constant";
break;
case Kind::Dirichlet:
return "Dirichlet";
break;
case Kind::Gamma:
return "Gamma";
break;
case Kind::HierGamma:
return "HierGamma";
break;
default:
throw std::logic_error("Implementation of to_string(Kind) incomplete!");
break;
}
}
std::ostream &operator<<(std::ostream &os, Variable variable) {
os << to_string(variable);
return os;
}
std::ostream &operator<<(std::ostream &os, Kind kind) {
os << to_string(kind);
return os;
}
std::istream &operator>>(std::istream &is, Variable &variable) {
string token;
is >> token;
token = to_lower(token);
if (token == "feature")
variable = Variable::Feature;
else if (token == "mix")
variable = Variable::Mix;
else if (token == "spot")
variable = Variable::Spot;
else if (token == "experiment")
variable = Variable::Experiment;
else
throw(std::runtime_error("Cannot parse variable type '" + token + "'."));
return is;
}
std::istream &operator>>(std::istream &is, Kind &kind) {
string token;
is >> token;
token = to_lower(token);
if (token == "constant")
kind = Kind::Constant;
else if (token == "dirichlet")
kind = Kind::Dirichlet;
else if (token == "gamma")
kind = Kind::Gamma;
else if (token == "hiergamma")
kind = Kind::HierGamma;
else
throw(
std::runtime_error("Cannot parse distribution type '" + token + "'."));
return is;
}
}
}