-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtarget.cpp
More file actions
96 lines (91 loc) · 2.67 KB
/
target.cpp
File metadata and controls
96 lines (91 loc) · 2.67 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
96
#include "target.hpp"
#include <boost/tokenizer.hpp>
using namespace std;
namespace PoissonFactorization {
ostream &operator<<(ostream &os, const Target &which) {
if (which == Target::empty) {
os << "empty";
return os;
} else {
bool first = true;
if (flagged(which & Target::contributions)) {
os << "contributions";
first = false;
}
if (flagged(which & Target::phi)) {
os << (first ? "" : ",") << "phi";
first = false;
}
if (flagged(which & Target::phi_prior)) {
os << (first ? "" : ",") << "phi_prior";
first = false;
}
if (flagged(which & Target::phi_local)) {
os << (first ? "" : ",") << "phi_local";
first = false;
}
if (flagged(which & Target::phi_prior_local)) {
os << (first ? "" : ",") << "phi_prior_local";
first = false;
}
if (flagged(which & Target::theta)) {
os << (first ? "" : ",") << "theta";
first = false;
}
if (flagged(which & Target::theta_prior)) {
os << (first ? "" : ",") << "theta_prior";
first = false;
}
if (flagged(which & Target::spot)) {
os << (first ? "" : ",") << "spot";
first = false;
}
if (flagged(which & Target::baseline)) {
os << (first ? "" : ",") << "baseline";
first = false;
}
if (flagged(which & Target::field)) {
os << (first ? "" : ",") << "field";
first = false;
}
}
return os;
}
istream &operator>>(istream &is, Target &which) {
which = Target::empty;
using tokenizer = boost::tokenizer<boost::char_separator<char>>;
boost::char_separator<char> sep(",");
string line;
getline(is, line);
tokenizer tok(line, sep);
for (auto token : tok) {
if (token == "contributions")
which = which | Target::contributions;
else if (token == "features")
which = which | Target::phi | Target::phi_prior;
else if (token == "mixing")
which = which | Target::theta | Target::theta_prior;
else if (token == "phi")
which = which | Target::phi;
else if (token == "phi_prior")
which = which | Target::phi_prior;
else if (token == "phi_local")
which = which | Target::phi_local;
else if (token == "phi_prior_local")
which = which | Target::phi_prior_local;
else if (token == "theta")
which = which | Target::theta;
else if (token == "theta_prior")
which = which | Target::theta_prior;
else if (token == "spot")
which = which | Target::spot;
else if (token == "baseline")
which = which | Target::baseline;
else if (token == "field")
which = which | Target::field;
else
throw(runtime_error("Unknown sampling token: " + token));
}
return is;
}
}