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

#include <ConstantRegressor.h>

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

List of all members.

Public Member Functions

 ConstantRegressor ()
virtual void build ()
 simply calls inherited::build() then build_()
virtual void makeDeepCopyFromShallowCopy (CopiesMap &copies)
 Transforms a shallow copy into a deep copy.
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual ConstantRegressordeepCopy (CopiesMap &copies) const
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< string > getTestCostNames () const
 Returns the names of the costs computed by computeCostsFromOutpus (and thus the test method)
virtual TVec< string > getTrainCostNames () const
 Returns the names of the objective costs that the train method computes and for which it updates the VecStatsCollector train_stats.

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 weight_decay
 Weight decay; not usually useful but...

Static Public Attributes

static StaticInitializer _static_initializer_

Static Protected Member Functions

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

Protected Attributes

Vec constant_output

Private Types

typedef PLearner inherited

Private Member Functions

void build_ ()
 This does the actual building.

Detailed Description

Definition at line 49 of file ConstantRegressor.h.


Member Typedef Documentation

Reimplemented from PLearn::PLearner.

Definition at line 52 of file ConstantRegressor.h.


Constructor & Destructor Documentation

PLearn::ConstantRegressor::ConstantRegressor ( )

Definition at line 46 of file ConstantRegressor.cc.

    : weight_decay(0.0)
{
}

Member Function Documentation

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

Reimplemented from PLearn::PLearner.

Definition at line 65 of file ConstantRegressor.cc.

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

Reimplemented from PLearn::PLearner.

Definition at line 65 of file ConstantRegressor.cc.

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

Reimplemented from PLearn::PLearner.

Definition at line 65 of file ConstantRegressor.cc.

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

Reimplemented from PLearn::PLearner.

Definition at line 65 of file ConstantRegressor.cc.

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

Reimplemented from PLearn::Object.

Definition at line 65 of file ConstantRegressor.cc.

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

Reimplemented from PLearn::PLearner.

Definition at line 65 of file ConstantRegressor.cc.

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

simply calls inherited::build() then build_()

Reimplemented from PLearn::PLearner.

Definition at line 95 of file ConstantRegressor.cc.

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

Here is the call graph for this function:

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

This does the actual building.

Reimplemented from PLearn::PLearner.

Definition at line 90 of file ConstantRegressor.cc.

Referenced by build().

{
}

Here is the caller graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 65 of file ConstantRegressor.cc.

void PLearn::ConstantRegressor::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 168 of file ConstantRegressor.cc.

References PLearn::powdistance(), and PLearn::TVec< T >::resize().

{
    // Compute the costs from *already* computed output. 
    costs.resize(1);
    costs[0] = powdistance(output,target);
}                                

Here is the call graph for this function:

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

Computes the output from the input.

Reimplemented from PLearn::PLearner.

Definition at line 161 of file ConstantRegressor.cc.

References constant_output, outputsize(), and PLearn::TVec< T >::resize().

{
    // Compute the output from the input
    output.resize(outputsize());
    output << constant_output;
}    

Here is the call graph for this function:

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

Declares this class' options.

Reimplemented from PLearn::PLearner.

Definition at line 67 of file ConstantRegressor.cc.

References PLearn::OptionBase::buildoption, constant_output, PLearn::declareOption(), PLearn::PLearner::declareOptions(), PLearn::OptionBase::learntoption, and weight_decay.

{
    // ### Declare all of this object's options here
    // ### For the "flags" of each option, you should typically specify  
    // ### one of OptionBase::buildoption, OptionBase::learntoption or 
    // ### OptionBase::tuningoption. Another possible flag to be combined with
    // ### is OptionBase::nosave

    declareOption(ol, "weight_decay", &ConstantRegressor::weight_decay,
                  OptionBase::buildoption,
                  "Weight decay parameter. Default=0.  NOT CURRENTLY TAKEN INTO ACCOUNT!");
  
    // ### ex:
    declareOption(ol, "constant_output", &ConstantRegressor::constant_output, 
                  OptionBase::learntoption,
                  "This is the learnt parameter, the constant output. During training\n"
                  "It is set to the (possibly weighted) average of the targets.\n"
        );

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

Here is the call graph for this function:

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

Reimplemented from PLearn::PLearner.

Definition at line 112 of file ConstantRegressor.h.

ConstantRegressor * PLearn::ConstantRegressor::deepCopy ( CopiesMap copies) const [virtual]

Reimplemented from PLearn::PLearner.

Definition at line 65 of file ConstantRegressor.cc.

void PLearn::ConstantRegressor::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 113 of file ConstantRegressor.cc.

{
    // Since this is a one-shot learner, there is nothing to forget.
}
OptionList & PLearn::ConstantRegressor::getOptionList ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 65 of file ConstantRegressor.cc.

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

Reimplemented from PLearn::Object.

Definition at line 65 of file ConstantRegressor.cc.

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

Reimplemented from PLearn::Object.

Definition at line 65 of file ConstantRegressor.cc.

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

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

Implements PLearn::PLearner.

Definition at line 176 of file ConstantRegressor.cc.

References getTrainCostNames().

{
    // Return the names of the costs computed by computeCostsFromOutpus
    return getTrainCostNames();
}

Here is the call graph for this function:

TVec< string > PLearn::ConstantRegressor::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 182 of file ConstantRegressor.cc.

Referenced by getTestCostNames().

{
    // Return the names of the objective costs that the train method computes and 
    // for which it updates the VecStatsCollector train_stats
    return TVec<string>(1,"mse");
}

Here is the caller graph for this function:

void PLearn::ConstantRegressor::makeDeepCopyFromShallowCopy ( CopiesMap copies) [virtual]

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::PLearner.

Definition at line 102 of file ConstantRegressor.cc.

References PLearn::PLearner::makeDeepCopyFromShallowCopy().

Here is the call graph for this function:

int PLearn::ConstantRegressor::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 108 of file ConstantRegressor.cc.

References PLearn::PLearner::targetsize().

Referenced by computeOutput().

{
    return targetsize();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void PLearn::ConstantRegressor::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 118 of file ConstantRegressor.cc.

References PLearn::TVec< T >::clear(), constant_output, PLearn::VMat::getExample(), PLearn::TVec< T >::hasMissing(), i, PLearn::PLearner::inputsize(), PLearn::VMat::length(), PLearn::multiply(), PLearn::multiplyAdd(), PLearn::PLearner::n_examples, PLearn::powdistance(), PLearn::TVec< T >::resize(), PLearn::PLearner::targetsize(), PLearn::PLearner::train_set, and PLearn::PLearner::train_stats.

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

    Vec input;  // Not static because God knows who may be using a ConstantRegressor.
    Vec target;
    Vec train_costs;
    Vec sum_of_weighted_targets;
    real weight;
    train_costs.resize(1);
    input.resize(inputsize());    // the train_set's inputsize()
    target.resize(targetsize());  // the train_set's targetsize()
    sum_of_weighted_targets.resize(targetsize());  // the running sum of weighted targets
    constant_output.resize(targetsize());

    if(!train_stats)  // make a default stats collector, in case there's none
        train_stats = new VecStatsCollector();

    real sum_of_weights = 0;
    sum_of_weighted_targets.clear();
      
    int n_examples = train_set->length();
    for (int i=0;i<n_examples;i++)
    {
        train_set->getExample(i, input, target, weight);

        // Skip the observation if it has any missings... (for now, next
        // version should only skip the components that have a missing value)
        if (target.hasMissing())
            continue;
      
        multiplyAdd(sum_of_weighted_targets,target,weight,sum_of_weighted_targets);
        sum_of_weights += weight;
        multiply(sum_of_weighted_targets,real(1.0/sum_of_weights),constant_output);
        train_costs[0] =
            weight*powdistance(constant_output,target);
        train_stats->update(train_costs);
    }
    train_stats->finalize(); // finalize statistics for this one and only epoch
}

Here is the call graph for this function:


Member Data Documentation

Reimplemented from PLearn::PLearner.

Definition at line 112 of file ConstantRegressor.h.

Definition at line 60 of file ConstantRegressor.h.

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

Weight decay; not usually useful but...

Definition at line 65 of file ConstantRegressor.h.

Referenced by declareOptions().


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