PLearn 0.1
|
#include <Experiment.h>
Public Types | |
typedef Object | inherited |
Public Member Functions | |
Experiment () | |
virtual void | build () |
Post-constructor. | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual Experiment * | deepCopy (CopiesMap &copies) const |
virtual void | run () |
runs the experiment | |
Static Public Member Functions | |
static string | _classname_ () |
Declares name and deepCopy methods. | |
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 | |
string | expdir |
Path of this experiment's directory in which to save all experiment results (will be created if it does not already exist) | |
PP< Learner > | learner |
VMat | dataset |
PP< Splitter > | splitter |
bool | save_models |
bool | save_initial_models |
bool | save_test_outputs |
bool | save_test_costs |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declares this class' options. | |
Private Member Functions | |
void | build_ () |
This does the actual building. |
Definition at line 51 of file Experiment.h.
typedef Object PLearn::Experiment::inherited |
Reimplemented from PLearn::Object.
Definition at line 55 of file Experiment.h.
PLearn::Experiment::Experiment | ( | ) |
Definition at line 50 of file Experiment.cc.
:save_models(true), save_initial_models(false), save_test_outputs(false), save_test_costs(false) {}
string PLearn::Experiment::_classname_ | ( | ) | [static] |
Declares name and deepCopy methods.
Reimplemented from PLearn::Object.
Definition at line 55 of file Experiment.cc.
: use PTester instead", "");
OptionList & PLearn::Experiment::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 55 of file Experiment.cc.
: use PTester instead", "");
RemoteMethodMap & PLearn::Experiment::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 55 of file Experiment.cc.
: use PTester instead", "");
Reimplemented from PLearn::Object.
Definition at line 55 of file Experiment.cc.
: use PTester instead", "");
Object * PLearn::Experiment::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 55 of file Experiment.cc.
: use PTester instead", "");
StaticInitializer Experiment::_static_initializer_ & PLearn::Experiment::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 55 of file Experiment.cc.
: use PTester instead", "");
void PLearn::Experiment::build | ( | ) | [virtual] |
Post-constructor.
The normal implementation should call simply inherited::build(), then this class's build_(). This method should be callable again at later times, after modifying some option fields to change the "architecture" of the object.
Reimplemented from PLearn::Object.
Definition at line 85 of file Experiment.cc.
References PLearn::Object::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::Experiment::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::Object.
Definition at line 79 of file Experiment.cc.
References dataset, and splitter.
Referenced by build().
string PLearn::Experiment::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 55 of file Experiment.cc.
: use PTester instead", "");
void PLearn::Experiment::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares this class' options.
Reimplemented from PLearn::Object.
Definition at line 57 of file Experiment.cc.
References PLearn::OptionBase::buildoption, dataset, PLearn::declareOption(), PLearn::Object::declareOptions(), expdir, learner, save_initial_models, save_models, save_test_costs, save_test_outputs, and splitter.
{ declareOption(ol, "expdir", &Experiment::expdir, OptionBase::buildoption, "Path of this experiment's directory in which to save all experiment results (will be created if it does not already exist)"); declareOption(ol, "learner", &Experiment::learner, OptionBase::buildoption, "The learner to train/test"); declareOption(ol, "dataset", &Experiment::dataset, OptionBase::buildoption, "The dataset to use for training/testing (will be split according to what is specified in the testmethod)\n" "You may omit this only if your splitter is an ExplicitSplitter"); declareOption(ol, "splitter", &Experiment::splitter, OptionBase::buildoption, "The splitter to use to generate one or several train/test pairs from the dataset."); declareOption(ol, "save_models", &Experiment::save_models, OptionBase::buildoption, "If true, the final model#k will be saved in Split#k/final.psave"); declareOption(ol, "save_initial_models", &Experiment::save_initial_models, OptionBase::buildoption, "If true, the initial model#k (just after forget() has been called) will be saved in Split#k/initial.psave"); declareOption(ol, "save_test_outputs", &Experiment::save_test_outputs, OptionBase::buildoption, "If true, the outputs of the test for split #k will be saved in Split#k/test_outputs.pmat"); declareOption(ol, "save_test_costs", &Experiment::save_test_costs, OptionBase::buildoption, "If true, the costs of the test for split #k will be saved in Split#k/test_costs.pmat"); inherited::declareOptions(ol); }
static const PPath& PLearn::Experiment::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::Object.
Definition at line 100 of file Experiment.h.
Experiment * PLearn::Experiment::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 55 of file Experiment.cc.
: use PTester instead", "");
OptionList & PLearn::Experiment::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 55 of file Experiment.cc.
: use PTester instead", "");
OptionMap & PLearn::Experiment::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 55 of file Experiment.cc.
: use PTester instead", "");
RemoteMethodMap & PLearn::Experiment::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 55 of file Experiment.cc.
: use PTester instead", "");
void PLearn::Experiment::run | ( | ) | [virtual] |
runs the experiment
Reimplemented from PLearn::Object.
Definition at line 91 of file Experiment.cc.
References PLearn::append_slash(), expdir, PLearn::force_mkdir(), PLearn::VecStatsCollector::getMean(), PLearn::VecStatsCollector::getStdDev(), PLearn::VecStatsCollector::getStdError(), learner, PLearn::TVec< T >::length(), PLearn::pathexists(), PLERROR, PLearn::TVec< T >::println(), PLearn::PLMPI::rank, PLearn::Object::save(), save_initial_models, save_models, save_test_costs, save_test_outputs, PLearn::TVec< T >::size(), slash, splitter, PLearn::TVec< T >::subVec(), PLearn::tostring(), and PLearn::VecStatsCollector::update().
{ if(expdir=="") PLERROR("No expdir specified for Experiment."); if(!learner) PLERROR("No learner specified for Experiment."); if(!splitter) PLERROR("No splitter specified for Experiment"); if(PLMPI::rank==0) { if(pathexists(expdir)) PLERROR("Directory (or file) %s already exists. First move it out of the way.",expdir.c_str()); if(!force_mkdir(expdir)) PLERROR("Could not create experiment directory %s", expdir.c_str()); // Save this experiment description in the expdir PLearn::save(append_slash(expdir)+"experiment.psave", *this); } int nsplits = splitter->nsplits(); Array<string> testresnames = learner->testResultsNames(); int ntestres = testresnames.size(); VecStatsCollector teststats; // the vmat in which to save results VMat results; if(PLMPI::rank==0) { // filename string fname = append_slash(expdir)+"results.amat"; // fieldnames TVec<string> fieldnames(1+ntestres); fieldnames[0] = "splitnum"; for(int k=0; k<ntestres; k++) fieldnames[k+1] = testresnames[k]; /* cerr << "ntestres: " << ntestres << endl; cerr << "testresnames: " << testresnames << endl; cerr << "fieldnames: " << fieldnames << endl; */ results = new AsciiVMatrix(fname, 1+ntestres, fieldnames, "# Special values for splitnum are: -1 -> MEAN; -2 -> STDERROR; -3 -> STDDEV"); } Vec resultrow(1+ntestres); // will hold splitnum and testresults for that split Vec resultrow_sub = resultrow.subVec(1,ntestres); // the part containing the test results for(int k=0; k<nsplits; k++) { TVec<VMat> train_test = splitter->getSplit(k); if(train_test.size()!=2) PLERROR("Splitter returned a split with %d subsets, instead of the expected 2: train&test",train_test.size()); VMat trainset = train_test[0]; VMat testset = train_test[1]; string learner_expdir = append_slash(expdir)+"Split"+tostring(k); learner->setExperimentDirectory(learner_expdir); learner->forget(); if(save_initial_models) PLearn::save(learner_expdir+slash+"initial.psave",learner); learner->setTestDuringTrain(testset); learner->train(trainset); if(save_models) PLearn::save(learner_expdir+slash+"final.psave",learner); string test_outputs_fname = learner_expdir+slash+"test_outputs.pmat"; if(save_test_outputs) test_outputs_fname = learner_expdir+slash+"test_outputs.pmat"; string test_costs_fname = learner_expdir+slash+"test_costs.pmat"; if(save_test_costs) test_costs_fname = learner_expdir+slash+"test_costs.pmat"; Vec testres = learner->test(testset, test_outputs_fname, test_costs_fname); testres.println(cout); // PLWARNING("In Experiment: length of Vec returned by test = %d; number of names returned by testResultNames = %d",testres.length(), ntestres); if(testres.length()!=ntestres) PLERROR("In Experiment: length of Vec returned by test (%d) differs from number of names returned by testResultNames (%d)", testres.length(), ntestres); teststats.update(testres); if(PLMPI::rank==0) // write to file { resultrow[0] = k; resultrow_sub << testres; results->appendRow(resultrow); } } if(PLMPI::rank==0) // write global stats to file { // MEAN resultrow[0] = -1; resultrow_sub << teststats.getMean(); results->appendRow(resultrow); // STDERROR resultrow[0] = -2; resultrow_sub << teststats.getStdError(); results->appendRow(resultrow); // STDDEV resultrow[0] = -3; resultrow_sub << teststats.getStdDev(); results->appendRow(resultrow); } }
Reimplemented from PLearn::Object.
Definition at line 100 of file Experiment.h.
Definition at line 66 of file Experiment.h.
Referenced by build_(), and declareOptions().
string PLearn::Experiment::expdir |
Path of this experiment's directory in which to save all experiment results (will be created if it does not already exist)
Definition at line 64 of file Experiment.h.
Referenced by declareOptions(), and run().
Definition at line 65 of file Experiment.h.
Referenced by declareOptions(), and run().
Definition at line 69 of file Experiment.h.
Referenced by declareOptions(), and run().
Definition at line 68 of file Experiment.h.
Referenced by declareOptions(), and run().
Definition at line 71 of file Experiment.h.
Referenced by declareOptions(), and run().
Definition at line 70 of file Experiment.h.
Referenced by declareOptions(), and run().
Definition at line 67 of file Experiment.h.
Referenced by build_(), declareOptions(), and run().