[ff1121]: src / lib / graph / VectorLogicalNode.cc  Maximize  Restore  History

Download this file

86 lines (72 with data), 2.3 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
#include <config.h>
#include <graph/VectorLogicalNode.h>
#include <function/FuncError.h>
#include <function/VectorFunction.h>
#include <graph/GraphMarks.h>
#include <graph/Graph.h>
#include <util/dim.h>
#include <stdexcept>
#include <vector>
#include <string>
#include <math.h>
using std::vector;
using std::string;
using std::set;
using std::logic_error;
namespace jags {
static unsigned int valueLength(VectorFunction const *func,
vector<Node const *> const &parents)
{
/*
Calculates length of vector logical node as a function of its
parameters.
*/
vector<unsigned int> parameter_lengths(parents.size());
for (unsigned int j = 0; j < parents.size(); ++j) {
parameter_lengths[j] = parents[j]->length();
}
if (!func) {
throw logic_error("NULL function in VectorLogicalNode constructor");
}
if (!checkNPar(func, parents.size())) {
throw FuncError(func, "Incorrect number of parameters");
}
if (!func->checkParameterLength(parameter_lengths)) {
throw FuncError(func, "Non-conforming parameters");
}
return func->length(parameter_lengths);
}
static vector<unsigned int> const &
parameterLengths(vector<Node const *> const &parameters) {
vector<unsigned int> lengths(parameters.size());
for (unsigned int j = 0; j < parameters.size(); ++j) {
lengths[j] = parameters[j]->length();
}
return getUnique(lengths);
}
VectorLogicalNode::VectorLogicalNode(VectorFunction const *function,
vector<Node const *> const &parameters)
: LogicalNode(vector<unsigned int>(1,valueLength(function, parameters)),
parameters, function),
_func(function), _lengths(parameterLengths(parameters))
{
if (isFixed()) {
for (unsigned int ch = 0; ch < _nchain; ++ch) {
deterministicSample(ch);
}
}
}
void VectorLogicalNode::deterministicSample(unsigned int chain)
{
_func->evaluate(_data + chain * _length, _parameters[chain], _lengths);
}
bool VectorLogicalNode::checkParentValues(unsigned int chain) const
{
return _func->checkParameterValue(_parameters[chain], _lengths);
}
DeterministicNode *
VectorLogicalNode::clone(vector<Node const*> const &parents) const
{
return new VectorLogicalNode(_func, parents);
}
} //namespace jags

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

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks