40#ifndef __EST_SIMPLESTATS_H__
41#define __EST_SIMPLESTATS_H__
43#include "EST_String.h"
45#include "EST_StringTrie.h"
90 return (((i=(
int*)nametrie.
lookup(n)) != NULL) ? *i : p_def_val);
110 { copy(a);
return *
this; }
123 EST_Discrete &discrete(
const int t)
const {
return *discretes[t-10];}
151 {n=s.n; p_sum = s.p_sum; p_sumx = s.p_sumx;}
153 void reset(
void) {n = p_sum = p_sumx = 0.0;}
159 double sum() {
return p_sum; }
161 double sumx() {
return p_sumx; }
163 double mean(
void)
const {
return (n==0)?0.0:(p_sum / n); }
166 {
return ((n*p_sumx)-(p_sum*p_sum))/((
double)n*(n-1)); }
170 void cumulate(
double a,
double count=1.0)
171 { n+=count; p_sum+=a*count; p_sumx+=count*(a*a); }
175 { cumulate(a,1.0);
return *
this;}
178 { cumulate(a,1.0);
return *
this;}
181 { copy(a);
return *
this;}
184enum EST_tprob_type {tprob_string, tprob_int, tprob_discrete};
250 double samples(
void)
const {
return num_samples; }
255 void cumulate(
int i,
double count=1);
263 double probability(
const EST_String &s)
const;
265 double probability(
const int i)
const;
269 double frequency(
const int i)
const;
const EST_Discrete *const get_discrete() const
Returns discrete vocabulary of distribution.
EST_Litem * item_next(EST_Litem *idx) const
Used for iterating through members of the distribution.
void item_freq(EST_Litem *idx, EST_String &s, double &freq) const
During iteration returns name and frequency given index
void set_num_samples(const double c)
EST_Litem * item_start() const
Used for iterating through members of the distribution.
EST_DiscreteProbDistribution(const EST_Discrete *d)
Create using given \Ref{EST_Discrete} class as the vocabulary.
void item_prob(EST_Litem *idx, EST_String &s, double &prob) const
During iteration returns name and probability given index.
const EST_String & most_probable(double *prob=NULL) const
Return the most probable member of the distribution.
~EST_DiscreteProbDistribution()
Destructor function.
const EST_String & item_name(EST_Litem *idx) const
During iteration returns name given index.
double samples(void) const
Total number of example found.
void clear(void)
Reset, clearing all counts and vocabulary.
EST_DiscreteProbDistribution(const EST_TList< EST_String > &vocab)
Create with given vocabulary.
void override_frequency(const EST_String &s, double c)
Sets the frequency of named item, without modifying {\tt num_samples}.
double entropy(void) const
void copy(const EST_DiscreteProbDistribution &b)
Copy all data from another DPD to this.
void cumulate(const EST_String &s, double count=1)
Add this observation, may specify number of occurrences.
void set_frequency(const EST_String &s, double c)
int item_end(EST_Litem *idx) const
Used for iterating through members of the distribution.
bool init(const EST_StrList &vocab)
(re-)initialise
const int index(const EST_String &n) const
void def_val(const EST_String &v)
set the default value when a name isn't found (-1 by default)
const EST_String & name(const int n) const
The name given the index.
const int length(void) const
The number of members in the discrete.
int name(const EST_String &n) const
An alternative method for getting the int form the name.
void * lookup(const EST_String &key) const
Find contents index by {\tt key}, 0 if there is not contents.
void clear(void)
Delete the tree.
double stddev(void) const
standard deviation of currently cummulated values
double sum()
sum of values
double variance(void) const
variance of currently cummulated values
double mean(void) const
mean of currently cummulated values
void reset(void)
reset internal values
EST_SuffStats & operator+(double a)
Used to cummulate new values.
double samples(void)
number of samples in set
EST_SuffStats & operator+=(double a)
Used to cummulate new values.
double sumx()
sum of squared values
INLINE int length() const
number of items in vector.