PLearn 0.1
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Static Protected Member Functions | Private Types | Private Member Functions
PLearn::NormalizationLearner Class Reference

The first sentence should be a BRIEF DESCRIPTION of what the class does. More...

#include <NormalizationLearner.h>

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

List of all members.

Public Member Functions

 NormalizationLearner ()
 Default constructor.
virtual int outputsize () const
 Returns the size of this learner's output, (which typically may depend on its inputsize(), targetsize() and set options).
virtual void forget ()
 (Re-)initializes the PLearner in its fresh state (that state may depend on the 'seed' option) and sets 'stage' back to 0 (this is the stage of a fresh learner!).
virtual void train ()
 The role of the train method is to bring the learner up to stage==nstages, updating the train_stats collector with training costs measured on-line in the process.
virtual void computeOutput (const Vec &input, Vec &output) const
 Computes the output from the input.
virtual void computeCostsFromOutputs (const Vec &input, const Vec &output, const Vec &target, Vec &costs) const
 Computes the costs from already computed output.
virtual TVec< std::string > getTestCostNames () const
 Returns the names of the costs computed by computeCostsFromOutpus (and thus the test method).
virtual TVec< std::string > getTrainCostNames () const
 Returns the names of the objective costs that the train method computes and for which it updates the VecStatsCollector train_stats.
virtual TVec< string > getOutputNames () const
 outputnames are the same as the inputnames
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual NormalizationLearnerdeepCopy (CopiesMap &copies) const
virtual void build ()
 Finish building the object; just call inherited::build followed by build_()
virtual void makeDeepCopyFromShallowCopy (CopiesMap &copies)
 Transforms a shallow copy into a deep copy.

Static Public Member Functions

static string _classname_ ()
static OptionList_getOptionList_ ()
static RemoteMethodMap_getRemoteMethodMap_ ()
static Object_new_instance_for_typemap_ ()
static bool _isa_ (const Object *o)
static void _static_initialize_ ()
static const PPathdeclaringFile ()

Public Attributes

real min_allowed_stddev
 ### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //!
double remove_components_with_stddev_smaller_than
double remove_components_whose_missing_proportion_exceeds
bool set_missing_to_zero
bool do_normalize
Vec meanvec
Vec inv_stddev
TVec< string > inputnames
TVec< intkept_components

Static Public Attributes

static StaticInitializer _static_initializer_

Static Protected Member Functions

static void declareOptions (OptionList &ol)
 Declares the class options.

Private Types

typedef PLearner inherited

Private Member Functions

void build_ ()
 This does the actual building.

Detailed Description

The first sentence should be a BRIEF DESCRIPTION of what the class does.

Place the rest of the class programmer documentation here. Doxygen supports Javadoc-style comments. See http://www.doxygen.org/manual.html

Todo:
Write class to-do's here if there are any.
Deprecated:
Write deprecated stuff here if there is any. Indicate what else should be used instead.

Definition at line 57 of file NormalizationLearner.h.


Member Typedef Documentation

Reimplemented from PLearn::PLearner.

Definition at line 59 of file NormalizationLearner.h.


Constructor & Destructor Documentation

PLearn::NormalizationLearner::NormalizationLearner ( )

Member Function Documentation

string PLearn::NormalizationLearner::_classname_ ( ) [static]

Reimplemented from PLearn::PLearner.

Definition at line 56 of file NormalizationLearner.cc.

OptionList & PLearn::NormalizationLearner::_getOptionList_ ( ) [static]

Reimplemented from PLearn::PLearner.

Definition at line 56 of file NormalizationLearner.cc.

RemoteMethodMap & PLearn::NormalizationLearner::_getRemoteMethodMap_ ( ) [static]

Reimplemented from PLearn::PLearner.

Definition at line 56 of file NormalizationLearner.cc.

bool PLearn::NormalizationLearner::_isa_ ( const Object o) [static]

Reimplemented from PLearn::PLearner.

Definition at line 56 of file NormalizationLearner.cc.

Object * PLearn::NormalizationLearner::_new_instance_for_typemap_ ( ) [static]

Reimplemented from PLearn::Object.

Definition at line 56 of file NormalizationLearner.cc.

StaticInitializer NormalizationLearner::_static_initializer_ & PLearn::NormalizationLearner::_static_initialize_ ( ) [static]

Reimplemented from PLearn::PLearner.

Definition at line 56 of file NormalizationLearner.cc.

void PLearn::NormalizationLearner::build ( ) [virtual]

Finish building the object; just call inherited::build followed by build_()

Reimplemented from PLearn::PLearner.

Definition at line 143 of file NormalizationLearner.cc.

References PLearn::PLearner::build(), and build_().

Here is the call graph for this function:

void PLearn::NormalizationLearner::build_ ( ) [private]

This does the actual building.

Reimplemented from PLearn::PLearner.

Definition at line 120 of file NormalizationLearner.cc.

References d, kept_components, PLearn::TVec< T >::length(), meanvec, and PLearn::TVec< T >::resize().

Referenced by build().

{
    // ### This method should do the real building of the object,
    // ### according to set 'options', in *any* situation.
    // ### Typical situations include:
    // ###  - Initial building of an object from a few user-specified options
    // ###  - Building of a "reloaded" object: i.e. from the complete set of
    // ###    all serialised options.
    // ###  - Updating or "re-building" of an object after a few "tuning"
    // ###    options have been modified.
    // ### You should assume that the parent class' build_() has already been
    // ### called.

    int d = meanvec.length();
    if(d>0 && kept_components.length()==0) // fill uninitialized kept_components
    {
        kept_components.resize(d);
        for(int k=0; k<d; k++)
            kept_components[k] = k;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

string PLearn::NormalizationLearner::classname ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 56 of file NormalizationLearner.cc.

void PLearn::NormalizationLearner::computeCostsFromOutputs ( const Vec input,
const Vec output,
const Vec target,
Vec costs 
) const [virtual]

Computes the costs from already computed output.

Implements PLearn::PLearner.

Definition at line 255 of file NormalizationLearner.cc.

References PLearn::TVec< T >::resize().

{
    costs.resize(0);
}

Here is the call graph for this function:

void PLearn::NormalizationLearner::computeOutput ( const Vec input,
Vec output 
) const [virtual]

Computes the output from the input.

Reimplemented from PLearn::PLearner.

Definition at line 226 of file NormalizationLearner.cc.

References PLearn::TVec< T >::data(), do_normalize, inv_stddev, PLearn::is_missing(), kept_components, PLearn::TVec< T >::length(), meanvec, n, PLERROR, PLearn::TVec< T >::resize(), and set_missing_to_zero.

{
    int n = meanvec.length();
    if(input.length()!=n)
        PLERROR("length of input differs from length of meanvec!");
    int n2 = kept_components.length();
    output.resize(n2);
    real* p_input = input.data();
    real* p_output = output.data();
    real* p_meanvec = meanvec.data();
    real* p_inv_stddev = inv_stddev.data();
    int*  p_kept_components = kept_components.data();

    for(int k=0; k<n2; k++)
    {
        int pos = p_kept_components[k];
        real val = p_input[pos];
        if(is_missing(val))
        {
            if(set_missing_to_zero)
                val = 0;
        }
        else if(do_normalize)
            val = p_inv_stddev[pos]*(val - p_meanvec[pos]);

        p_output[k] = val;
    }
}

Here is the call graph for this function:

void PLearn::NormalizationLearner::declareOptions ( OptionList ol) [static, protected]

Declares the class options.

Reimplemented from PLearn::PLearner.

Definition at line 67 of file NormalizationLearner.cc.

References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::PLearner::declareOptions(), do_normalize, inputnames, inv_stddev, kept_components, PLearn::OptionBase::learntoption, meanvec, min_allowed_stddev, remove_components_whose_missing_proportion_exceeds, remove_components_with_stddev_smaller_than, and set_missing_to_zero.

{
    declareOption(ol, "min_allowed_stddev", &NormalizationLearner::min_allowed_stddev,
                  OptionBase::buildoption,
                  "If the empirical standard deviation is lower than this, we'll use this value to \n"
                  "compute inv_stddev (this is to prevent getting too large or even infinite values for inv_stddev");

    declareOption(ol, "remove_components_with_stddev_smaller_than", &NormalizationLearner::remove_components_with_stddev_smaller_than,
                  OptionBase::buildoption,
                  "Components of the input whose stddev is strictly below that value will be excluded from the output\n");

    declareOption(ol, "remove_components_whose_missing_proportion_exceeds", &NormalizationLearner::remove_components_whose_missing_proportion_exceeds,
                  OptionBase::buildoption,
                  "Components of the input that are missing more than that given fraction of times will be excluded from the output\n"
                  "The default 1 means no component will be excluded for being missing.\n"
                  "At the other extreme 0 means any component that was missing at east once wil be excluded\n"
                  "0.75 would exclude components that are missing more than 75 percent of the time\n");

    declareOption(ol, "do_normalize", &NormalizationLearner::do_normalize,
                  OptionBase::buildoption,
                  "If true (the default) then subtract mean and divide by stddev.\n"
                  "It can be useful to set this to false if all you want to do is remove components with small\n"
                  "stddev (see option remove_components with_small_stddev) but leave the others untouched.");

    declareOption(ol, "set_missing_to_zero", &NormalizationLearner::set_missing_to_zero,
                  OptionBase::buildoption,
                  "How to handle missing values: \n"
                  "  If true (the default), missing values will be replaced by 0\n"
                  "  (this corresponds to post-normalization mean if indeed we d_normakize) \n"
                  "  If false missing values will be left as missing values. \n");

    declareOption(ol, "meanvec", &NormalizationLearner::meanvec,
                  OptionBase::learntoption,
                  "The empirical mean to subtract from the input\n");

    declareOption(ol, "inv_stddev", &NormalizationLearner::inv_stddev,
                  OptionBase::learntoption,
                  "The vector of factors by which to multiply (input-meanvec)\n");

    declareOption(ol, "kept_components", &NormalizationLearner::kept_components,
                  OptionBase::learntoption,
                  "The indices of the input components kept in the final output\n");

    declareOption(ol, "inputnames", &NormalizationLearner::inputnames,
                  OptionBase::learntoption,
                  "We store the inputnames, which are also the outputnames\n");



    // Now call the parent class' declareOptions
    inherited::declareOptions(ol);
}

Here is the call graph for this function:

static const PPath& PLearn::NormalizationLearner::declaringFile ( ) [inline, static]

Reimplemented from PLearn::PLearner.

Definition at line 151 of file NormalizationLearner.h.

:
    //#####  Protected Options  ###############################################
NormalizationLearner * PLearn::NormalizationLearner::deepCopy ( CopiesMap copies) const [virtual]

Reimplemented from PLearn::PLearner.

Definition at line 56 of file NormalizationLearner.cc.

void PLearn::NormalizationLearner::forget ( ) [virtual]

(Re-)initializes the PLearner in its fresh state (that state may depend on the 'seed' option) and sets 'stage' back to 0 (this is the stage of a fresh learner!).

Reimplemented from PLearn::PLearner.

Definition at line 170 of file NormalizationLearner.cc.

References PLearn::PLearner::forget(), and PLearn::PLearner::stage.

Here is the call graph for this function:

OptionList & PLearn::NormalizationLearner::getOptionList ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 56 of file NormalizationLearner.cc.

OptionMap & PLearn::NormalizationLearner::getOptionMap ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 56 of file NormalizationLearner.cc.

TVec< string > PLearn::NormalizationLearner::getOutputNames ( ) const [virtual]

outputnames are the same as the inputnames

Reimplemented from PLearn::PLearner.

Definition at line 271 of file NormalizationLearner.cc.

References inputnames, kept_components, PLearn::TVec< T >::length(), and PLearn::TVec< T >::resize().

{
    TVec<string> outnames;
    if(kept_components.length()==inputnames.length())
        outnames = inputnames;
    else
    {
        int n2 = kept_components.length();
        outnames.resize(n2);
        for(int k=0; k<n2; k++)
            outnames[k] = inputnames[kept_components[k]];
    }
    return outnames;
}

Here is the call graph for this function:

RemoteMethodMap & PLearn::NormalizationLearner::getRemoteMethodMap ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 56 of file NormalizationLearner.cc.

TVec< string > PLearn::NormalizationLearner::getTestCostNames ( ) const [virtual]

Returns the names of the costs computed by computeCostsFromOutpus (and thus the test method).

Implements PLearn::PLearner.

Definition at line 261 of file NormalizationLearner.cc.

{
    return TVec<string>();
}
TVec< string > PLearn::NormalizationLearner::getTrainCostNames ( ) const [virtual]

Returns the names of the objective costs that the train method computes and for which it updates the VecStatsCollector train_stats.

Implements PLearn::PLearner.

Definition at line 266 of file NormalizationLearner.cc.

{
    return TVec<string>();
}
void PLearn::NormalizationLearner::makeDeepCopyFromShallowCopy ( CopiesMap copies) [virtual]

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::PLearner.

Definition at line 150 of file NormalizationLearner.cc.

References PLearn::PLearner::makeDeepCopyFromShallowCopy(), and PLERROR.

{
    inherited::makeDeepCopyFromShallowCopy(copies);

    // ### Call deepCopyField on all "pointer-like" fields
    // ### that you wish to be deepCopied rather than
    // ### shallow-copied.
    // ### ex:
    // deepCopyField(trainvec, copies);

    // ### Remove this line when you have fully implemented this method.
    PLERROR("NormalizationLearner::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!");
}

Here is the call graph for this function:

int PLearn::NormalizationLearner::outputsize ( ) const [virtual]

Returns the size of this learner's output, (which typically may depend on its inputsize(), targetsize() and set options).

Implements PLearn::PLearner.

Definition at line 165 of file NormalizationLearner.cc.

References kept_components, and PLearn::TVec< T >::length().

{
    return kept_components.length();
}

Here is the call graph for this function:

void PLearn::NormalizationLearner::train ( ) [virtual]

The role of the train method is to bring the learner up to stage==nstages, updating the train_stats collector with training costs measured on-line in the process.

Implements PLearn::PLearner.

Definition at line 176 of file NormalizationLearner.cc.

References PLearn::TVec< T >::append(), PLearn::VecStatsCollector::finalize(), PLearn::VMat::getExample(), PLearn::VecStatsCollector::getMean(), i, PLearn::PLearner::initTrain(), inputnames, inv_stddev, kept_components, PLearn::VMat::length(), PLearn::max(), meanvec, min_allowed_stddev, n, PLearn::StatsCollector::nmissing(), remove_components_whose_missing_proportion_exceeds, remove_components_with_stddev_smaller_than, PLearn::PLearner::report_progress, PLearn::TVec< T >::resize(), PLearn::PLearner::stage, PLearn::VecStatsCollector::stats, PLearn::StatsCollector::stddev(), PLearn::PLearner::train_set, PLearn::PLearner::train_stats, and PLearn::VecStatsCollector::update().

{
    if (!initTrain())
        return;

    if(stage<1)
    {
        inputnames = train_set->inputFieldNames();

        train_stats->forget();
        int l = train_set->length();
        int n = train_set->inputsize();
        Vec input;
        Vec target;
        real weight;

        VecStatsCollector st;
        PP<ProgressBar> pb;
        if(report_progress)
            pb = new ProgressBar("NormalizationLearner computing statistics ",l);

        for(int i=0; i<l; i++)
        {
            train_set->getExample(i, input, target, weight);
            st.update(input, weight);
            if(pb)
                pb->update(i);
        }
        st.finalize();

        st.getMean(meanvec);
        inv_stddev.resize(n);
        kept_components.resize(n);
        kept_components.resize(0);
        for(int k=0; k<n; k++)
        {
            const StatsCollector& stk = st.stats[k];
            real sd = stk.stddev();
            inv_stddev[k] = 1/max(min_allowed_stddev,sd);
            double missing_proportion = (double)stk.nmissing()/(double)l;
            if( (missing_proportion<=remove_components_whose_missing_proportion_exceeds)
                && (sd>=remove_components_with_stddev_smaller_than) )
                kept_components.append(k);
        }
        ++stage;
        train_stats->finalize(); 
    }
}

Here is the call graph for this function:


Member Data Documentation

Reimplemented from PLearn::PLearner.

Definition at line 151 of file NormalizationLearner.h.

Definition at line 72 of file NormalizationLearner.h.

Referenced by computeOutput(), and declareOptions().

Definition at line 77 of file NormalizationLearner.h.

Referenced by declareOptions(), getOutputNames(), and train().

Definition at line 76 of file NormalizationLearner.h.

Referenced by computeOutput(), declareOptions(), and train().

Definition at line 75 of file NormalizationLearner.h.

Referenced by build_(), computeOutput(), declareOptions(), and train().

### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //!

Definition at line 68 of file NormalizationLearner.h.

Referenced by declareOptions(), and train().

Definition at line 70 of file NormalizationLearner.h.

Referenced by declareOptions(), and train().

Definition at line 69 of file NormalizationLearner.h.

Referenced by declareOptions(), and train().

Definition at line 71 of file NormalizationLearner.h.

Referenced by computeOutput(), and declareOptions().


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