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