/usr/include/JAGS/sampler/GraphView.h is in jags 4.2.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | #ifndef GRAPH_VIEW_H_
#define GRAPH_VIEW_H_
#include <vector>
#include <string>
#include <set>
namespace jags {
class StochasticNode;
class DeterministicNode;
class Node;
class Graph;
struct RNG;
/**
* @short Interface to a graph for Samplers.
*
* The GraphView class is a helper class used by a Sampler. It allows
* new values to be assigned to a vector of stochastic nodes. When
* new values are assigned, it also updates the immediate
* deterministic descendants of those nodes (see below for a
* definition). Sampling takes place in the context of a Graph,
* which must contain the sampled nodes. Any descendents of these
* nodes outside of the Graph are ignored when updating.
*
* Some terminology:
*
* The "immediate deterministic descendants" of a set of stochastic
* nodes S are the descendants of S in the graph where all stochastic
* nodes except those in S have been removed.
*
* The "marginal stochastic children" of a set of stochastic nodes S
* are the children of S in the graph where all deterministic nodes
* have been marginalized out.
*
* A vector of nodes in an acyclic Graph is in topological order if
* node B always appears after node A when there is a path from A to
* B. Note that topological order is not uniquely determined.
*/
class GraphView {
unsigned int _length;
std::vector<StochasticNode *> _nodes;
std::vector<StochasticNode *> _stoch_children;
std::vector<DeterministicNode*> _determ_children;
bool _multilevel;
void classifyChildren(std::vector<StochasticNode *> const &nodes,
Graph const &graph,
std::vector<StochasticNode *> &stoch_nodes,
std::vector<DeterministicNode*> &dtrm_nodes,
bool allow_multilevel);
public:
/**
* Constructs a GraphView for the given vector of nodes.
*
* @param nodes Vector of Nodes to be sampled
*
* @param graph Graph within which sampling is to take place. It is
* an error if this Graph does not contain all of the Nodes
* to be sampled.
*
* @param allow_multilevel Indicates whether the GraphView may be
* multilevel, i.e. some sampled nodes are stochastic
* children of other sampled nodes. Many update methods do
* not work with multi-level models so this parameter is false
* by default. If an attempt is made to create a multi-level graph
* view when the multilevel is false, a logic_error is thrown.
*/
GraphView(std::vector<StochasticNode *> const &nodes, Graph const &graph,
bool allow_multilevel=false);
/**
* Returns the vector of sampled nodes.
*/
std::vector<StochasticNode *> const &nodes() const;
/**
* Sets the values of the sampled nodes. Their immediate
* deterministic descendants are automatically updated.
*
* @param value Array of concatenated values to be applied to the
* sampled nodes.
*
* @param length Length of the value array. This must be equal to the
* sum of the lengths of the sampled nodes.
*
* @param chain Number of the chain (starting from zero) to be modified.
*/
void setValue(double const * value, unsigned int length, unsigned int chain)
const;
void setValue(std::vector<double> const &value, unsigned int chain) const;
void getValue(std::vector<double> &value, unsigned int chain) const;
/**
* Returns the total length of the sampled nodes.
*/
unsigned int length() const;
/**
* Returns the marginal stochastic children of the sampled nodes.
*/
std::vector<StochasticNode *> const &stochasticChildren() const;
/**
* Returns the immediate deterministic descendendants of the sampled
* nodes, in topological order
*/
std::vector<DeterministicNode*> const &deterministicChildren() const;
/**
* Tests whether the node depends deterministically on any of the
* sampled nodes. This function may be used by SamplerFactory
* objects to test the validity of sampling methods. For example, we
* may need to check that the mean, but not the variance of a
* stochastic child depends on the sampled nodes.
*
* @param node Node to test
*
* @return true if node is in either the vector of sampled nodes or the
* vector of deterministic children, false otherwise.
*/
bool isDependent(Node const *node) const;
/**
* Calculates the log conditional density of the sampled nodes,
* given all other nodes in the graph that was supplied to the
* constructor, plus the parents of the nodes (which may be outside
* the graph). The log full conditional is calculated up to an
* additive constant.
*
* @param chain Number of the chain (starting from zero) to query.
*/
double logFullConditional(unsigned int chain) const;
/**
* Calculates the log prior density of the sampled nodes, i.e. the
* density conditioned only on the parents.
*/
double logPrior(unsigned int chain) const;
/**
* Calculates the log likelihood, which is added to the log prior
* to give the log full conditional density
*/
double logLikelihood(unsigned int chain) const;
/**
* Checks that the log density is finite for all sampled nodes and
* all stochastic children. If any log density value is negative
* infinite a NodeError exception is thrown.
*
* This utility function should be called by the constructor of any
* sample method that needs to ensure the graph is in a valid state
* before sampling.
*/
void checkFinite(unsigned int chain) const;
};
unsigned int nchain(GraphView const *gv);
} /* namespace jags */
#endif /* GRAPH_VIEW_H_ */
|