Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

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

Download this file

AMFactory.cc    81 lines (67 with data), 1.8 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
#include <config.h>
#include <string>
#include "BinaryFactory.h"
#include "AMFactory.h"
#include "AMMethod.h"
#include "Linear.h"
#include "AuxMixPoisson.h"
#include "AuxMixBinomial.h"
#include "NormalLinear.h"
#include <graph/StochasticNode.h>
#include <graph/LinkNode.h>
#include <distribution/Distribution.h>
#include <sampler/GraphView.h>
#include <module/ModuleError.h>
using std::string;
using std::vector;
namespace jags {
namespace glm {
AMFactory::AMFactory()
: GLMFactory("glm::Auxiliary-Mixture")
{}
bool AMFactory::checkOutcome(StochasticNode const *snode) const
{
return AuxMixPoisson::canRepresent(snode) ||
AuxMixBinomial::canRepresent(snode) ||
NormalLinear::canRepresent(snode);
}
GLMMethod *
AMFactory::newMethod(GraphView const *view,
vector<SingletonGraphView const *> const &sub_views,
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 (AuxMixBinomial::canRepresent(*p)) {
outcome = new AuxMixBinomial(*p, chain);
linear = false;
}
else if (AuxMixPoisson::canRepresent(*p)) {
outcome = new AuxMixPoisson(*p, chain);
linear = false;
}
else {
throwLogicError("Invalid outcome in BinaryFactory");
}
outcomes.push_back(outcome);
}
if (linear) {
return new Linear(view, sub_views, outcomes, chain, false);
}
else {
return new AMMethod(view, sub_views, outcomes, chain);
}
}
bool AMFactory::canSample(StochasticNode const *snode) const
{
return !isBounded(snode);
}
}}