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

PLearn::EmbeddedLearner Class Reference

#include <EmbeddedLearner.h>

Inheritance diagram for PLearn::EmbeddedLearner:

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

Collaboration graph
[legend]
List of all members.

Public Types

typedef PLearner inherited

Public Member Functions

 EmbeddedLearner ()
virtual void build ()
 **** SUBCLASS WRITING: **** This method should be redefined in subclasses, to just call inherited::build() and then build_()

virtual void makeDeepCopyFromShallowCopy (map< const void *, void * > &copies)
 Transforms a shallow copy into a deep copy.

 PLEARN_DECLARE_OBJECT (EmbeddedLearner)
 Declares name and deepCopy methods.

virtual int inputsize () const
 Default returns train_set->inputsize().

virtual int targetsize () const
 Default returns train_set->targetsize().

virtual int outputsize () const
 SUBCLASS WRITING: overload this so that it returns the size of this learner's output, as a function of 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 stats with training costs measured on-line in the process.

virtual void test (VMat testset, PP< VecStatsCollector > test_stats, VMat testoutputs=0, VMat testcosts=0) const
 Override the test method to forward to embedded learner's test method.

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.

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 TVec< stringgetTestCostNames () const
 *** SUBCLASS WRITING: *** This should return the names of the costs computed by computeCostsFromOutpus

virtual TVec< stringgetTrainCostNames () const
 *** SUBCLASS WRITING: *** This should return the names of the objective costs that the train method computes and for which it updates the VecStatsCollector train_stats


Public Attributes

PP< PLearnerlearner_

Static Protected Member Functions

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


Private Member Functions

void build_ ()
 This does the actual building.


Member Typedef Documentation

typedef PLearner PLearn::EmbeddedLearner::inherited
 

Reimplemented from PLearn::PLearner.

Reimplemented in PLearn::SelectInputSubsetLearner.

Definition at line 59 of file EmbeddedLearner.h.


Constructor & Destructor Documentation

PLearn::EmbeddedLearner::EmbeddedLearner  ) 
 

Definition at line 53 of file EmbeddedLearner.cc.


Member Function Documentation

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

**** SUBCLASS WRITING: **** This method should be redefined in subclasses, to just call inherited::build() and then build_()

Reimplemented from PLearn::PLearner.

Reimplemented in PLearn::SelectInputSubsetLearner.

Definition at line 71 of file EmbeddedLearner.cc.

References build_().

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

This does the actual building.

Reimplemented from PLearn::PLearner.

Reimplemented in PLearn::SelectInputSubsetLearner.

Definition at line 63 of file EmbeddedLearner.cc.

References learner_, and PLERROR.

Referenced by build().

void PLearn::EmbeddedLearner::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::SelectInputSubsetLearner.

Definition at line 104 of file EmbeddedLearner.cc.

References learner_.

void PLearn::EmbeddedLearner::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.

Definition at line 116 of file EmbeddedLearner.cc.

References learner_.

void PLearn::EmbeddedLearner::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::SelectInputSubsetLearner.

Definition at line 99 of file EmbeddedLearner.cc.

References learner_, and PLearn::Vec.

void PLearn::EmbeddedLearner::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::SelectInputSubsetLearner.

Definition at line 110 of file EmbeddedLearner.cc.

References learner_.

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

Declares this class' options.

Reimplemented from PLearn::PLearner.

Reimplemented in PLearn::SelectInputSubsetLearner.

Definition at line 56 of file EmbeddedLearner.cc.

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

void PLearn::EmbeddedLearner::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.

Definition at line 78 of file EmbeddedLearner.cc.

References learner_.

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

*** SUBCLASS WRITING: *** This should return the names of the costs computed by computeCostsFromOutpus

Implements PLearn::PLearner.

Definition at line 119 of file EmbeddedLearner.cc.

References learner_.

TVec< string > PLearn::EmbeddedLearner::getTrainCostNames  )  const [virtual]
 

*** SUBCLASS WRITING: *** This should return 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 122 of file EmbeddedLearner.cc.

References learner_.

int PLearn::EmbeddedLearner::inputsize  )  const [virtual]
 

Default returns train_set->inputsize().

Reimplemented from PLearn::PLearner.

Reimplemented in PLearn::SelectInputSubsetLearner.

Definition at line 81 of file EmbeddedLearner.cc.

References learner_.

void PLearn::EmbeddedLearner::makeDeepCopyFromShallowCopy map< const void *, void * > &  copies  )  [virtual]
 

Transforms a shallow copy into a deep copy.

Reimplemented in PLearn::SelectInputSubsetLearner.

Definition at line 125 of file EmbeddedLearner.cc.

References PLearn::deepCopyField(), and learner_.

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

SUBCLASS WRITING: overload this so that it returns the size of this learner's output, as a function of its inputsize(), targetsize() and set options.

Implements PLearn::PLearner.

Definition at line 87 of file EmbeddedLearner.cc.

References learner_.

PLearn::EmbeddedLearner::PLEARN_DECLARE_OBJECT EmbeddedLearner   ) 
 

Declares name and deepCopy methods.

int PLearn::EmbeddedLearner::targetsize  )  const [virtual]
 

Default returns train_set->targetsize().

Reimplemented from PLearn::PLearner.

Definition at line 84 of file EmbeddedLearner.cc.

References learner_.

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

Override the test method to forward to embedded learner's test method.

Reimplemented from PLearn::PLearner.

Definition at line 93 of file EmbeddedLearner.cc.

References learner_.

void PLearn::EmbeddedLearner::train  )  [virtual]
 

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

*** SUBCLASS WRITING: ***

TYPICAL CODE:

static Vec input; // static so we don't reallocate/deallocate memory each time... static Vec target; // (but be careful that static means shared!) input.resize(inputsize()); // the train_set's inputsize() target.resize(targetsize()); // the train_set's targetsize() real weight;

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

if(nstages<stage) // asking to revert to a previous stage! forget(); // reset the learner to stage=0

while(stage<nstages) { clear statistics of previous epoch train_stats->forget();

... train for 1 stage, and update train_stats, using train_set->getSample(input, target, weight); and train_stats->update(train_costs)

++stage; train_stats->finalize(); // finalize statistics for this epoch }

Implements PLearn::PLearner.

Definition at line 90 of file EmbeddedLearner.cc.

References learner_.


Member Data Documentation

PP<PLearner> PLearn::EmbeddedLearner::learner_
 

Definition at line 56 of file EmbeddedLearner.h.

Referenced by build_(), computeCostsFromOutputs(), computeCostsOnly(), computeOutput(), computeOutputAndCosts(), forget(), getTestCostNames(), getTrainCostNames(), inputsize(), makeDeepCopyFromShallowCopy(), outputsize(), targetsize(), test(), and train().


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