PLearn 0.1
Public Member Functions | Protected Attributes
PLearn::ProbVector Class Reference

#include <ProbVector.h>

Inheritance diagram for PLearn::ProbVector:
Inheritance graph
[legend]
Collaboration diagram for PLearn::ProbVector:
Collaboration graph
[legend]

List of all members.

Public Member Functions

void smoothNormalize (string name, real discounting_value=DISCOUNT_MASS)
void normalize ()

Protected Attributes

int smoothingMethod

Detailed Description

Definition at line 46 of file ProbVector.h.


Member Function Documentation

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;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

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");
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 51 of file ProbVector.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines