[4634c7]: src / modules / glm / samplers / BinaryFactory.cc Maximize Restore History

Download this file

BinaryFactory.cc    83 lines (69 with data), 1.9 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
#include <config.h>
#include <string>
#include "BinaryFactory.h"
#include "Linear.h"
#include "NormalLinear.h"
#include "BinaryProbit.h"
#include "BinaryLogit.h"
#include <graph/StochasticNode.h>
#include <graph/LinkNode.h>
#include <distribution/Distribution.h>
#include <module/ModuleError.h>
#include <sampler/SingletonGraphView.h>
using std::string;
using std::vector;
namespace jags {
namespace glm {
BinaryFactory::BinaryFactory(string const &name, bool gibbs)
: GLMFactory(name), _gibbs(gibbs)
{}
bool BinaryFactory::checkOutcome(StochasticNode const *snode) const
{
return (BinaryProbit::canRepresent(snode) ||
BinaryLogit::canRepresent(snode) ||
NormalLinear::canRepresent(snode));
}
GLMMethod *
BinaryFactory::newMethod(GraphView const *view,
vector<SingletonGraphView const *> const &subviews,
unsigned int chain) const
{
bool linear = true;
vector<Outcome*> outcomes;
for (vector<StochasticNode *>::const_iterator p = view->stochasticChildren().begin();
p != view->stochasticChildren().end(); ++p)
{
Outcome *outcome = 0;
if (NormalLinear::canRepresent(*p)) {
outcome = new NormalLinear(*p, chain);
}
else if (BinaryProbit::canRepresent(*p)) {
outcome = new BinaryProbit(*p, chain);
linear = false;
}
else if (BinaryLogit::canRepresent(*p)) {
outcome = new BinaryLogit(*p, chain);
linear = false;
}
else {
throwLogicError("Invalid outcome in BinaryFactory");
}
outcomes.push_back(outcome);
}
if (linear) {
return new Linear(view, subviews, outcomes, chain, _gibbs);
}
else {
return newBinary(view, subviews, outcomes, chain);
}
}
bool BinaryFactory::canSample(StochasticNode const *snode) const
{
if (_gibbs) {
return snode->length() == 1;
}
else {
return !isBounded(snode);
}
}
}}