PLearn 0.1
|
#include <VPLCombinedLearner.h>
Public Member Functions | |
VPLCombinedLearner () | |
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 string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual VPLCombinedLearner * | deepCopy (CopiesMap &copies) const |
virtual int | outputsize () const |
SUBCLASS WRITING: override this so that it returns the size of this learner's output, as a function of its inputsize(), targetsize() and set options. | |
virtual void | setValidationSet (VMat validset) |
Forwarded to inner learner. | |
virtual void | setTrainStatsCollector (PP< VecStatsCollector > statscol) |
Forwarded to inner learner. | |
virtual void | setExperimentDirectory (const PPath &the_expdir) |
Forwarded to inner learner. | |
virtual void | forget () |
Forwarded to inner learner. | |
virtual void | setTrainingSet (VMat training_set, bool call_forget=true) |
Declares the training set. | |
virtual void | train () |
*** SUBCLASS WRITING: *** | |
virtual void | computeOutput (const Vec &input, Vec &output) const |
*** SUBCLASS WRITING: *** | |
virtual void | computeOutputAndCosts (const Vec &input, const Vec &target, Vec &output, Vec &costs) const |
Default calls computeOutput and computeCostsFromOutputs. | |
virtual void | computeCostsFromOutputs (const Vec &input, const Vec &output, const Vec &target, Vec &costs) const |
*** SUBCLASS WRITING: *** | |
virtual TVec< string > | getOutputNames () const |
Returns a vector of length outputsize() containing the outputs' names. | |
virtual TVec< std::string > | getTestCostNames () const |
*** SUBCLASS WRITING: *** | |
virtual TVec< string > | getTrainCostNames () const |
*** SUBCLASS WRITING: *** | |
virtual void | resetInternalState () |
If any, reset the internal state Default: do nothing. | |
virtual bool | isStatefulLearner () const |
Does this PLearner has an internal state? Default: false. | |
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 > > | sublearners_ |
Inner learner which is embedded into the current learner. | |
string | output_prg |
string | costs_prg |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declares this class' options. | |
Protected Attributes | |
VMatLanguage | output_prg_ |
VMatLanguage | costs_prg_ |
TVec< string > | outputnames_ |
TVec< string > | costnames_ |
Vec | invec_for_output_prg |
Vec | invec_for_costs_prg |
TVec< int > | sublearners_outputsizes |
TVec< int > | sublearners_ntestcosts |
TVec< string > | orig_fieldnames |
int | orig_inputsize |
int | orig_targetsize |
Private Types | |
typedef PLearner | inherited |
Private Member Functions | |
void | build_ () |
This does the actual building. | |
void | initializeOutputPrograms () |
void | initializeCostNames () |
Definition at line 52 of file VPLCombinedLearner.h.
typedef PLearner PLearn::VPLCombinedLearner::inherited [private] |
Reimplemented from PLearn::PLearner.
Definition at line 57 of file VPLCombinedLearner.h.
PLearn::VPLCombinedLearner::VPLCombinedLearner | ( | ) |
Default constructor.
Definition at line 52 of file VPLCombinedLearner.cc.
:orig_inputsize(-1), orig_targetsize(-1) { }
string PLearn::VPLCombinedLearner::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::PLearner.
Definition at line 64 of file VPLCombinedLearner.cc.
OptionList & PLearn::VPLCombinedLearner::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::PLearner.
Definition at line 64 of file VPLCombinedLearner.cc.
RemoteMethodMap & PLearn::VPLCombinedLearner::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::PLearner.
Definition at line 64 of file VPLCombinedLearner.cc.
Reimplemented from PLearn::PLearner.
Definition at line 64 of file VPLCombinedLearner.cc.
Object * PLearn::VPLCombinedLearner::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 64 of file VPLCombinedLearner.cc.
StaticInitializer VPLCombinedLearner::_static_initializer_ & PLearn::VPLCombinedLearner::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::PLearner.
Definition at line 64 of file VPLCombinedLearner.cc.
void PLearn::VPLCombinedLearner::build | ( | ) | [virtual] |
Simply calls inherited::build() then build_().
Reimplemented from PLearn::PLearner.
Definition at line 121 of file VPLCombinedLearner.cc.
References PLearn::PLearner::build(), and build_().
Referenced by setTrainingSet().
{ inherited::build(); build_(); }
void PLearn::VPLCombinedLearner::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::PLearner.
Definition at line 110 of file VPLCombinedLearner.cc.
References initializeCostNames(), initializeOutputPrograms(), PLearn::PP< T >::isNull(), orig_inputsize, orig_targetsize, and PLearn::PLearner::train_set.
Referenced by build().
{ if(train_set.isNull() && (orig_inputsize>0 || orig_targetsize>0) ) // we're probably reloading a saved VPLCombinedLearner { initializeOutputPrograms(); } else initializeCostNames(); }
string PLearn::VPLCombinedLearner::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 64 of file VPLCombinedLearner.cc.
void PLearn::VPLCombinedLearner::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.
Definition at line 404 of file VPLCombinedLearner.cc.
References computeOutputAndCosts().
{ Vec nonconst_output = output; // to make the constipated compiler happy computeOutputAndCosts(input, target, nonconst_output, costs); }
*** SUBCLASS WRITING: ***
This should be defined in subclasses to compute the output from the input.
Reimplemented from PLearn::PLearner.
Definition at line 308 of file VPLCombinedLearner.cc.
References PLearn::VMatLanguage::inputsize(), PLearn::PLearner::inputsize(), invec_for_output_prg, PLearn::TVec< T >::length(), output_prg, output_prg_, outputsize(), PLearn::TVec< T >::resize(), PLearn::VMatLanguage::run(), sublearners_, sublearners_outputsizes, and PLearn::TVec< T >::subVec().
{ output.resize(outputsize()); int nlearners = sublearners_.length(); int ninputs = inputsize(); int outpos = 0; if(!output_prg.empty()) // no output_prg: output is simply concatenation of sublearner's outputs { invec_for_output_prg.resize(output_prg_.inputsize()); invec_for_output_prg.subVec(outpos, ninputs) << input; // copy input part into invec_for_output_prg outpos += ninputs; } Vec outvec; for(int k=0; k<nlearners; k++) { int nout = sublearners_outputsizes[k]; if(output_prg.empty()) // no output_prg: output is simply concatenation of sublearner's outputs outvec = output.subVec(outpos,nout); else outvec = invec_for_output_prg.subVec(outpos, nout); sublearners_[k]->computeOutput(input, outvec); outpos += nout; } if(!output_prg.empty()) output_prg_.run(invec_for_output_prg, output); }
void PLearn::VPLCombinedLearner::computeOutputAndCosts | ( | const Vec & | input, |
const Vec & | target, | ||
Vec & | output, | ||
Vec & | costs | ||
) | const [virtual] |
Default calls computeOutput and computeCostsFromOutputs.
You may override this if you have a more efficient way to compute both output and weighted costs at the same time.
Reimplemented from PLearn::PLearner.
Definition at line 338 of file VPLCombinedLearner.cc.
References costs_prg, costs_prg_, PLearn::VMatLanguage::inputsize(), PLearn::PLearner::inputsize(), invec_for_costs_prg, invec_for_output_prg, PLearn::TVec< T >::length(), PLearn::PLearner::nTestCosts(), output_prg, output_prg_, outputsize(), PLASSERT, PLearn::TVec< T >::resize(), PLearn::VMatLanguage::run(), sublearners_, sublearners_ntestcosts, sublearners_outputsizes, PLearn::TVec< T >::subVec(), and PLearn::PLearner::targetsize().
Referenced by computeCostsFromOutputs().
{ output.resize(outputsize()); costs.resize(nTestCosts()); PLASSERT(input.length()==inputsize()); PLASSERT(target.length()==targetsize()); output.resize(outputsize()); int nlearners = sublearners_.length(); int ninputs = inputsize(); int ntargets= targetsize(); int outpos = 0; int costspos = 0; if(!output_prg.empty()) { invec_for_output_prg.resize(output_prg_.inputsize()); invec_for_output_prg.subVec(outpos,ninputs) << input; outpos += ninputs; } if(!costs_prg.empty()) { invec_for_costs_prg.resize(costs_prg_.inputsize()); invec_for_costs_prg.subVec(costspos,ninputs) << input; costspos += ninputs; invec_for_costs_prg.subVec(costspos,ntargets) << target; costspos += ntargets; } Vec outvec; Vec costvec; for(int k=0; k<nlearners; k++) { int nout = sublearners_outputsizes[k]; int ncosts = sublearners_ntestcosts[k]; if(output_prg.empty()) outvec = output.subVec(outpos, nout); else outvec = invec_for_output_prg.subVec(outpos, nout); if(costs_prg.empty()) costvec = costs.subVec(costspos, ncosts); else costvec = invec_for_costs_prg.subVec(costspos+nout, ncosts); sublearners_[k]->computeOutputAndCosts(input, target, outvec, costvec); if(!costs_prg.empty()) // copy outvec into correct position in invec_for_costs_prg { invec_for_costs_prg.subVec(costspos, nout) << outvec; costspos += nout+ncosts; } outpos += nout; } if(!output_prg.empty()) output_prg_.run(invec_for_output_prg, output); if(!costs_prg.empty()) costs_prg_.run(invec_for_costs_prg, costs); }
void PLearn::VPLCombinedLearner::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares this class' options.
Reimplemented from PLearn::PLearner.
Definition at line 66 of file VPLCombinedLearner.cc.
References PLearn::OptionBase::buildoption, costs_prg, PLearn::declareOption(), PLearn::PLearner::declareOptions(), PLearn::OptionBase::learntoption, orig_fieldnames, orig_inputsize, orig_targetsize, output_prg, and sublearners_.
{ // ### Declare all of this object's options here // ### For the "flags" of each option, you should typically specify // ### one of OptionBase::buildoption, OptionBase::learntoption or // ### OptionBase::tuningoption. Another possible flag to be combined with // ### is OptionBase::nosave // ### ex: // declareOption(ol, "myoption", &VPLCombinedLearner::myoption, OptionBase::buildoption, // "Help text describing this option"); // ... declareOption(ol, "sublearners", &VPLCombinedLearner::sublearners_, OptionBase::buildoption, "The list of sub-learners that will receive the training set."); declareOption(ol, "output_prg", &VPLCombinedLearner::output_prg, OptionBase::buildoption, "Program string in VPL language to compute this learner's outputs\n" "from a concatenation of the raw input fields and the sublearners' outputs,\n" "renamed as learner0.outputname learner1.outputname, etc... \n" "Note that outputs are often named out0, out1, out2, ...\n" "Note that new outputnames must be given to the generated values with :fieldname VPL syntax.\n" "If it's an empty string, then we'll output the sub-learner's outputs.\n"); declareOption(ol, "costs_prg", &VPLCombinedLearner::costs_prg, OptionBase::buildoption, "Program string in VPL language to obtain postprocessed test costs\n" "from a concatenation of the raw input fields and arget fields, \n" "and the sublearners' outputs and test costs.\n" "Note that names must be given to the generated values with :fieldname VPL syntax.\n" "If it's an empty string, then we'll output the underlying learner's test costs.\n" "Note that this processing is only applied to test costs, not to train costs which are returned as is."); declareOption(ol, "orig_fieldnames", &VPLCombinedLearner::orig_fieldnames, OptionBase::learntoption, "original fieldnames of the training set"); declareOption(ol, "orig_inputsize", &VPLCombinedLearner::orig_inputsize, OptionBase::learntoption, "original inputsize of the training set"); declareOption(ol, "orig_targetsize", &VPLCombinedLearner::orig_targetsize, OptionBase::learntoption, "original targetsize of the training set"); // Now call the parent class' declareOptions inherited::declareOptions(ol); }
static const PPath& PLearn::VPLCombinedLearner::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::PLearner.
Definition at line 138 of file VPLCombinedLearner.h.
VPLCombinedLearner * PLearn::VPLCombinedLearner::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::PLearner.
Definition at line 64 of file VPLCombinedLearner.cc.
void PLearn::VPLCombinedLearner::forget | ( | ) | [virtual] |
Forwarded to inner learner.
Reimplemented from PLearn::PLearner.
Definition at line 176 of file VPLCombinedLearner.cc.
References PLearn::TVec< T >::length(), PLearn::PLearner::stage, and sublearners_.
{ for(int k=0; k<sublearners_.length(); k++) sublearners_[k]->forget(); stage = 0; }
OptionList & PLearn::VPLCombinedLearner::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 64 of file VPLCombinedLearner.cc.
OptionMap & PLearn::VPLCombinedLearner::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 64 of file VPLCombinedLearner.cc.
TVec< string > PLearn::VPLCombinedLearner::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 411 of file VPLCombinedLearner.cc.
References outputnames_.
{ return outputnames_; }
RemoteMethodMap & PLearn::VPLCombinedLearner::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 64 of file VPLCombinedLearner.cc.
TVec< string > PLearn::VPLCombinedLearner::getTestCostNames | ( | ) | const [virtual] |
*** SUBCLASS WRITING: ***
This should return the names of the costs computed by computeCostsFromOutputs.
Implements PLearn::PLearner.
Definition at line 416 of file VPLCombinedLearner.cc.
References costnames_.
{ return costnames_; }
TVec< string > PLearn::VPLCombinedLearner::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 421 of file VPLCombinedLearner.cc.
{
return TVec<string>();
}
void PLearn::VPLCombinedLearner::initializeCostNames | ( | ) | [private] |
Definition at line 253 of file VPLCombinedLearner.cc.
References PLearn::TVec< T >::append(), costnames_, costs_prg, PLearn::VMatLanguage::getOutputFieldNamesFromString(), PLearn::TVec< T >::length(), PLearn::TVec< T >::resize(), sublearners_, and sublearners_ntestcosts.
Referenced by build_().
{ int nlearners = sublearners_.length(); sublearners_ntestcosts.resize(nlearners); costnames_.resize(0); for(int k=0; k<nlearners; k++) { char tmp[100]; sprintf(tmp,"learner%d.",k); string prefix(tmp); int ntest = sublearners_[k]->nTestCosts(); sublearners_ntestcosts[k] = ntest; TVec<string> testcostnames = sublearners_[k]->getTestCostNames(); for(int p=0; p<ntest; p++) { string costname = prefix+testcostnames[p]; if(costs_prg.empty()) costnames_.append(costname); } } if(!costs_prg.empty()) VMatLanguage::getOutputFieldNamesFromString(costs_prg, costnames_); }
void PLearn::VPLCombinedLearner::initializeOutputPrograms | ( | ) | [private] |
Definition at line 190 of file VPLCombinedLearner.cc.
References PLearn::TVec< T >::append(), PLearn::VMatLanguage::compileString(), PLearn::concat(), PLearn::TVec< T >::copy(), costnames_, costs_prg, costs_prg_, PLearn::TVec< T >::length(), orig_fieldnames, orig_inputsize, orig_targetsize, output_prg, output_prg_, outputnames_, PLearn::TVec< T >::resize(), PLearn::VMatLanguage::setSourceFieldNames(), sublearners_, sublearners_ntestcosts, sublearners_outputsizes, and PLearn::TVec< T >::subVec().
Referenced by build_(), and setTrainingSet().
{ TVec<string> orig_input_fieldnames = orig_fieldnames.subVec(0,orig_inputsize); TVec<string> orig_target_fieldnames = orig_fieldnames.subVec(orig_inputsize, orig_targetsize); int nlearners = sublearners_.length(); sublearners_outputsizes.resize(nlearners); sublearners_ntestcosts.resize(nlearners); TVec<string> infields_for_output_prg = orig_input_fieldnames.copy(); TVec<string> infields_for_costs_prg = concat(orig_input_fieldnames,orig_target_fieldnames); outputnames_.resize(0); costnames_.resize(0); for(int k=0; k<nlearners; k++) { char tmp[100]; sprintf(tmp,"learner%d.",k); string prefix(tmp); int nout = sublearners_[k]->outputsize(); sublearners_outputsizes[k] = nout; TVec<string> outputnames = sublearners_[k]->getOutputNames(); for(int p=0; p<nout; p++) { string outname = prefix+outputnames[p]; if(output_prg.empty()) outputnames_.append(outname); else infields_for_output_prg.append(prefix+outputnames[p]); if(!costs_prg.empty()) infields_for_costs_prg.append(prefix+outputnames[p]); } int ntest = sublearners_[k]->nTestCosts(); sublearners_ntestcosts[k] = ntest; TVec<string> testcostnames = sublearners_[k]->getTestCostNames(); for(int p=0; p<ntest; p++) { string costname = prefix+testcostnames[p]; if(costs_prg.empty()) costnames_.append(costname); else infields_for_costs_prg.append(costname); } } if(!output_prg.empty()) { output_prg_.setSourceFieldNames(infields_for_output_prg); output_prg_.compileString(output_prg, outputnames_); } if(!costs_prg.empty()) { costs_prg_.setSourceFieldNames(infields_for_costs_prg); costs_prg_.compileString(costs_prg, costnames_); } }
bool PLearn::VPLCombinedLearner::isStatefulLearner | ( | ) | const [virtual] |
Does this PLearner has an internal state? Default: false.
Reimplemented from PLearn::PLearner.
Definition at line 433 of file VPLCombinedLearner.cc.
References sublearners_.
{ return sublearners_[0]->isStatefulLearner(); }
void PLearn::VPLCombinedLearner::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::PLearner.
Definition at line 127 of file VPLCombinedLearner.cc.
References costnames_, costs_prg_, PLearn::deepCopyField(), invec_for_costs_prg, invec_for_output_prg, PLearn::VMatLanguage::makeDeepCopyFromShallowCopy(), PLearn::PLearner::makeDeepCopyFromShallowCopy(), orig_fieldnames, output_prg_, outputnames_, sublearners_, sublearners_ntestcosts, and sublearners_outputsizes.
{ inherited::makeDeepCopyFromShallowCopy(copies); // ### Call deepCopyField on all "pointer-like" fields // ### that you wish to be deepCopied rather than // ### shallow-copied. deepCopyField(sublearners_, copies); output_prg_.makeDeepCopyFromShallowCopy(copies); costs_prg_.makeDeepCopyFromShallowCopy(copies); deepCopyField(outputnames_, copies); deepCopyField(costnames_, copies); deepCopyField(invec_for_output_prg, copies); deepCopyField(invec_for_costs_prg, copies); deepCopyField(sublearners_outputsizes, copies); deepCopyField(sublearners_ntestcosts, copies); deepCopyField(orig_fieldnames, copies); }
int PLearn::VPLCombinedLearner::outputsize | ( | ) | const [virtual] |
SUBCLASS WRITING: override 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 164 of file VPLCombinedLearner.cc.
References outputnames_, and PLearn::TVec< T >::size().
Referenced by computeOutput(), and computeOutputAndCosts().
{ return outputnames_.size(); }
void PLearn::VPLCombinedLearner::resetInternalState | ( | ) | [virtual] |
If any, reset the internal state Default: do nothing.
Reimplemented from PLearn::PLearner.
Definition at line 427 of file VPLCombinedLearner.cc.
References PLearn::TVec< T >::length(), and sublearners_.
{ for(int k=0; k<sublearners_.length(); k++) sublearners_[k]->resetInternalState(); }
void PLearn::VPLCombinedLearner::setExperimentDirectory | ( | const PPath & | the_expdir | ) | [virtual] |
Forwarded to inner learner.
Reimplemented from PLearn::PLearner.
Definition at line 169 of file VPLCombinedLearner.cc.
References PLearn::TVec< T >::length(), PLearn::PLearner::setExperimentDirectory(), sublearners_, and PLearn::tostring().
{ inherited::setExperimentDirectory(the_expdir); for(int k=0; k<sublearners_.length(); k++) sublearners_[k]->setExperimentDirectory(the_expdir/("SubLearner_"+tostring(k))); }
void PLearn::VPLCombinedLearner::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 282 of file VPLCombinedLearner.cc.
References build(), initializeOutputPrograms(), PLearn::TVec< T >::length(), orig_fieldnames, orig_inputsize, orig_targetsize, PLearn::PLearner::setTrainingSet(), sublearners_, and PLearn::PLearner::train_set.
{ bool training_set_has_changed = !train_set || !(train_set->looksTheSameAs(training_set)); if (call_forget && !training_set_has_changed) { // In this case, the sublearner's build() will not have been called, which may // cause trouble if it updates data from the training set. // NOTE: I'M NOT QUITE SURE WHAT THE ABOVE SITUATION MEANS. // BUT FOR NOW, LET'S BELIEVE IT'S TRUE, SO WE MUST CALL build_ ON THE SUBLEARNERS for(int k=0; k<sublearners_.length(); k++) sublearners_[k]->build(); } orig_fieldnames = training_set->fieldNames(); orig_inputsize = training_set->inputsize(); orig_targetsize = training_set->targetsize(); for(int k=0; k<sublearners_.length(); k++) sublearners_[k]->setTrainingSet(training_set, call_forget); inherited::setTrainingSet(training_set, call_forget); // will call forget if needed initializeOutputPrograms(); }
void PLearn::VPLCombinedLearner::setTrainStatsCollector | ( | PP< VecStatsCollector > | statscol | ) | [virtual] |
Forwarded to inner learner.
Reimplemented from PLearn::PLearner.
Definition at line 157 of file VPLCombinedLearner.cc.
References PLearn::TVec< T >::length(), PLearn::PLearner::setTrainStatsCollector(), and sublearners_.
{ inherited::setTrainStatsCollector(statscol); for(int k=0; k<sublearners_.length(); k++) sublearners_[k]->setTrainStatsCollector(new VecStatsCollector()); }
void PLearn::VPLCombinedLearner::setValidationSet | ( | VMat | validset | ) | [virtual] |
Forwarded to inner learner.
Reimplemented from PLearn::PLearner.
Definition at line 150 of file VPLCombinedLearner.cc.
References PLearn::TVec< T >::length(), PLearn::PLearner::setValidationSet(), and sublearners_.
{ inherited::setValidationSet(validset); for(int k=0; k<sublearners_.length(); k++) sublearners_[k]->setValidationSet(validset); }
void PLearn::VPLCombinedLearner::train | ( | ) | [virtual] |
*** SUBCLASS WRITING: ***
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.
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 183 of file VPLCombinedLearner.cc.
References PLearn::TVec< T >::length(), PLearn::PLearner::stage, and sublearners_.
{ for(int k=0; k<sublearners_.length(); k++) sublearners_[k]->train(); ++stage; }
Reimplemented from PLearn::PLearner.
Definition at line 138 of file VPLCombinedLearner.h.
TVec<string> PLearn::VPLCombinedLearner::costnames_ [protected] |
Definition at line 65 of file VPLCombinedLearner.h.
Referenced by getTestCostNames(), initializeCostNames(), initializeOutputPrograms(), and makeDeepCopyFromShallowCopy().
Definition at line 93 of file VPLCombinedLearner.h.
Referenced by computeOutputAndCosts(), declareOptions(), initializeCostNames(), and initializeOutputPrograms().
VMatLanguage PLearn::VPLCombinedLearner::costs_prg_ [protected] |
Definition at line 62 of file VPLCombinedLearner.h.
Referenced by computeOutputAndCosts(), initializeOutputPrograms(), and makeDeepCopyFromShallowCopy().
Vec PLearn::VPLCombinedLearner::invec_for_costs_prg [mutable, protected] |
Definition at line 68 of file VPLCombinedLearner.h.
Referenced by computeOutputAndCosts(), and makeDeepCopyFromShallowCopy().
Vec PLearn::VPLCombinedLearner::invec_for_output_prg [mutable, protected] |
Definition at line 67 of file VPLCombinedLearner.h.
Referenced by computeOutput(), computeOutputAndCosts(), and makeDeepCopyFromShallowCopy().
TVec<string> PLearn::VPLCombinedLearner::orig_fieldnames [protected] |
Definition at line 78 of file VPLCombinedLearner.h.
Referenced by declareOptions(), initializeOutputPrograms(), makeDeepCopyFromShallowCopy(), and setTrainingSet().
int PLearn::VPLCombinedLearner::orig_inputsize [protected] |
Definition at line 79 of file VPLCombinedLearner.h.
Referenced by build_(), declareOptions(), initializeOutputPrograms(), and setTrainingSet().
int PLearn::VPLCombinedLearner::orig_targetsize [protected] |
Definition at line 80 of file VPLCombinedLearner.h.
Referenced by build_(), declareOptions(), initializeOutputPrograms(), and setTrainingSet().
Definition at line 92 of file VPLCombinedLearner.h.
Referenced by computeOutput(), computeOutputAndCosts(), declareOptions(), and initializeOutputPrograms().
VMatLanguage PLearn::VPLCombinedLearner::output_prg_ [protected] |
Definition at line 61 of file VPLCombinedLearner.h.
Referenced by computeOutput(), computeOutputAndCosts(), initializeOutputPrograms(), and makeDeepCopyFromShallowCopy().
TVec<string> PLearn::VPLCombinedLearner::outputnames_ [protected] |
Definition at line 64 of file VPLCombinedLearner.h.
Referenced by getOutputNames(), initializeOutputPrograms(), makeDeepCopyFromShallowCopy(), and outputsize().
Inner learner which is embedded into the current learner.
Definition at line 90 of file VPLCombinedLearner.h.
Referenced by computeOutput(), computeOutputAndCosts(), declareOptions(), forget(), initializeCostNames(), initializeOutputPrograms(), isStatefulLearner(), makeDeepCopyFromShallowCopy(), resetInternalState(), setExperimentDirectory(), setTrainingSet(), setTrainStatsCollector(), setValidationSet(), and train().
TVec<int> PLearn::VPLCombinedLearner::sublearners_ntestcosts [protected] |
Definition at line 71 of file VPLCombinedLearner.h.
Referenced by computeOutputAndCosts(), initializeCostNames(), initializeOutputPrograms(), and makeDeepCopyFromShallowCopy().
TVec<int> PLearn::VPLCombinedLearner::sublearners_outputsizes [protected] |
Definition at line 70 of file VPLCombinedLearner.h.
Referenced by computeOutput(), computeOutputAndCosts(), initializeOutputPrograms(), and makeDeepCopyFromShallowCopy().