GClasses
GClasses::GCategoricalDistribution Class Reference

Detailed Description

This is a distribution that specifies a probability for each value in a set of nominal values.

#include <GDistribution.h>

Inheritance diagram for GClasses::GCategoricalDistribution:
GClasses::GUnivariateDistribution GClasses::GDistribution

Public Member Functions

 GCategoricalDistribution ()
 
virtual ~GCategoricalDistribution ()
 
void deserialize (GDomNode *pNode)
 Load values from a text format. More...
 
double entropy ()
 Returns the entropy of the values. More...
 
virtual bool isDiscrete () const
 Returns true. More...
 
virtual bool isSupported (double x) const
 Returns true if x is within the range of support. If x is not an integer, it will round x to the nearest integer and then return true if that value is supported. More...
 
virtual double likelihood (double x)
 See the comment for GUnivariateDistribution::likelihood. More...
 
virtual double logLikelihood (double x)
 See the comment for GUnivariateDistribution::logLikelihood. More...
 
virtual double mode () const
 Returns the mode. More...
 
void normalize ()
 Makes the values sum to 1, and finds the mode. More...
 
double normalizedEntropy ()
 Computes the entropy of the values, normalized to fall between 0 and 1. More...
 
void normalizeFromLogSpace ()
 Safely converts from log space, and then normalizes. More...
 
GDomNodeserialize (GDom *pDoc) const
 Save values to a text format. More...
 
void setBoolean (double d)
 (1-d) is the probability of 0, and d is the probability of 1 More...
 
void setSpike (size_t nValueCount, size_t nValue, size_t nDepth)
 This is a hack for when you know the mode but you don't know the other values. More...
 
void setToUniform (size_t nValues)
 Set all uniform probabilities. More...
 
void setValues (size_t nValueCount, const double *pValues)
 Sets the specified values, and normalizes. More...
 
void setValuesInferLast (size_t nValueCount, const double *pValues)
 Sets the specified values, except infers the last, and normalizes. More...
 
virtual Type type () const
 Returns categorical. More...
 
size_t valueCount ()
 Returns the number of supported values. More...
 
GVecvalues (size_t nValueCount)
 Resizes the vector of probabilities if it does not have nValueCount elements, and returns that vector. More...
 
- Public Member Functions inherited from GClasses::GUnivariateDistribution
 GUnivariateDistribution ()
 
virtual ~GUnivariateDistribution ()
 

Protected Attributes

size_t m_nMode
 
size_t m_nValueCount
 
GVec m_pValues
 

Additional Inherited Members

- Public Types inherited from GClasses::GUnivariateDistribution

Constructor & Destructor Documentation

GClasses::GCategoricalDistribution::GCategoricalDistribution ( )
inline
virtual GClasses::GCategoricalDistribution::~GCategoricalDistribution ( )
inlinevirtual

Member Function Documentation

void GClasses::GCategoricalDistribution::deserialize ( GDomNode pNode)

Load values from a text format.

double GClasses::GCategoricalDistribution::entropy ( )

Returns the entropy of the values.

virtual bool GClasses::GCategoricalDistribution::isDiscrete ( ) const
inlinevirtual

Returns true.

Implements GClasses::GUnivariateDistribution.

virtual bool GClasses::GCategoricalDistribution::isSupported ( double  x) const
virtual

Returns true if x is within the range of support. If x is not an integer, it will round x to the nearest integer and then return true if that value is supported.

Implements GClasses::GUnivariateDistribution.

virtual double GClasses::GCategoricalDistribution::likelihood ( double  x)
inlinevirtual
virtual double GClasses::GCategoricalDistribution::logLikelihood ( double  x)
virtual
virtual double GClasses::GCategoricalDistribution::mode ( ) const
inlinevirtual

Returns the mode.

Implements GClasses::GUnivariateDistribution.

void GClasses::GCategoricalDistribution::normalize ( )

Makes the values sum to 1, and finds the mode.

double GClasses::GCategoricalDistribution::normalizedEntropy ( )
inline

Computes the entropy of the values, normalized to fall between 0 and 1.

void GClasses::GCategoricalDistribution::normalizeFromLogSpace ( )

Safely converts from log space, and then normalizes.

GDomNode* GClasses::GCategoricalDistribution::serialize ( GDom pDoc) const

Save values to a text format.

void GClasses::GCategoricalDistribution::setBoolean ( double  d)
inline

(1-d) is the probability of 0, and d is the probability of 1

void GClasses::GCategoricalDistribution::setSpike ( size_t  nValueCount,
size_t  nValue,
size_t  nDepth 
)

This is a hack for when you know the mode but you don't know the other values.

void GClasses::GCategoricalDistribution::setToUniform ( size_t  nValues)
inline

Set all uniform probabilities.

void GClasses::GCategoricalDistribution::setValues ( size_t  nValueCount,
const double *  pValues 
)

Sets the specified values, and normalizes.

void GClasses::GCategoricalDistribution::setValuesInferLast ( size_t  nValueCount,
const double *  pValues 
)

Sets the specified values, except infers the last, and normalizes.

virtual Type GClasses::GCategoricalDistribution::type ( ) const
inlinevirtual

Returns categorical.

Implements GClasses::GUnivariateDistribution.

size_t GClasses::GCategoricalDistribution::valueCount ( )
inline

Returns the number of supported values.

GVec& GClasses::GCategoricalDistribution::values ( size_t  nValueCount)
inline

Resizes the vector of probabilities if it does not have nValueCount elements, and returns that vector.

Member Data Documentation

size_t GClasses::GCategoricalDistribution::m_nMode
protected
size_t GClasses::GCategoricalDistribution::m_nValueCount
protected
GVec GClasses::GCategoricalDistribution::m_pValues
protected