[50073b]: src / modules / bugs / samplers / ConjugateFactory.cc  Maximize  Restore  History

Download this file

170 lines (158 with data), 4.0 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
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#include <config.h>
#include "ConjugateFactory.h"
#include "ConjugateNormal.h"
#include "ConjugateGamma.h"
#include "ConjugateBeta.h"
#include "ConjugateDirichlet.h"
#include "ConjugateMNormal.h"
#include "ConjugateWishart.h"
//#include "Censored.h"
//#include "TruncatedGamma.h"
#include "ShiftedCount.h"
#include "ShiftedMultinomial.h"
#include <graph/StochasticNode.h>
#include <distribution/Distribution.h>
#include <sampler/SingletonGraphView.h>
#include <module/ModuleError.h>
#include <sampler/ImmutableSampler.h>
#include <string>
using std::string;
namespace jags {
namespace bugs {
bool ConjugateFactory::canSample(StochasticNode * snode,
Graph const &graph) const
{
/*
if (Censored::canSample(snode, graph))
return true;
*/
bool ans = false;
switch(getDist(snode)) {
case NORM:
ans = ConjugateNormal::canSample(snode, graph);
break;
case GAMMA: case CHISQ:
ans = ConjugateGamma::canSample(snode, graph);
break;
case EXP:
ans = ConjugateGamma::canSample(snode, graph) ||
ConjugateNormal::canSample(snode, graph);
break;
case BETA:
ans = ConjugateBeta::canSample(snode, graph);
break;
case DIRCH:
ans = ConjugateDirichlet::canSample(snode, graph);
break;
case MNORM:
ans = ConjugateMNormal::canSample(snode, graph);
break;
case WISH:
ans = ConjugateWishart::canSample(snode, graph);
break;
case UNIF:
/*
ans = TruncatedGamma::canSample(snode, graph) ||
ConjugateBeta::canSample(snode, graph);
*/
ans = ConjugateBeta::canSample(snode, graph);
break;
case POIS: case BIN: case NEGBIN:
ans = ShiftedCount::canSample(snode, graph);
break;
case MULTI:
ans = ShiftedMultinomial::canSample(snode, graph);
break;
default:
break;
}
return ans;
}
Sampler *ConjugateFactory::makeSampler(StochasticNode *snode,
Graph const &graph) const
{
SingletonGraphView *gv = new SingletonGraphView(snode, graph);
ConjugateMethod* method = 0;
string name;
/*
if (Censored::canSample(snode, graph)) {
method = new Censored(gv);
name = "Censored";
}
else {
*/
switch (getDist(snode)) {
case NORM:
method = new ConjugateNormal(gv);
name = "bugs::ConjugateNormal";
break;
case GAMMA: case CHISQ:
method = new ConjugateGamma(gv);
name = "bugs::ConjugateGamma";
break;
case EXP:
if (ConjugateGamma::canSample(snode, graph)) {
method = new ConjugateGamma(gv);
name = "bugs::ConjugateGamma";
}
else if (ConjugateNormal::canSample(snode, graph)) {
method = new ConjugateNormal(gv);
name = "bugs::ConjugateNormal";
}
else {
throwLogicError("Cannot find conjugate sampler for exponential");
}
break;
case BETA:
method = new ConjugateBeta(gv);
name = "bugs::ConjugateBeta";
break;
case DIRCH:
method = new ConjugateDirichlet(gv);
name = "bugs::ConjugateDirichlet";
break;
case MNORM:
method = new ConjugateMNormal(gv);
name = "bugs::ConjugateMNormal";
break;
case WISH:
method = new ConjugateWishart(gv);
name = "bugs::ConjugateWishart";
break;
case UNIF:
/*
if (TruncatedGamma::canSample(snode, graph)) {
method = new TruncatedGamma(gv);
name = "TruncatedGamma";
}
else
*/
if (ConjugateBeta::canSample(snode, graph)) {
method = new ConjugateBeta(gv);
name = "bugs::ConjugateBeta";
}
else {
throwLogicError("Cannot find conjugate sampler for uniform");
}
break;
case POIS: case BIN: case NEGBIN:
method = new ShiftedCount(gv);
name = "bugs::ShiftedCount";
break;
case MULTI:
method = new ShiftedMultinomial(gv);
name = "bugs::ShiftedMultiNomial";
break;
default:
throwLogicError("Unable to create conjugate sampler");
}
/*
}
*/
return new ImmutableSampler(gv, method, name);
}
string ConjugateFactory::name() const
{
return "bugs::Conjugate";
}
}}

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks