Loading...
Searching...
No Matches
EST_DiscreteProbDistribution Class Reference

`#include <include/EST_simplestats.h>`

## Public Member Functions

| EST_DiscreteProbDistribution (const EST_DiscreteProbDistribution &b)
| Create with copying from an existing distribution.
| EST_DiscreteProbDistribution (const EST_TList< EST_String > &vocab)
| Create with given vocabulary.
| EST_DiscreteProbDistribution (const EST_Discrete *d)
| Create using given \Ref{EST_Discrete} class as the vocabulary.
| EST_DiscreteProbDistribution (const EST_Discrete *d, const double n_samples, const EST_DVector &counts)
| ~EST_DiscreteProbDistribution ()
| Destructor function.
void | copy (const EST_DiscreteProbDistribution &b)
| Copy all data from another DPD to this.
void | clear (void)
| Reset, clearing all counts and vocabulary.
bool | init (const EST_StrList &vocab)
| Initialise using given vocabulary.
void | init (const EST_Discrete *d)
| Initialise using given \Ref{EST_Discrete} as vocabulary.
void | init ()
| Initialise.
double | samples (void) const
| Total number of example found.
void | cumulate (const EST_String &s, double count=1)
| Add this observation, may specify number of occurrences.
void | cumulate (EST_Litem *i, double count=1)
| Add this observation, i must be with in EST_Discrete range.
void | cumulate (int i, double count=1)
const EST_String & | most_probable (double *prob=NULL) const
| Return the most probable member of the distribution.
double | entropy (void) const
double | probability (const EST_String &s) const
double | probability (const int i) const
double | frequency (const EST_String &s) const
double | frequency (const int i) const
EST_Litem * | item_start () const
| Used for iterating through members of the distribution.
EST_Litem * | item_next (EST_Litem *idx) const
| Used for iterating through members of the distribution.
int | item_end (EST_Litem *idx) const
| Used for iterating through members of the distribution.
const EST_String & | item_name (EST_Litem *idx) const
| During iteration returns name given index.
void | item_freq (EST_Litem *idx, EST_String &s, double &freq) const
| During iteration returns name and frequency given index.
void | item_prob (EST_Litem *idx, EST_String &s, double &prob) const
| During iteration returns name and probability given index.
const EST_Discrete *const | get_discrete () const
| Returns discrete vocabulary of distribution.
void | set_frequency (const EST_String &s, double c)
void | set_frequency (int i, double c)
void | set_frequency (EST_Litem *i, double c)
void | override_frequency (const EST_String &s, double c)
| Sets the frequency of named item, without modifying {\tt num_samples}.
void | override_frequency (int i, double c)
| Sets the frequency of named item, without modifying {\tt num_samples}.
void | override_frequency (EST_Litem *i, double c)
void | set_num_samples (const double c)
EST_DiscreteProbDistribution & | operator= (const EST_DiscreteProbDistribution &a)

## Friends

ostream & | operator<< (ostream &s, const EST_DiscreteProbDistribution &p)

## Detailed Description

A class for cummulating ``sufficient statistics'' for a set of numbers: sum, count, sum squared.

This collects the number, sum and sum squared for a set of number. Offering mean, variance and standard deviation derived from the cummulated values.

Author
  Alan W Black (awb@c.nosp@m.str..nosp@m.ed.ac.nosp@m..uk): July 1996 */ class EST_SuffStats { private: double n; // allows frequencies to be non-integers double p_sum; double p_sumx; public: / EST_SuffStats() {n = p_sum = p_sumx = 0.0;} / EST_SuffStats(double in, double isum, double isumx) {n = in; p_sum = isum; p_sumx = isumx;} / EST_SuffStats(const EST_SuffStats &s) { copy(s); } / void copy(const EST_SuffStats &s) {n=s.n; p_sum = s.p_sum; p_sumx = s.p_sumx;} / reset internal values void reset(void) {n = p_sum = p_sumx = 0.0;} void set(double in, double isum, double isumx) {n = in; p_sum = isum; p_sumx = isumx;} / number of samples in set double samples(void) {return n;} / sum of values double sum() { return p_sum; } / sum of squared values double sumx() { return p_sumx; } / mean of currently cummulated values double mean(void) const { return (n==0)?0.0:(p_sum / n); } / variance of currently cummulated values double variance(void) const { return ((n*p_sumx)-(p_sum*p_sum))/((double)n*(n-1)); } / standard deviation of currently cummulated values double stddev(void) const { return sqrt(variance()); }

void cumulate(double a,double count=1.0) { n+=count; p_sum+=a*count; p_sumx+=count*(a*a); }

/ Used to cummulate new values EST_SuffStats &operator +=(double a) { cumulate(a,1.0); return *this;} / Used to cummulate new values EST_SuffStats &operator + (double a) { cumulate(a,1.0); return *this;} / EST_SuffStats &operator = (const EST_SuffStats &a) { copy(a); return *this;} };

enum EST_tprob_type {tprob_string, tprob_int, tprob_discrete}; /** A class for representing probability distributions for a set of discrete values.

This may be used to cummulate the probability distribution of a class of values. Values are actually help as frequencies so both frequency and probability information may be available. Note that frequencies are not integers because using smoothing and backoff integers are too restrictive so they are actually represented as doubles.

Methods are provided to iterate over the values in a distribution, for example \begin{verbatim} EST_DiscreteProbistribution pdf; for (int i=pdf.item_start(); i < pdf.item_end(); i=pdf.item_next(i)) { EST_String name; double prob; item_prob(i,name,prob); cout << name << ": prob " << prob << endl; } \end{verbatim}

Author
  Alan W Black (awb@c.nosp@m.str..nosp@m.ed.ac.nosp@m..uk): July 1996

Definition at line 210 of file EST_simplestats.h.

## Constructor & Destructor Documentation

## EST_DiscreteProbDistribution() [1/5]

EST_DiscreteProbDistribution::EST_DiscreteProbDistribution | ( |  | ) |

inline

Definition at line 221 of file EST_simplestats.h.

## EST_DiscreteProbDistribution() [2/5]

EST_DiscreteProbDistribution::EST_DiscreteProbDistribution | ( | const EST_DiscreteProbDistribution & | b | ) |

Create with copying from an existing distribution.

Definition at line 92 of file EST_DProbDist.cc.

## EST_DiscreteProbDistribution() [3/5]

EST_DiscreteProbDistribution::EST_DiscreteProbDistribution | ( | const EST_TList< EST_String > & | vocab | ) |

inline

Create with given vocabulary.

Definition at line 225 of file EST_simplestats.h.

## EST_DiscreteProbDistribution() [4/5]

EST_DiscreteProbDistribution::EST_DiscreteProbDistribution | ( | const EST_Discrete * | d | ) |

inline

Create using given \Ref{EST_Discrete} class as the vocabulary.

Definition at line 228 of file EST_simplestats.h.

## EST_DiscreteProbDistribution() [5/5]

EST_DiscreteProbDistribution::EST_DiscreteProbDistribution | ( | const EST_Discrete * | d,
|  | const double | n_samples,
|  | const EST_DVector & | counts )

Create using given \Ref{EST_Discrete} class as vocabulary plus given counts

Definition at line 82 of file EST_DProbDist.cc.

## ~EST_DiscreteProbDistribution()

EST_DiscreteProbDistribution::~EST_DiscreteProbDistribution | ( |  | ) |

inline

Destructor function.

Definition at line 237 of file EST_simplestats.h.

## Member Function Documentation

## copy()

void EST_DiscreteProbDistribution::copy | ( | const EST_DiscreteProbDistribution & | b | ) |

Copy all data from another DPD to this.

Definition at line 97 of file EST_DProbDist.cc.

## clear()

void EST_DiscreteProbDistribution::clear | ( | void |  | ) |

Reset, clearing all counts and vocabulary.

Definition at line 106 of file EST_DProbDist.cc.

## init() [1/3]

bool EST_DiscreteProbDistribution::init | ( | const EST_StrList & | vocab | ) |

Initialise using given vocabulary.

Definition at line 118 of file EST_DProbDist.cc.

## init() [2/3]

void EST_DiscreteProbDistribution::init | ( | const EST_Discrete * | d | ) |

Initialise using given \Ref{EST_Discrete} as vocabulary.

Definition at line 133 of file EST_DProbDist.cc.

## init() [3/3]

void EST_DiscreteProbDistribution::init | ( | void |  | ) |

Initialise.

Definition at line 111 of file EST_DProbDist.cc.

## samples()

double EST_DiscreteProbDistribution::samples | ( | void |  | ) | const

inline

Total number of example found.

Definition at line 250 of file EST_simplestats.h.

## cumulate() [1/3]

void EST_DiscreteProbDistribution::cumulate | ( | const EST_String & | s,
|  | double | count = 1 )

Add this observation, may specify number of occurrences.

Definition at line 157 of file EST_DProbDist.cc.

## cumulate() [2/3]

void EST_DiscreteProbDistribution::cumulate | ( | EST_Litem * | i,
|  | double | count = 1 )

Add this observation, i must be with in EST_Discrete range.

Definition at line 145 of file EST_DProbDist.cc.

## cumulate() [3/3]

void EST_DiscreteProbDistribution::cumulate | ( | int | i,
|  | double | count = 1 )

Definition at line 151 of file EST_DProbDist.cc.

## most_probable()

const EST_String & EST_DiscreteProbDistribution::most_probable | ( | double * | prob = NULL | ) | const

Return the most probable member of the distribution.

Definition at line 182 of file EST_DProbDist.cc.

## entropy()

double EST_DiscreteProbDistribution::entropy | ( | void |  | ) | const

Return the entropy of the distribution [ -\sum_{i=1}^N(prob(i)*log(prob(i))) ]

Definition at line 339 of file EST_DProbDist.cc.

## probability() [1/2]

double EST_DiscreteProbDistribution::probability | ( | const EST_String & | s | ) | const

Definition at line 233 of file EST_DProbDist.cc.

## probability() [2/2]

double EST_DiscreteProbDistribution::probability | ( | const int | i | ) | const

Definition at line 241 of file EST_DProbDist.cc.

## frequency() [1/2]

double EST_DiscreteProbDistribution::frequency | ( | const EST_String & | s | ) | const

Definition at line 249 of file EST_DProbDist.cc.

## frequency() [2/2]

double EST_DiscreteProbDistribution::frequency | ( | const int | i | ) | const

Definition at line 257 of file EST_DProbDist.cc.

## item_start()

EST_Litem * EST_DiscreteProbDistribution::item_start | ( | void |  | ) | const

Used for iterating through members of the distribution.

Definition at line 370 of file EST_DProbDist.cc.

## item_next()

EST_Litem * EST_DiscreteProbDistribution::item_next | ( | EST_Litem * | idx | ) | const

Used for iterating through members of the distribution.

Definition at line 386 of file EST_DProbDist.cc.

## item_end()

int EST_DiscreteProbDistribution::item_end | ( | EST_Litem * | idx | ) | const

Used for iterating through members of the distribution.

Definition at line 378 of file EST_DProbDist.cc.

## item_name()

const EST_String & EST_DiscreteProbDistribution::item_name | ( | EST_Litem * | idx | ) | const

During iteration returns name given index.

Definition at line 394 of file EST_DProbDist.cc.

## item_freq()

void EST_DiscreteProbDistribution::item_freq | ( | EST_Litem * | idx,
|  | EST_String & | s,
|  | double & | freq ) const

During iteration returns name and frequency given index.

Definition at line 402 of file EST_DProbDist.cc.

## item_prob()

void EST_DiscreteProbDistribution::item_prob | ( | EST_Litem * | idx,
|  | EST_String & | s,
|  | double & | prob ) const

During iteration returns name and probability given index.

Definition at line 416 of file EST_DProbDist.cc.

## get_discrete()

const EST_Discrete *const EST_DiscreteProbDistribution::get_discrete | ( |  | ) | const

inline

Returns discrete vocabulary of distribution.

Definition at line 285 of file EST_simplestats.h.

## set_frequency() [1/3]

void EST_DiscreteProbDistribution::set_frequency | ( | const EST_String & | s,
|  | double | c )

Sets the frequency of named item, modifies {\tt num_samples} accordingly. This is used when smoothing frequencies.

Definition at line 268 of file EST_DProbDist.cc.

## set_frequency() [2/3]

void EST_DiscreteProbDistribution::set_frequency | ( | int | i,
|  | double | c )

Sets the frequency of named item, modifies {\tt num_samples} accordingly. This is used when smoothing frequencies.

Definition at line 284 of file EST_DProbDist.cc.

## set_frequency() [3/3]

void EST_DiscreteProbDistribution::set_frequency | ( | EST_Litem * | i,
|  | double | c )

Definition at line 299 of file EST_DProbDist.cc.

## override_frequency() [1/3]

void EST_DiscreteProbDistribution::override_frequency | ( | const EST_String & | s,
|  | double | c )

Sets the frequency of named item, without modifying {\tt num_samples}.

Definition at line 315 of file EST_DProbDist.cc.

## override_frequency() [2/3]

void EST_DiscreteProbDistribution::override_frequency | ( | int | i,
|  | double | c )

Sets the frequency of named item, without modifying {\tt num_samples}.

Definition at line 323 of file EST_DProbDist.cc.

## override_frequency() [3/3]

void EST_DiscreteProbDistribution::override_frequency | ( | EST_Litem * | i,
|  | double | c )

Definition at line 331 of file EST_DProbDist.cc.

## set_num_samples()

void EST_DiscreteProbDistribution::set_num_samples | ( | const double | c | ) |

inline

Sets the number of samples. Care should be taken on setting this as it will affect how probabilities are calculated.

Definition at line 306 of file EST_simplestats.h.

## operator=()

EST_DiscreteProbDistribution & EST_DiscreteProbDistribution::operator= | ( | const EST_DiscreteProbDistribution & | a | ) |

Definition at line 450 of file EST_DProbDist.cc.

## Friends And Related Symbol Documentation

## operator<<

ostream & operator<< | ( | ostream & | s,
|  | const EST_DiscreteProbDistribution & | p )

friend

Definition at line 430 of file EST_DProbDist.cc.

The documentation for this class was generated from the following files:

- include/EST_simplestats.h
- stats/EST_DProbDist.cc