PLearn 0.1
|
#include <StatefulLearner.h>
Public Member Functions | |
StatefulLearner () | |
Default constructor. | |
virtual void | build () |
Simply calls inherited::build() then build_(). | |
virtual void | makeDeepCopyFromShallowCopy (CopiesMap &copies) |
Transforms a shallow copy into a deep copy. | |
virtual StatefulLearner * | deepCopy (CopiesMap &copies) const |
virtual void | forget ()=0 |
Forget still needs to be redefined in derived classes, but the implementation here performs a no-op. | |
virtual void | resetInternalState () |
This method resets current_test_t to test_start_time. | |
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 void | computeOutputAndCosts (const Vec &input, const Vec &target, Vec &output, Vec &costs) const =0 |
Computes the outputs and costs simultaneously. | |
virtual void | computeCostsOnly (const Vec &input, const Vec &target, Vec &costs) const |
Computes the costs from the input and target vectors Simply calls computeOutputAndCosts(...) | |
virtual void | setTrainingSet (VMat training_set, bool call_forget=true) |
Declares the train set. | |
virtual bool | isStatefulLearner () const |
Does this PLearner has an internal state? Default: true. | |
virtual void | setTestSet (VMat testset) |
Set the dataset of an AssetManager (if any) to this testset Default: do nothing! | |
virtual void | setTestStartTime (int t) |
Set the suggested test_start_time; virtual so that derived classes may override to call the method of sublearners. | |
int | getTestStartTime () const |
Return the current test_start_time. | |
Static Public Member Functions | |
static string | _classname_ () |
static OptionList & | _getOptionList_ () |
static RemoteMethodMap & | _getRemoteMethodMap_ () |
static bool | _isa_ (const Object *o) |
static void | _static_initialize_ () |
static const PPath & | declaringFile () |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declares this class' options. | |
Protected Attributes | |
int | current_test_t |
Time step at which the current test is performed. | |
Private Types | |
typedef PLearner | inherited |
Private Member Functions | |
void | build_ () |
This does the actual building. | |
Private Attributes | |
int | test_start_time |
"Suggested" time-step at which testing should start; this should be read and set using the accessors below |
Definition at line 52 of file StatefulLearner.h.
typedef PLearner PLearn::StatefulLearner::inherited [private] |
Reimplemented from PLearn::PLearner.
Reimplemented in PLearn::HorizonStatefulLearner.
Definition at line 54 of file StatefulLearner.h.
PLearn::StatefulLearner::StatefulLearner | ( | ) |
Default constructor.
Definition at line 49 of file StatefulLearner.cc.
: current_test_t(-1), test_start_time(-1) {}
string PLearn::StatefulLearner::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::PLearner.
Reimplemented in PLearn::HorizonStatefulLearner.
Definition at line 57 of file StatefulLearner.cc.
OptionList & PLearn::StatefulLearner::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::PLearner.
Reimplemented in PLearn::HorizonStatefulLearner.
Definition at line 57 of file StatefulLearner.cc.
RemoteMethodMap & PLearn::StatefulLearner::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::PLearner.
Reimplemented in PLearn::HorizonStatefulLearner.
Definition at line 57 of file StatefulLearner.cc.
Reimplemented from PLearn::PLearner.
Reimplemented in PLearn::HorizonStatefulLearner.
Definition at line 57 of file StatefulLearner.cc.
StaticInitializer StatefulLearner::_static_initializer_ & PLearn::StatefulLearner::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::PLearner.
Reimplemented in PLearn::HorizonStatefulLearner.
Definition at line 57 of file StatefulLearner.cc.
void PLearn::StatefulLearner::build | ( | ) | [virtual] |
Simply calls inherited::build() then build_().
Reimplemented from PLearn::PLearner.
Reimplemented in PLearn::HorizonStatefulLearner.
Definition at line 73 of file StatefulLearner.cc.
References PLearn::PLearner::build(), and build_().
Referenced by PLearn::HorizonStatefulLearner::build().
{ inherited::build(); build_(); }
void PLearn::StatefulLearner::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::PLearner.
Reimplemented in PLearn::HorizonStatefulLearner.
Definition at line 69 of file StatefulLearner.cc.
Referenced by build().
{}
void PLearn::StatefulLearner::computeCostsFromOutputs | ( | const Vec & | input, |
const Vec & | output, | ||
const Vec & | target, | ||
Vec & | costs | ||
) | const [virtual] |
Computes the costs from already computed output.
This has no sense for a StatefulLearner since we suppose that the output and costs are computed together from the SAME state!
Implements PLearn::PLearner.
Definition at line 105 of file StatefulLearner.cc.
References PLERROR.
{ PLERROR("The method computeCostsFromOutputs is not defined and has no meaning for a StatefulLearner"); }
void PLearn::StatefulLearner::computeCostsOnly | ( | const Vec & | input, |
const Vec & | target, | ||
Vec & | costs | ||
) | const [virtual] |
Computes the costs from the input and target vectors Simply calls computeOutputAndCosts(...)
Reimplemented from PLearn::PLearner.
Definition at line 111 of file StatefulLearner.cc.
References computeOutputAndCosts(), PLearn::PLearner::outputsize(), PLWARNING, PLearn::TVec< T >::resize(), and PLearn::PLearner::tmp_output.
{ PLWARNING("You called StatefulLearner::computeCostsOnly(...), are you sure you don't want to use computeOutputAndCosts(...) instead???"); static Vec tmp_output; tmp_output.resize(outputsize()); computeOutputAndCosts(input, target, tmp_output, costs); }
Computes the output from the input.
Simply calls computeOutputAndCosts(...)
Reimplemented from PLearn::PLearner.
Definition at line 92 of file StatefulLearner.cc.
References computeOutputAndCosts(), PLearn::PLearner::nTestCosts(), PLearn::TVec< T >::resize(), and PLearn::PLearner::targetsize().
{ // PLWARNING("You called StatefulLearner::computeOutput(...), are you sure you don't want to use computeOutputAndCosts(...) instead???"); // These cannot be static because of potential re-entrancy problem upon // recursive calls Vec tmp_target(targetsize()); Vec tmp_costs(nTestCosts()); tmp_target.resize(targetsize()); tmp_costs.resize(nTestCosts()); computeOutputAndCosts(input, tmp_target, output, tmp_costs); }
virtual void PLearn::StatefulLearner::computeOutputAndCosts | ( | const Vec & | input, |
const Vec & | target, | ||
Vec & | output, | ||
Vec & | costs | ||
) | const [pure virtual] |
Computes the outputs and costs simultaneously.
Reimplemented from PLearn::PLearner.
Referenced by computeCostsOnly(), and computeOutput().
void PLearn::StatefulLearner::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares this class' options.
Reimplemented from PLearn::PLearner.
Reimplemented in PLearn::HorizonStatefulLearner.
Definition at line 59 of file StatefulLearner.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::PLearner::declareOptions(), and test_start_time.
Referenced by PLearn::HorizonStatefulLearner::declareOptions().
{ declareOption( ol, "test_start_time", &StatefulLearner::test_start_time, OptionBase::buildoption, "Initial time at which testing should be started."); inherited::declareOptions(ol); }
static const PPath& PLearn::StatefulLearner::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::PLearner.
Reimplemented in PLearn::HorizonStatefulLearner.
Definition at line 96 of file StatefulLearner.h.
{ return test_start_time; }
StatefulLearner * PLearn::StatefulLearner::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::PLearner.
Reimplemented in PLearn::HorizonStatefulLearner.
Definition at line 57 of file StatefulLearner.cc.
void PLearn::StatefulLearner::forget | ( | ) | [pure virtual] |
Forget still needs to be redefined in derived classes, but the implementation here performs a no-op.
This allows derived classes to write inherited::forget() without fear.
Reimplemented from PLearn::PLearner.
Definition at line 84 of file StatefulLearner.cc.
Referenced by setTrainingSet().
{ /* empty */ }
int PLearn::StatefulLearner::getTestStartTime | ( | ) | const [inline] |
Return the current test_start_time.
Definition at line 149 of file StatefulLearner.h.
{ return test_start_time; }
bool PLearn::StatefulLearner::isStatefulLearner | ( | ) | const [virtual] |
Does this PLearner has an internal state? Default: true.
Reimplemented from PLearn::PLearner.
Definition at line 134 of file StatefulLearner.cc.
{ return true; }
void PLearn::StatefulLearner::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::PLearner.
Reimplemented in PLearn::HorizonStatefulLearner.
Definition at line 79 of file StatefulLearner.cc.
References PLearn::PLearner::makeDeepCopyFromShallowCopy().
Referenced by PLearn::HorizonStatefulLearner::makeDeepCopyFromShallowCopy().
{ inherited::makeDeepCopyFromShallowCopy(copies); }
void PLearn::StatefulLearner::resetInternalState | ( | ) | [virtual] |
This method resets current_test_t to test_start_time.
Reimplemented from PLearn::PLearner.
Definition at line 87 of file StatefulLearner.cc.
References current_test_t, and test_start_time.
{ current_test_t = test_start_time; }
void PLearn::StatefulLearner::setTestSet | ( | VMat | testset | ) | [virtual] |
Set the dataset of an AssetManager (if any) to this testset Default: do nothing!
Definition at line 131 of file StatefulLearner.cc.
{}
void PLearn::StatefulLearner::setTestStartTime | ( | int | t | ) | [virtual] |
Set the suggested test_start_time; virtual so that derived classes may override to call the method of sublearners.
Definition at line 139 of file StatefulLearner.cc.
References test_start_time.
{ test_start_time = t; }
void PLearn::StatefulLearner::setTrainingSet | ( | VMat | training_set, |
bool | call_forget = true |
||
) | [virtual] |
Declares the train set.
Reimplemented from PLearn::PLearner.
Definition at line 120 of file StatefulLearner.cc.
References forget(), PLearn::PLearner::inputsize_, PLearn::PLearner::targetsize_, PLearn::PLearner::train_set, and PLearn::PLearner::weightsize_.
{ train_set = training_set; inputsize_ = train_set->inputsize(); targetsize_ = train_set->targetsize(); weightsize_ = train_set->weightsize(); if ( call_forget ) forget(); }
Reimplemented from PLearn::PLearner.
Reimplemented in PLearn::HorizonStatefulLearner.
Definition at line 96 of file StatefulLearner.h.
int PLearn::StatefulLearner::current_test_t [mutable, protected] |
Time step at which the current test is performed.
This can be useful when entering computeOutputAndCosts(...) method. NOTE: it is the responsibility of each derived class to increment this counter upon processing computeOutputAndCosts.
Definition at line 61 of file StatefulLearner.h.
Referenced by resetInternalState().
int PLearn::StatefulLearner::test_start_time [private] |
"Suggested" time-step at which testing should start; this should be read and set using the accessors below
Definition at line 66 of file StatefulLearner.h.
Referenced by declareOptions(), resetInternalState(), and setTestStartTime().