Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

PLearn::SequentialLearner Class Reference

#include <SequentialLearner.h>

Inheritance diagram for PLearn::SequentialLearner:

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

Collaboration graph
[legend]
List of all members.

Public Types

typedef PLearner inherited

Public Member Functions

int get_last_train_t ()
 last value of test_set.length() for which testing was actually done

int get_last_call_train_t ()
int get_last_test_t ()
 SequentialLearner ()
 Constructor.

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

virtual int outputsize () const
 Returns train_set->targetsize().

virtual int nTestCosts () const
 Caches getTestCostNames().size() in an internal variable the first time it is called, and then returns the content of this variable.

virtual void setTrainingSet (VMat training_set, bool call_forget=true)
 Declares the train_set Then calls build() and forget() if necessary Note: You shouldn't have to overload this in subclasses, except in maybe to forward the call to an underlying learner.

virtual void train ()=0
virtual void test (VMat testset, PP< VecStatsCollector > test_stats, VMat testoutputs=0, VMat testcosts=0) const =0
virtual void computeOutputAndCosts (const Vec &input, const Vec &target, Vec &output, Vec &costs) const
 Default calls computeOutput and computeCostsFromOutputs You may overload this if you have a more efficient way to compute both output and weighted costs at the same time.

virtual void computeCostsOnly (const Vec &input, const Vec &target, Vec &costs) const
 Default calls computeOutputAndCosts This may be overloaded if there is a more efficient way to compute the costs directly, without computing the whole output vector.

virtual void computeOutput (const Vec &input, Vec &output) const
 *** SUBCLASS WRITING: *** This should be defined in subclasses to compute the output from the input

virtual void computeCostsFromOutputs (const Vec &input, const Vec &output, const Vec &target, Vec &costs) const
 *** SUBCLASS WRITING: *** This should be defined in subclasses to compute the weighted costs from already computed output.

int sequenceStart () const
int sequenceLength () const
Vec getCostSequence (int cost_index) const
Vec getCostSequence (string cname) const
virtual void matlabSave (const string &matlab_subdir)
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!)

 PLEARN_DECLARE_ABSTRACT_OBJECT (SequentialLearner)
 Does the necessary operations to transform a shallow copy (this) into a deep copy by deep-copying all the members that need to be.

virtual void makeDeepCopyFromShallowCopy (CopiesMap &copies)

Public Attributes

int init_train_size
int max_seq_len
 max length of the VMat that train can contain = max de t ci-haut

int max_train_len
 max nb of (input,target) pairs actually used for training

int train_step
 how often we have to re-train a model, (default = 1 = after every time step)

int horizon
 by how much to offset the target columns wrt the input columns (default = 1)

int outputsize_
Mat predictions
 these two fields are used by other classes such as SequentialModelSelector and SequentialValidation and they are filled when the method test is called

Mat errors
 initial values may be 'missing value'


Static Protected Member Functions

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


Protected Attributes

int last_train_t
int last_call_train_t
 last value of train_set.length() for which training was actually done (<= last_call_train_t)

int last_test_t
 last value of train_set.length() for which train() was called (may not have done anything)


Private Member Functions

void build_ ()
 This does the actual building.


Detailed Description

We use the following conventions throughout this module:

Definition at line 57 of file SequentialLearner.h.


Member Typedef Documentation

typedef PLearner PLearn::SequentialLearner::inherited
 

Reimplemented from PLearn::PLearner.

Reimplemented in PLearn::MovingAverage, and PLearn::SequentialModelSelector.

Definition at line 60 of file SequentialLearner.h.


Constructor & Destructor Documentation

PLearn::SequentialLearner::SequentialLearner  ) 
 

Constructor.

Definition at line 46 of file SequentialLearner.cc.


Member Function Documentation

void PLearn::SequentialLearner::build  )  [virtual]
 

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

Reimplemented from PLearn::PLearner.

Reimplemented in PLearn::EmbeddedSequentialLearner, PLearn::MovingAverage, and PLearn::SequentialModelSelector.

Definition at line 78 of file SequentialLearner.cc.

References build_().

void PLearn::SequentialLearner::build_  )  [private]
 

This does the actual building.

Reimplemented from PLearn::PLearner.

Reimplemented in PLearn::EmbeddedSequentialLearner, PLearn::MovingAverage, and PLearn::SequentialModelSelector.

Definition at line 59 of file SequentialLearner.cc.

References errors, PLearn::TMat< T >::fill(), max_seq_len, MISSING_VALUE, nTestCosts(), outputsize(), PLERROR, predictions, and PLearn::TMat< T >::resize().

Referenced by build().

void PLearn::SequentialLearner::computeCostsFromOutputs const Vec input,
const Vec output,
const Vec target,
Vec costs
const [virtual]
 

*** SUBCLASS WRITING: *** This should be defined in subclasses to compute the weighted costs from already computed output.

The costs should correspond to the cost names returned by getTestCostNames() NOTE: In exotic cases, the cost may also depend on some info in the input, that's why the method also gets so see it.

Implements PLearn::PLearner.

Reimplemented in PLearn::MovingAverage, and PLearn::SequentialModelSelector.

Definition at line 154 of file SequentialLearner.cc.

References PLERROR.

void PLearn::SequentialLearner::computeCostsOnly const Vec input,
const Vec target,
Vec costs
const [virtual]
 

Default calls computeOutputAndCosts This may be overloaded if there is a more efficient way to compute the costs directly, without computing the whole output vector.

Reimplemented from PLearn::PLearner.

Reimplemented in PLearn::SequentialModelSelector.

Definition at line 147 of file SequentialLearner.cc.

References PLERROR.

void PLearn::SequentialLearner::computeOutput const Vec input,
Vec output
const [virtual]
 

*** SUBCLASS WRITING: *** This should be defined in subclasses to compute the output from the input

Implements PLearn::PLearner.

Reimplemented in PLearn::SequentialModelSelector.

Definition at line 151 of file SequentialLearner.cc.

References PLERROR.

void PLearn::SequentialLearner::computeOutputAndCosts const Vec input,
const Vec target,
Vec output,
Vec costs
const [virtual]
 

Default calls computeOutput and computeCostsFromOutputs You may overload this if you have a more efficient way to compute both output and weighted costs at the same time.

Reimplemented from PLearn::PLearner.

Reimplemented in PLearn::SequentialModelSelector.

Definition at line 143 of file SequentialLearner.cc.

References PLERROR, and PLearn::Vec.

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

Declare this class' options.

Reimplemented from PLearn::PLearner.

Reimplemented in PLearn::EmbeddedSequentialLearner, PLearn::MovingAverage, and PLearn::SequentialModelSelector.

Definition at line 84 of file SequentialLearner.cc.

References PLearn::declareOption(), and PLearn::OptionList.

void PLearn::SequentialLearner::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!)

*** SUBCLASS WRITING: *** A typical forget() method should do the following:

  • initialize a random number generator with the seed option
  • initialize the learner's parameters, using this random generator
  • stage = 0; This method is typically called by the build_() method, after it has finished setting up the parameters, and if it deemed useful to set or reset the learner in its fresh state. (remember build may be called after modifying options that do not necessarily require the learner to restart from a fresh state...) forget is also called by the setTrainingSet method, after calling build(), so it will generally be called TWICE during setTrainingSet!

Implements PLearn::PLearner.

Reimplemented in PLearn::EmbeddedSequentialLearner, PLearn::MovingAverage, and PLearn::SequentialModelSelector.

Definition at line 125 of file SequentialLearner.cc.

References errors, PLearn::TMat< T >::fill(), PLearn::TMat< T >::isNotEmpty(), last_call_train_t, last_test_t, last_train_t, MISSING_VALUE, and predictions.

Referenced by setTrainingSet().

int PLearn::SequentialLearner::get_last_call_train_t  )  [inline]
 

Definition at line 69 of file SequentialLearner.h.

References last_call_train_t.

int PLearn::SequentialLearner::get_last_test_t  )  [inline]
 

Definition at line 70 of file SequentialLearner.h.

References last_test_t.

int PLearn::SequentialLearner::get_last_train_t  )  [inline]
 

last value of test_set.length() for which testing was actually done

Definition at line 68 of file SequentialLearner.h.

References last_train_t.

Vec PLearn::SequentialLearner::getCostSequence string  cname  )  const [inline]
 

Definition at line 155 of file SequentialLearner.h.

Vec PLearn::SequentialLearner::getCostSequence int  cost_index  )  const [inline]
 

Definition at line 153 of file SequentialLearner.h.

References errors, getCostSequence(), sequenceLength(), sequenceStart(), and PLearn::TMat< T >::subMat().

Referenced by getCostSequence(), and matlabSave().

void PLearn::SequentialLearner::makeDeepCopyFromShallowCopy CopiesMap copies  )  [virtual]
 

Does the necessary operations to transform a shallow copy (this) into a deep copy by deep-copying all the members that need to be. Typical implementation:

void CLASS_OF_THIS::makeDeepCopyFromShallowCopy(CopiesMap& copies) { SUPERCLASS_OF_THIS::makeDeepCopyFromShallowCopy(copies); member_ptr = member_ptr->deepCopy(copies); member_smartptr = member_smartptr->deepCopy(copies); member_mat.makeDeepCopyFromShallowCopy(copies); member_vec.makeDeepCopyFromShallowCopy(copies); ... }

Reimplemented from PLearn::PLearner.

Reimplemented in PLearn::EmbeddedSequentialLearner, and PLearn::SequentialModelSelector.

Definition at line 52 of file SequentialLearner.cc.

References PLearn::CopiesMap, PLearn::deepCopyField(), errors, and predictions.

void PLearn::SequentialLearner::matlabSave const string matlab_subdir  )  [virtual]
 

Any SequentialLearner will have the possiblity to save some data in a matlab 'readable' format. The data will be saved in expdir/matlab_subdir through the global matlabSave function (MatIO.h).

Reimplemented from PLearn::PLearner.

Reimplemented in PLearn::SequentialModelSelector.

Definition at line 158 of file SequentialLearner.cc.

References PLearn::add(), PLearn::append_slash(), getCostSequence(), PLearn::PLearner::getExperimentDirectory(), PLearn::PLearner::getTestCostNames(), PLearn::TVec< T >::length(), PLearn::matlabSave(), predictions, and sequenceStart().

int PLearn::SequentialLearner::nTestCosts  )  const [virtual]
 

Caches getTestCostNames().size() in an internal variable the first time it is called, and then returns the content of this variable.

Reimplemented from PLearn::PLearner.

Definition at line 140 of file SequentialLearner.cc.

References PLearn::PLearner::getTestCostNames(), and PLearn::TVec< string >::size().

Referenced by build_(), and PLearn::EmbeddedSequentialLearner::test().

int PLearn::SequentialLearner::outputsize  )  const [virtual]
 

Returns train_set->targetsize().

Implements PLearn::PLearner.

Definition at line 137 of file SequentialLearner.cc.

References outputsize_.

Referenced by build_(), PLearn::MovingAverage::test(), PLearn::EmbeddedSequentialLearner::test(), and PLearn::MovingAverage::train().

PLearn::SequentialLearner::PLEARN_DECLARE_ABSTRACT_OBJECT SequentialLearner   ) 
 

Does the necessary operations to transform a shallow copy (this) into a deep copy by deep-copying all the members that need to be.

int PLearn::SequentialLearner::sequenceLength  )  const [inline]
 

Definition at line 152 of file SequentialLearner.h.

References init_train_size, and last_test_t.

Referenced by getCostSequence().

int PLearn::SequentialLearner::sequenceStart  )  const [inline]
 

The getCostSequence method returns the sequence of the cost at index 'cost_index' or named 'cname' from sequenceStart() with a length of sequenceLength().

Definition at line 151 of file SequentialLearner.h.

References init_train_size.

Referenced by getCostSequence(), and matlabSave().

void PLearn::SequentialLearner::setTrainingSet VMat  training_set,
bool  call_forget = true
[virtual]
 

Declares the train_set Then calls build() and forget() if necessary Note: You shouldn't have to overload this in subclasses, except in maybe to forward the call to an underlying learner.

Reimplemented from PLearn::PLearner.

Definition at line 119 of file SequentialLearner.cc.

References forget().

virtual void PLearn::SequentialLearner::test VMat  testset,
PP< VecStatsCollector test_stats,
VMat  testoutputs = 0,
VMat  testcosts = 0
const [pure virtual]
 

*** SUBCLASS WRITING: *** The method should:

  • call computeOutputAndCosts on the test set
  • save the outputs and the costs in the predictions & errors matrices, beginning at position last_call_train_t

Reimplemented from PLearn::PLearner.

Implemented in PLearn::EmbeddedSequentialLearner, PLearn::MovingAverage, and PLearn::SequentialModelSelector.

virtual void PLearn::SequentialLearner::train  )  [pure virtual]
 

*** SUBCLASS WRITING: *** Does the actual training. Subclasses must implement this method. The method should upon entry, call setTrainingSet(training_set); The method should:

  • do nothing if we already called it with this value of train.length or a value between [last_train_t-train_step+1,last_train_t]
  • if not, train and update the value of last_train_t
  • in either case, update the value of last_call_train_t

Implements PLearn::PLearner.

Implemented in PLearn::EmbeddedSequentialLearner, PLearn::MovingAverage, and PLearn::SequentialModelSelector.


Member Data Documentation

Mat PLearn::SequentialLearner::errors
 

initial values may be 'missing value'

Definition at line 89 of file SequentialLearner.h.

Referenced by build_(), forget(), getCostSequence(), and makeDeepCopyFromShallowCopy().

int PLearn::SequentialLearner::horizon
 

by how much to offset the target columns wrt the input columns (default = 1)

Definition at line 82 of file SequentialLearner.h.

int PLearn::SequentialLearner::init_train_size
 

Before the length of train_set reaches init_train_size, train doesn't do anything. Default: 1.

Definition at line 78 of file SequentialLearner.h.

Referenced by sequenceLength(), and sequenceStart().

int PLearn::SequentialLearner::last_call_train_t [protected]
 

last value of train_set.length() for which training was actually done (<= last_call_train_t)

Definition at line 64 of file SequentialLearner.h.

Referenced by forget(), and get_last_call_train_t().

int PLearn::SequentialLearner::last_test_t [mutable, protected]
 

last value of train_set.length() for which train() was called (may not have done anything)

Definition at line 65 of file SequentialLearner.h.

Referenced by forget(), get_last_test_t(), and sequenceLength().

int PLearn::SequentialLearner::last_train_t [protected]
 

Definition at line 63 of file SequentialLearner.h.

Referenced by forget(), and get_last_train_t().

int PLearn::SequentialLearner::max_seq_len
 

max length of the VMat that train can contain = max de t ci-haut

Definition at line 79 of file SequentialLearner.h.

Referenced by build_().

int PLearn::SequentialLearner::max_train_len
 

max nb of (input,target) pairs actually used for training

Definition at line 80 of file SequentialLearner.h.

int PLearn::SequentialLearner::outputsize_
 

Definition at line 83 of file SequentialLearner.h.

Referenced by outputsize().

Mat PLearn::SequentialLearner::predictions
 

these two fields are used by other classes such as SequentialModelSelector and SequentialValidation and they are filled when the method test is called

Definition at line 87 of file SequentialLearner.h.

Referenced by build_(), forget(), makeDeepCopyFromShallowCopy(), and matlabSave().

int PLearn::SequentialLearner::train_step
 

how often we have to re-train a model, (default = 1 = after every time step)

Definition at line 81 of file SequentialLearner.h.


The documentation for this class was generated from the following files:
Generated on Tue Aug 17 16:27:48 2004 for PLearn by doxygen 1.3.7