[c69947]: src / lib / graph / ConstantNode.cc  Maximize  Restore  History

Download this file

81 lines (66 with data), 1.7 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 <graph/ConstantNode.h>
#include <sstream>
#include <cmath>
#include <stdexcept>
using std::vector;
using std::string;
using std::ostringstream;
using std::floor;
using std::logic_error;
namespace jags {
ConstantNode::ConstantNode(double value, unsigned int nchain,
bool observed)
: Node(vector<unsigned int>(1,1), nchain), _observed(observed)
{
for (unsigned int n = 0; n < nchain; ++n) {
setValue(&value, 1, n);
}
}
ConstantNode::ConstantNode(vector<unsigned int> const &dim,
vector<double> const &value,
unsigned int nchain, bool observed)
: Node(dim, nchain), _observed(observed)
{
if (value.size() != _length) {
throw logic_error("Invalid value in ConstantNode");
}
for (unsigned int n = 0; n < nchain; ++n) {
setValue(&value[0], _length, n);
}
}
bool ConstantNode::isDiscreteValued() const
{
double const *val = value(0);
for (unsigned int i = 0; i < _length; ++i) {
if (val[i] != floor(val[i]))
return false;
}
return true;
}
void ConstantNode::deterministicSample(unsigned int) {}
void ConstantNode::randomSample(RNG*, unsigned int) {}
string ConstantNode::deparse(vector<string> const &parents) const
{
ostringstream os;
if (length() == 1) {
os << *value(0);
}
else {
os << "c(" << value(0)[0] << "..." << value(0)[length() - 1] << ")";
}
return os.str();
}
bool ConstantNode::checkParentValues(unsigned int) const
{
return true;
}
bool ConstantNode::isFixed() const
{
return true;
}
RVStatus ConstantNode::randomVariableStatus() const
{
return _observed ? RV_TRUE_OBSERVED : RV_FALSE;
}
} //namespace jags

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

Sign up for the SourceForge newsletter:





No, thanks