GClasses
GClasses::GBNCategorical Class Reference

Detailed Description

A node in a belief network that represents a categorical distribution. Instances of this class can serve as parent-nodes to any GBNVariable node. The child node must specify distribution parameters for every category that the parent node supports (or for every combination of categories if there are multiply categorical parents).

#include <GBayesianNetwork.h>

Inheritance diagram for GClasses::GBNCategorical:
GClasses::GBNVariable GClasses::GBNNode

Public Member Functions

 GBNCategorical (size_t categories, GBNNode *pDefaultWeight)
 General-purpose constructor. All of the categories will initially be given a weight of pDefaultWeight. Typically, you will want to change these (by calling setWeights) after you construct a node. More...
 
virtual ~GBNCategorical ()
 
virtual void addCatParent (GBNCategorical *pNode, GBNNode *pDefaultVal)
 Adds a categorical node as a parent of this node. Calling this method will cause This node to resize its table of distribution parameters, so a default value is required to fill in new elements. Typically, you will set these new elements to something more meaningful (by calling setWeights) after you call this method. More...
 
size_t categories ()
 Returns the number of categories supported by this distribution. More...
 
virtual double currentValue ()
 Returns the most recent value sampled from this node. More...
 
virtual double likelihood (double x)
 Computes the likelihood that the specified value (after being truncated to an integer) would be drawn from this categorical distribution given the current values of all the parent nodes of this class. More...
 
virtual void sample (GRand *pRand)
 Draws a new Gibbs sample for this node given the current values of all other nodes it its Markov blanket. More...
 
void setWeights (size_t cat, GBNNode *pW1, GBNNode *pW2, GBNNode *pW3=NULL, GBNNode *pW4=NULL, GBNNode *pW5=NULL, GBNNode *pW6=NULL, GBNNode *pW7=NULL, GBNNode *pW8=NULL)
 Set the weights for one of the categorical distributions of this node. If there are n categories in this node, then the first n parameters should be non-NULL. "cat" specifies the index of the combination of values (in little-endian order) in the categorical parent distributions for which this categorical distribution is being specified. More...
 
- Public Member Functions inherited from GClasses::GBNVariable
 GBNVariable ()
 
virtual ~GBNVariable ()
 
size_t catCount ()
 Returns the total number of combinations of categorical values supported by the categorical parents of this node. This node is expected to specify a distribution for each of these categorical combinations. More...
 
const std::vector< GBNVariable * > & children ()
 Returns all nodes that are known to depend on this one. More...
 
size_t currentCatIndex ()
 Queries the categorical parent nodes to determine their current values, and combines them to produce a single index value that is unique for this combination of categorical values. The value this returns will be from 0 to catCount()-1. The values are organized in little-endian manner. That is, it cycles through all values supported by the first categorical parent before moving on to the next value of the next parent. More...
 
virtual void onNewChild (GBNVariable *pChild)
 This method links back to the child node that just added this node as a parent. More...
 
void setObserved (double value)
 Set this node to an observed value. After calling this, subsequent calls to sample will not change its value. More...
 
void setUnobserved ()
 Set this node to an unobserved value. After calling this, subsequent calls to sample will draw new values for this node. More...
 
- Public Member Functions inherited from GClasses::GBNNode
 GBNNode ()
 
virtual ~GBNNode ()
 

Protected Attributes

size_t m_categories
 
size_t m_val
 
std::vector< GBNNode * > m_weights
 
- Protected Attributes inherited from GClasses::GBNVariable
std::vector< GBNCategorical * > m_catParents
 
std::vector< GBNVariable * > m_children
 
- Protected Attributes inherited from GClasses::GBNNode
bool m_observed
 
double m_observedValue
 

Constructor & Destructor Documentation

GClasses::GBNCategorical::GBNCategorical ( size_t  categories,
GBNNode pDefaultWeight 
)

General-purpose constructor. All of the categories will initially be given a weight of pDefaultWeight. Typically, you will want to change these (by calling setWeights) after you construct a node.

virtual GClasses::GBNCategorical::~GBNCategorical ( )
inlinevirtual

Member Function Documentation

virtual void GClasses::GBNCategorical::addCatParent ( GBNCategorical pNode,
GBNNode pDefaultVal 
)
virtual

Adds a categorical node as a parent of this node. Calling this method will cause This node to resize its table of distribution parameters, so a default value is required to fill in new elements. Typically, you will set these new elements to something more meaningful (by calling setWeights) after you call this method.

Implements GClasses::GBNVariable.

size_t GClasses::GBNCategorical::categories ( )
inline

Returns the number of categories supported by this distribution.

virtual double GClasses::GBNCategorical::currentValue ( )
virtual

Returns the most recent value sampled from this node.

Implements GClasses::GBNVariable.

virtual double GClasses::GBNCategorical::likelihood ( double  x)
virtual

Computes the likelihood that the specified value (after being truncated to an integer) would be drawn from this categorical distribution given the current values of all the parent nodes of this class.

Implements GClasses::GBNVariable.

virtual void GClasses::GBNCategorical::sample ( GRand pRand)
virtual

Draws a new Gibbs sample for this node given the current values of all other nodes it its Markov blanket.

Implements GClasses::GBNVariable.

void GClasses::GBNCategorical::setWeights ( size_t  cat,
GBNNode pW1,
GBNNode pW2,
GBNNode pW3 = NULL,
GBNNode pW4 = NULL,
GBNNode pW5 = NULL,
GBNNode pW6 = NULL,
GBNNode pW7 = NULL,
GBNNode pW8 = NULL 
)

Set the weights for one of the categorical distributions of this node. If there are n categories in this node, then the first n parameters should be non-NULL. "cat" specifies the index of the combination of values (in little-endian order) in the categorical parent distributions for which this categorical distribution is being specified.

Member Data Documentation

size_t GClasses::GBNCategorical::m_categories
protected
size_t GClasses::GBNCategorical::m_val
protected
std::vector<GBNNode*> GClasses::GBNCategorical::m_weights
protected