PLearn 0.1
|
The first sentence should be a BRIEF DESCRIPTION of what the class does. More...
#include <ChainedLearners.h>
Public Member Functions | |
ChainedLearners () | |
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 | setTrainingSet (VMat training_set, bool call_forget=true) |
Declares the training set. | |
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 |
Returns a vector of length outputsize() containing the outputs' names. | |
virtual void | setExperimentDirectory (const PPath &the_expdir) |
The experiment directory is the directory in which files related to this model are to be saved. | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual ChainedLearners * | deepCopy (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 PPath & | declaringFile () |
Public Attributes | |
TVec< PP< PLearner > > | learners |
### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //! | |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declares the class options. | |
Protected Attributes | |
Vec | tmp_input |
Vec | tmp_output |
Global storage to save memory allocations. | |
Private Types | |
typedef PLearner | inherited |
Private Member Functions | |
void | build_ () |
This does the actual building. |
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
Definition at line 57 of file ChainedLearners.h.
typedef PLearner PLearn::ChainedLearners::inherited [private] |
Reimplemented from PLearn::PLearner.
Definition at line 59 of file ChainedLearners.h.
PLearn::ChainedLearners::ChainedLearners | ( | ) |
string PLearn::ChainedLearners::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::PLearner.
Definition at line 56 of file ChainedLearners.cc.
OptionList & PLearn::ChainedLearners::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::PLearner.
Definition at line 56 of file ChainedLearners.cc.
RemoteMethodMap & PLearn::ChainedLearners::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::PLearner.
Definition at line 56 of file ChainedLearners.cc.
Reimplemented from PLearn::PLearner.
Definition at line 56 of file ChainedLearners.cc.
Object * PLearn::ChainedLearners::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 56 of file ChainedLearners.cc.
StaticInitializer ChainedLearners::_static_initializer_ & PLearn::ChainedLearners::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::PLearner.
Definition at line 56 of file ChainedLearners.cc.
void PLearn::ChainedLearners::build | ( | ) | [virtual] |
Finish building the object; just call inherited::build followed by build_()
Reimplemented from PLearn::PLearner.
Definition at line 86 of file ChainedLearners.cc.
{ inherited::build(); build_(); }
void PLearn::ChainedLearners::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::PLearner.
Definition at line 71 of file ChainedLearners.cc.
{ // ### 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. }
string PLearn::ChainedLearners::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 56 of file ChainedLearners.cc.
void PLearn::ChainedLearners::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 204 of file ChainedLearners.cc.
{ // this is generally called after a computeOutput, so the last learner's input // we used was stored in tmp_output return learners.lastElement()->computeCostsFromOutputs(tmp_output, output, target, costs); }
Computes the output from the input.
Reimplemented from PLearn::PLearner.
Definition at line 182 of file ChainedLearners.cc.
References n.
{ int nlearners = learners.length(); if(nlearners==1) learners[0]->computeOutput(input, output); else { tmp_output.resize(learners[0]->outputsize()); learners[0]->computeOutput(input, tmp_output); for(int k=1; k<nlearners-1; k++) { int n = tmp_output.length(); tmp_input.resize(n); tmp_input << tmp_output; tmp_output->resize(learners[k]->outputsize()); learners[k]->computeOutput(tmp_input, tmp_output); } learners[nlearners-1]->computeOutput(tmp_output, output); } }
void PLearn::ChainedLearners::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares the class options.
Reimplemented from PLearn::PLearner.
Definition at line 61 of file ChainedLearners.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), and learners.
{ declareOption(ol, "learners", &ChainedLearners::learners, OptionBase::buildoption, "This is a list of learners to train in sequence."); // Now call the parent class' declareOptions inherited::declareOptions(ol); }
static const PPath& PLearn::ChainedLearners::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::PLearner.
Definition at line 147 of file ChainedLearners.h.
:
//##### Protected Options ###############################################
ChainedLearners * PLearn::ChainedLearners::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::PLearner.
Definition at line 56 of file ChainedLearners.cc.
void PLearn::ChainedLearners::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!).
(Re-)initialize 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!)
A typical forget() method should do the following:
Reimplemented from PLearn::PLearner.
Definition at line 107 of file ChainedLearners.cc.
{ for(int k=0; k<learners.length(); k++) learners[k]->forget(); inherited::forget(); stage = 0; }
OptionList & PLearn::ChainedLearners::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 56 of file ChainedLearners.cc.
OptionMap & PLearn::ChainedLearners::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 56 of file ChainedLearners.cc.
TVec< string > PLearn::ChainedLearners::getOutputNames | ( | ) | const [virtual] |
Returns a vector of length outputsize() containing the outputs' names.
Default version returns ["out0", "out1", ...] Don't forget name should not have space or it will cause trouble when they are saved in the file {metadatadir}/fieldnames
Reimplemented from PLearn::PLearner.
Definition at line 223 of file ChainedLearners.cc.
References PLearn::TVec< T >::lastElement().
{ return learners.lastElement()->getOutputNames(); }
RemoteMethodMap & PLearn::ChainedLearners::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 56 of file ChainedLearners.cc.
TVec< string > PLearn::ChainedLearners::getTestCostNames | ( | ) | const [virtual] |
Returns the names of the costs computed by computeCostsFromOutpus (and thus the test method).
Implements PLearn::PLearner.
Definition at line 212 of file ChainedLearners.cc.
{ return learners.lastElement()->getTestCostNames(); }
TVec< string > PLearn::ChainedLearners::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 217 of file ChainedLearners.cc.
{ return learners.lastElement()->getTrainCostNames(); }
void PLearn::ChainedLearners::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::PLearner.
Definition at line 93 of file ChainedLearners.cc.
References PLearn::deepCopyField().
{ inherited::makeDeepCopyFromShallowCopy(copies); deepCopyField(learners, copies); deepCopyField(tmp_input, copies); deepCopyField(tmp_output, copies); }
int PLearn::ChainedLearners::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 102 of file ChainedLearners.cc.
{ return learners.lastElement()->outputsize(); }
void PLearn::ChainedLearners::setExperimentDirectory | ( | const PPath & | the_expdir | ) | [virtual] |
The experiment directory is the directory in which files related to this model are to be saved.
If it is an empty string, it is understood to mean that the user doesn't want any file created by this learner.
Reimplemented from PLearn::PLearner.
Definition at line 229 of file ChainedLearners.cc.
References PLearn::PPath::isEmpty(), and PLearn::tostring().
{ inherited::setExperimentDirectory(the_expdir); if (! the_expdir.isEmpty()) for(int k= 0; k < learners.length(); ++k) learners[k]->setExperimentDirectory(the_expdir / ("SubLearner_"+tostring(k))); }
void PLearn::ChainedLearners::setTrainingSet | ( | VMat | training_set, |
bool | call_forget = true |
||
) | [virtual] |
Declares the training set.
Then calls build() and forget() if necessary. Also sets this learner's inputsize_ targetsize_ weightsize_ from those of the training_set. Note: You shouldn't have to override this in subclasses, except in maybe to forward the call to an underlying learner.
Reimplemented from PLearn::PLearner.
Definition at line 126 of file ChainedLearners.cc.
{ inherited::setTrainingSet(training_set, call_forget); VMat dataset = getTrainingSet(); int nlearners = learners.length(); for(int k=0; k<nlearners; k++) { learners[k]->setTrainingSet(dataset, call_forget); if(k<nlearners-1) dataset = learners[k]->processDataSet(dataset); } }
void PLearn::ChainedLearners::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 139 of file ChainedLearners.cc.
{ // 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. // This generic PLearner method does a number of standard stuff useful for // (almost) any learner, and return 'false' if no training should take // place. See PLearner.h for more details. if (!initTrain()) return; VMat dataset = getTrainingSet(); int nlearners = learners.length(); if(stage>nstages) forget(); if(stage==0) { for(int k=0; k<nlearners; k++) { learners[k]->setTrainingSet(dataset); if(k<nlearners-1) { learners[k]->train(); dataset = learners[k]->processDataSet(dataset); } else // last learner { learners[k]->setTrainStatsCollector(train_stats); train_stats->forget(); learners[k]->train(); train_stats->finalize(); } } ++stage; } else // stage already==1 { // only call train on last learner, in case its own nstages has changed or something similar learners[nlearners-1]->train(); } }
Reimplemented from PLearn::PLearner.
Definition at line 147 of file ChainedLearners.h.
### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //!
Definition at line 67 of file ChainedLearners.h.
Referenced by declareOptions().
Vec PLearn::ChainedLearners::tmp_input [mutable, protected] |
Definition at line 165 of file ChainedLearners.h.
Vec PLearn::ChainedLearners::tmp_output [mutable, protected] |
Global storage to save memory allocations.
Reimplemented from PLearn::PLearner.
Definition at line 166 of file ChainedLearners.h.