[4634c7]: src / modules / glm / samplers / GLMFactory.h  Maximize  Restore  History

Download this file

119 lines (111 with data), 4.2 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
#ifndef GLM_FACTORY_H_
#define GLM_FACTORY_H_
#include "GLMMethod.h"
#include <sampler/SamplerFactory.h>
namespace jags {
class LinkNode;
class SingletonGraphView;
namespace glm {
/**
* @short Abstract factory for GLM samplers
*
* All factory objects for samplers that handle generalized linear
* models (GLMs) must recognize the same basic structures in the
* graph. They differ only by the allowed link function(s) and
* outcome distribution(s) for the GLM, and the update methods
* that they use for sampling.
*/
class GLMFactory : public SamplerFactory
{
std::string _name;
SingletonGraphView * makeView(StochasticNode *snode,
Graph const &graph) const;
bool checkDescendants(SingletonGraphView const *view) const;
public:
GLMFactory(std::string const &name);
virtual ~GLMFactory();
/**
* Creates a newly-allocated Sampler for the set of candidate nodes,
* or a NULL pointer. Sub-classes of GLMFactory only have to
* implement the abstract member function newMethod.
*/
Sampler * makeSampler(std::set<StochasticNode*> const &nodes,
Graph const &graph) const;
/**
* Wraps GLMFactory#makeSampler and returns a single
* newly-allocated sampler in a vector.
*/
std::vector<Sampler*>
makeSamplers(std::set<StochasticNode*> const &nodes,
Graph const &graph) const;
/**
* Checks that an outcome variable in a GLM has the correct
* family and link function.
*
* @param snode Stochastic node representing an outcome variable
*/
virtual bool checkOutcome(StochasticNode const *snode) const = 0;
/**
* Function for returning a newly allocated GLMMethod. This
* is called by GLMFactory#makeSampler
*
* @param view Pointer to a GraphView object for all sampled nodes.
*
* @param sub_views Vector of pointers to SingletonGraphView
* objects with length equal to the number of sampled
* nodes. Each sub-view corresponds to a single sampled node.
*
* @param chain Number of the chain (starting from 0) to which
* the sampling method will be applied.
*/
virtual GLMMethod *
newMethod(GraphView const *view,
std::vector<SingletonGraphView const *> const &sub_views,
unsigned int chain) const = 0;
/**
* Virtual function for checking that that a candidate
* stochastic node is suitable for sampling. Currently, we
* assume that all candidate nodes have a normal distribution:
* this does not need to be checked by canSample. However,
* some sampling methods have restrictions on which nodes can
* be sampled, e.g. they must be unbounded, or scalar. Such
* restrictions must be coded in the canSample function.
*/
virtual bool canSample(StochasticNode const *snode) const = 0;
/**
* Returns the string provided as the parameter "name" in the
* constructor.
*/
std::string name() const;
/**
* Returns true if the factory can only work with outcome
* variables that are observed. The default implementation
* returns false.
*
* If a sampling method uses auxiliary variables, then
* generally it cannot work with unobserved outcomes. With
* auxiliary variable sampling the observed outcome is
* considered to be a deterministic function of the auxiliary
* variables. When an unobserved outcome variable is updated
* (by a sampling method independent of this one) it may be
* inconsistent with the current values of the auxiliary
* variables, leaving them in an invalid state. An exception
* is when the auxiliary variables can be sampled directly,
* without reference to the current values.
*/
virtual bool fixedOutcome() const;
/**
* Returns true if the factory can only work on a GLM with a
* fixed design matrix (i.e. one that does not change between
* iterations) and false otherwise. GLMs with variable design
* matrices occur in the context of missing data and
* measurement error models. The default implementation
* returns false.
*
* Note that the same restrictions as for the fixedOutome
* function apply for auxiliary variables.
*/
virtual bool fixedDesign() const;
};
}}
#endif /* GLM_FACTORY_H_ */

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

Sign up for the SourceForge newsletter:





No, thanks