70 for (i=0,d=0,x=1; i<24; i++)
81 #define tprob_int(X) (est_64to32(X)) 89 num_samples = n_samples;
102 num_samples = b.num_samples;
103 discrete = b.discrete;
128 icounts.resize(vocab.
length());
129 for (i=0; i<icounts.length(); i++)
130 icounts.a_no_check(i) = 0;
142 icounts.resize(d->
length());
143 for (i=0; i<icounts.length(); i++)
144 icounts.a_no_check(i) = 0;
150 num_samples += count;
156 num_samples += count;
165 int idx = discrete->index(s);
166 icounts[idx] += count;
170 for (p=scounts.list.head(); p != 0; p=p->
next())
172 if (scounts.list(p).k == s)
174 scounts.list(p).v += count;
179 scounts.add_item(s,count,1);
181 num_samples += count;
192 for (i=0; i < icounts.length(); i++)
193 if (icounts.a_no_check(i) >
max)
196 max = icounts.a_no_check(i);
207 *prob = probability(pt);
208 return discrete->name(pt);
214 for (p=scounts.list.head(); p != 0; p=p->
next())
215 if (scounts.list(p).v >
max)
218 max = scounts.list(p).v;
229 *prob = (double)max/num_samples;
230 return scounts.list(t).k;
237 if (frequency(s) == 0.0)
240 return (
double)frequency(s)/num_samples;
245 if (frequency(i) == 0.0)
248 return (
double)frequency(i)/num_samples;
254 return icounts.a_no_check(discrete->index(s));
256 return scounts.val_def(s,0);
265 cerr <<
"ProbDistribution: can't access string type pd with int\n";
274 num_samples -= icounts.a_no_check(discrete->index(s));
276 icounts.a_no_check(discrete->index(s)) = c;
280 num_samples -= scounts.val_def(s,0);
282 scounts.add_item(s,c);
290 num_samples -= icounts[i];
296 cerr <<
"ProbDistribution: can't access string type pd with int\n";
311 cerr <<
"ProbDistribution: can't access string type pd with int\n";
320 icounts.a_no_check(discrete->index(s)) = c;
322 scounts.add_item(s,c);
330 cerr <<
"ProbDistribution: can't access string type pd with int\n";
338 cerr <<
"ProbDistribution: can't access string type pd with int\n";
350 for (i=0; i < icounts.length(); i++)
352 double prob = icounts.a_no_check(i)/num_samples;
354 e += prob * log(prob);
359 for (p=scounts.list.head(); p != 0; p=p->
next())
361 double prob = scounts.list(p).v/num_samples;
363 e += prob * log(prob);
377 return scounts.list.head();
383 return (
tprob_int(idx) >= icounts.length());
391 return (
EST_Litem *)(((
unsigned char *)idx)+1);
401 return scounts.list(idx).k;
413 s = scounts.list(idx).k;
414 freq = scounts.list(idx).v;
427 s = scounts.list(idx).k;
428 prob = (double)scounts.list(idx).v/num_samples;
444 s <<
"(" << name <<
"=" << prob <<
") ";
448 << pd.
samples() <<
" sum=" << sum <<
")";
EST_Litem * item_next(EST_Litem *idx) const
Used for iterating through members of the distribution.
const EST_String & most_probable(double *prob=NULL) const
Return the most probable member of the distribution.
double samples(void) const
Total number of example found.
int length(void) const
The number of members in the discrete.
EST_Litem * item_start() const
Used for iterating through members of the distribution.
int item_end(EST_Litem *idx) const
Used for iterating through members of the distribution.
double probability(const EST_String &s) const
float max(float a, float b)
void cumulate(const EST_String &s, double count=1)
Add this observation, may specify number of occurrences.
double frequency(const EST_String &s) const
void item_freq(EST_Litem *idx, EST_String &s, double &freq) const
During iteration returns name and frequency given index.
ostream & operator<<(ostream &s, const EST_DiscreteProbDistribution &pd)
double entropy(void) const
void copy(const EST_DiscreteProbDistribution &b)
Copy all data from another DPD to this.
void item_prob(EST_Litem *idx, EST_String &s, double &prob) const
During iteration returns name and probability given index.
const EST_String & item_name(EST_Litem *idx) const
During iteration returns name given index.
EST_TVector< T > & copy(EST_TVector< T > a, const EST_TList< T > &in)
void clear(void)
Reset, clearing all counts and vocabulary.
A vector class for double precision floating point numbers. EST_DVector x should be used instead of f...
void set_frequency(const EST_String &s, double c)
EST_DiscreteProbDistribution & operator=(const EST_DiscreteProbDistribution &a)
void override_frequency(const EST_String &s, double c)
Sets the frequency of named item, without modifying num\_samples.
float sum(const EST_FMatrix &a)
sum of elements
static const EST_String Empty
Constant empty string.
EST_DiscreteProbDistribution()