PLearn 0.1
|
#include <ProbVector.h>
Public Member Functions | |
void | smoothNormalize (string name, real discounting_value=DISCOUNT_MASS) |
void | normalize () |
Protected Attributes | |
int | smoothingMethod |
Definition at line 46 of file ProbVector.h.
void PLearn::ProbVector::normalize | ( | ) |
Definition at line 92 of file ProbVector.cc.
References PLearn::TVec< real >::data(), PLearn::TVec< real >::length_, and PLearn::TVec< real >::size().
Referenced by PLearn::GraphicalBiText::init().
{ // Normalize the vector (sum = 1) int f; int size = length_; real *v = data(); real sum_v = 0; for(f=0;f<size;f++){ sum_v+=v[f]; } for(f=0;f<size;f++){ v[f]/=sum_v; } }
void PLearn::ProbVector::smoothNormalize | ( | string | name, |
real | discounting_value = DISCOUNT_MASS |
||
) |
Definition at line 41 of file ProbVector.cc.
References PLearn::TVec< real >::data(), PLearn::endl(), PLearn::TVec< real >::length_, PLWARNING, and PLearn::TVec< real >::size().
Referenced by PLearn::GraphicalBiText::init(), PLearn::GraphicalBiText::init_WSD(), and PLearn::GraphicalBiText::update_WSD_model().
{ // smooth by discounting and Normalize #ifdef DEBUG cout << "Smoothing "<< name; #endif bool err_smooth_flag=false; int f; int size = length_; real *v = data(); real word_seen=0; real sum_discounted=0.0; real sum_v = 0; for(f=0;f<size;f++){ if (v[f]>discounting_value){ sum_v+=v[f]; v[f]-=discounting_value; sum_discounted +=discounting_value; word_seen++; continue; } // in the case of non integer counts (typically during E.M. algo) if (v[f]>0 && v[f]<discounting_value){ sum_v+=v[f]; err_smooth_flag=true; } } #ifdef DEBUG cout << ": discounted " << sum_discounted << " from " << word_seen << " seen events summing " <<sum_v ; #endif // distribute discounted mass real unseen_prob=sum_discounted/(sum_v*size); word_seen=0; for(f=0;f<size;f++){ // Distribute on both seen and unseen events //if (v[f]<=discounting_value){ word_seen++; v[f]/=sum_v; v[f]+= unseen_prob; // }else{ // v[f]/=sum_v; // } } #ifdef DEBUG cout << " redistribute " << unseen_prob << " to "<< word_seen << " unseen events" <<endl; #endif if(err_smooth_flag)PLWARNING("minimal value < discounted value in Backoff Smoothing smoothNormalize a probVector"); }
int PLearn::ProbVector::smoothingMethod [protected] |
Definition at line 51 of file ProbVector.h.