PLearn 0.1
|
#include <EmbeddedSequentialLearner.h>
Public Member Functions | |
EmbeddedSequentialLearner () | |
Constructor. | |
virtual void | build () |
simply calls inherited::build() then build_() | |
virtual void | train () |
Does the actual training. | |
virtual void | test (VMat testset, PP< VecStatsCollector > test_stats, VMat testoutputs=0, VMat testcosts=0) const |
virtual void | makeDeepCopyFromShallowCopy (CopiesMap &copies) |
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 | forget () |
*** SUBCLASS WRITING: *** | |
virtual void | computeOutput (const Vec &input, Vec &output) |
virtual void | computeCostsFromOutputs (const Vec &input, const Vec &output, const Vec &target, Vec &costs) |
virtual void | computeOutputAndCosts (const Vec &input, const Vec &target, Vec &output, Vec &costs) |
virtual void | computeCostsOnly (const Vec &input, const Vec &target, Vec &costs) |
virtual TVec< string > | getTestCostNames () const |
*** SUBCLASS WRITING: *** | |
virtual TVec< string > | getTrainCostNames () const |
*** SUBCLASS WRITING: *** | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual EmbeddedSequentialLearner * | deepCopy (CopiesMap &copies) const |
Static Public Member Functions | |
static string | _classname_ () |
Declares a few other classes and functions related to this class. | |
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 | |
PP< PLearner > | learner |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declare this class' options. | |
Private Member Functions | |
void | build_ () |
This does the actual building. |
This SequentialLearner simply embeddes a Learner that we wish to train sequentially. Most of the methods simply forward the call to the underlying Learner.
Definition at line 51 of file EmbeddedSequentialLearner.h.
PLearn::EmbeddedSequentialLearner::EmbeddedSequentialLearner | ( | ) |
string PLearn::EmbeddedSequentialLearner::_classname_ | ( | ) | [static] |
Declares a few other classes and functions related to this class.
Reimplemented from PLearn::SequentialLearner.
Definition at line 47 of file EmbeddedSequentialLearner.cc.
OptionList & PLearn::EmbeddedSequentialLearner::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::SequentialLearner.
Definition at line 47 of file EmbeddedSequentialLearner.cc.
RemoteMethodMap & PLearn::EmbeddedSequentialLearner::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::SequentialLearner.
Definition at line 47 of file EmbeddedSequentialLearner.cc.
Reimplemented from PLearn::SequentialLearner.
Definition at line 47 of file EmbeddedSequentialLearner.cc.
Object * PLearn::EmbeddedSequentialLearner::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 47 of file EmbeddedSequentialLearner.cc.
StaticInitializer EmbeddedSequentialLearner::_static_initializer_ & PLearn::EmbeddedSequentialLearner::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::SequentialLearner.
Definition at line 47 of file EmbeddedSequentialLearner.cc.
void PLearn::EmbeddedSequentialLearner::build | ( | ) | [virtual] |
simply calls inherited::build() then build_()
Reimplemented from PLearn::SequentialLearner.
Definition at line 68 of file EmbeddedSequentialLearner.cc.
{ inherited::build(); build_(); }
void PLearn::EmbeddedSequentialLearner::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::SequentialLearner.
Definition at line 58 of file EmbeddedSequentialLearner.cc.
References PLERROR.
string PLearn::EmbeddedSequentialLearner::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 47 of file EmbeddedSequentialLearner.cc.
void PLearn::EmbeddedSequentialLearner::computeCostsFromOutputs | ( | const Vec & | input, |
const Vec & | output, | ||
const Vec & | target, | ||
Vec & | costs | ||
) | [virtual] |
Definition at line 172 of file EmbeddedSequentialLearner.cc.
{ learner->computeCostsFromOutputs(input, output, target, costs); }
void PLearn::EmbeddedSequentialLearner::computeCostsOnly | ( | const Vec & | input, |
const Vec & | target, | ||
Vec & | costs | ||
) | [virtual] |
Definition at line 180 of file EmbeddedSequentialLearner.cc.
{ learner->computeCostsOnly(input, target, costs); }
Definition at line 169 of file EmbeddedSequentialLearner.cc.
{ learner->computeOutput(input, output); }
void PLearn::EmbeddedSequentialLearner::computeOutputAndCosts | ( | const Vec & | input, |
const Vec & | target, | ||
Vec & | output, | ||
Vec & | costs | ||
) | [virtual] |
Definition at line 176 of file EmbeddedSequentialLearner.cc.
{ learner->computeOutputAndCosts(input, target, output, costs); }
void PLearn::EmbeddedSequentialLearner::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declare this class' options.
Reimplemented from PLearn::SequentialLearner.
Definition at line 74 of file EmbeddedSequentialLearner.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), and learner.
{ declareOption(ol, "learner", &EmbeddedSequentialLearner::learner, OptionBase::buildoption, "The underlying learner \n"); inherited::declareOptions(ol); }
static const PPath& PLearn::EmbeddedSequentialLearner::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::SequentialLearner.
Definition at line 108 of file EmbeddedSequentialLearner.h.
EmbeddedSequentialLearner * PLearn::EmbeddedSequentialLearner::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::SequentialLearner.
Definition at line 47 of file EmbeddedSequentialLearner.cc.
void PLearn::EmbeddedSequentialLearner::forget | ( | ) | [virtual] |
*** SUBCLASS WRITING: ***
(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!)
A typical forget() method should do the following:
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!
Reimplemented from PLearn::SequentialLearner.
Definition at line 163 of file EmbeddedSequentialLearner.cc.
{ // BUG? call inherited::forget(); ??? learner->forget(); }
OptionList & PLearn::EmbeddedSequentialLearner::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 47 of file EmbeddedSequentialLearner.cc.
OptionMap & PLearn::EmbeddedSequentialLearner::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 47 of file EmbeddedSequentialLearner.cc.
RemoteMethodMap & PLearn::EmbeddedSequentialLearner::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 47 of file EmbeddedSequentialLearner.cc.
TVec< string > PLearn::EmbeddedSequentialLearner::getTestCostNames | ( | ) | const [virtual] |
*** SUBCLASS WRITING: ***
This should return the names of the costs computed by computeCostsFromOutputs.
Implements PLearn::PLearner.
Definition at line 183 of file EmbeddedSequentialLearner.cc.
{ return learner->getTestCostNames(); }
TVec< string > PLearn::EmbeddedSequentialLearner::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 186 of file EmbeddedSequentialLearner.cc.
{ return learner->getTrainCostNames(); }
void PLearn::EmbeddedSequentialLearner::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.
Reimplemented from PLearn::SequentialLearner.
Definition at line 52 of file EmbeddedSequentialLearner.cc.
References PLearn::deepCopyField().
{ inherited::makeDeepCopyFromShallowCopy(copies); deepCopyField(learner, copies); }
void PLearn::EmbeddedSequentialLearner::test | ( | VMat | testset, |
PP< VecStatsCollector > | test_stats, | ||
VMat | testoutputs = 0 , |
||
VMat | testcosts = 0 |
||
) | const [virtual] |
*** SUBCLASS WRITING: *** The method should:
Implements PLearn::SequentialLearner.
Definition at line 105 of file EmbeddedSequentialLearner.cc.
References PLearn::VMat::getExample(), PLearn::TVec< T >::hasMissing(), PLearn::VMat::length(), and MAX.
{ int l = testset.length(); Vec input, target; static Vec dummy_input; real weight; Vec output(testoutputs ?outputsize() :0); Vec costs(nTestCosts()); //testset->defineSizes(inputsize(),targetsize(),weightsize()); //test_stats.forget(); // We DON'T allow in-sample testing; hence, we test either from the end of the // last test, or the end of the training set. The last_train_t MINUS 1 is because // we allow the last training day to be part of the test set. Example: using // today's price, we can train a model and then use it to make a prediction that // has today's price as input (all that WITHOUT CHEATING or breaking the Criminal // Code.) int start = MAX(last_train_t-1,last_test_t); PP<ProgressBar> pb; if(report_progress) pb = new ProgressBar("Testing learner",l-start); for (int t=start; t<testset.length(); t++) { testset.getExample(t, input, target, weight); //testset.getSample(t-last_call_train_t+1, input, dummy_target, weight); //testset.getSample(t-last_call_train_t+1+horizon, dummy_input, target, dummy_weight); if (!input.hasMissing()) { Vec output = predictions(t); learner->computeOutput(input, output); if (testoutputs) testoutputs->appendRow(output); } if (t>=horizon) { Vec output = predictions(t-horizon); if (!target.hasMissing() && !output.hasMissing()) { Vec error_t = errors(t); learner->computeCostsFromOutputs(dummy_input, output, target, error_t); if (testcosts) testcosts->appendRow(error_t); test_stats->update(error_t); } //learner->computeOutputAndCosts(input, target, weight, output, costs); //predictions(t) << output; //errors(t+horizon) << costs; if (pb) pb->update(t-start); } } last_test_t = testset.length(); }
void PLearn::EmbeddedSequentialLearner::train | ( | ) | [virtual] |
Does the actual training.
Implements PLearn::SequentialLearner.
Definition at line 82 of file EmbeddedSequentialLearner.cc.
References PLearn::TmpFilenames::addFilename(), PLearn::filter(), PLearn::VMat::length(), PLearn::max(), and PLearn::VMat::subMatRows().
{ // TODO: this code should be moved to overrided setTrainingSet and setTrainStatsCollector (Pascal&Nicolas) int t = train_set.length(); if (t >= last_train_t+train_step) { VMat aligned_set = new TemporalHorizonVMatrix(train_set, horizon, targetsize()); // last training pair is (t-1-horizon,t-1) int start = (max_train_len<0) ? 0 : max(0,aligned_set.length()-max_train_len); int len = aligned_set.length()-start; TmpFilenames tmpfile; // TODO: Remove the ugly, grotesque, brittle and unnecessay use of an "indexfile" (Nicolas&Pascal) string index_fname = tmpfile.addFilename(); VMat aligned_set_non_missing = filter(aligned_set.subMatRows(start,len), index_fname); learner->setTrainingSet(aligned_set_non_missing); learner->setTrainStatsCollector(train_stats); learner->train(); last_train_t = t; } // BUG? what about setting last_call_train_t ??? }
Reimplemented from PLearn::SequentialLearner.
Definition at line 108 of file EmbeddedSequentialLearner.h.
Definition at line 55 of file EmbeddedSequentialLearner.h.
Referenced by declareOptions().