PLearn 0.1
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Static Protected Member Functions | Protected Attributes | Private Types | Private Member Functions
PLearn::VPLPreprocessedLearner Class Reference

#include <VPLPreprocessedLearner.h>

Inheritance diagram for PLearn::VPLPreprocessedLearner:
Inheritance graph
[legend]
Collaboration diagram for PLearn::VPLPreprocessedLearner:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 VPLPreprocessedLearner ()
 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 OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual VPLPreprocessedLearnerdeepCopy (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 bool computeConfidenceFromOutput (const Vec &input, const Vec &output, real probability, TVec< pair< real, real > > &intervals) const
 Compute a confidence intervals for the output, given the input and the pre-computed output (resulting from computeOutput or similar).
virtual TVec< string > getOutputNames () const
 If there's an output_prg, it returns output_prg_fieldnames If there's no output_prg, the call is forwarded to the inner learner.
virtual TVec< std::string > getTestCostNames () const
 *** SUBCLASS WRITING: ***
virtual TVec< string > getTrainCostNames () const
 Forwarded to inner learner.
virtual void resetInternalState ()
 Forwarded to inner learner.
virtual bool isStatefulLearner () const
 Forwarded to inner learner.

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 PPathdeclaringFile ()

Public Attributes

PP< PLearnerlearner_
 Inner learner which is embedded into the current learner.
string trainset_preproc
int newtargetsize
int newweightsize
int newextrasize
string input_preproc
string output_postproc
string costs_postproc

Static Public Attributes

static StaticInitializer _static_initializer_

Static Protected Member Functions

static void declareOptions (OptionList &ol)
 Declares this class' options.

Protected Attributes

PP< VMatLanguagerow_prg
PP< VMatLanguageinput_prg
PP< VMatLanguageoutput_prg
PP< VMatLanguagecosts_prg
TVec< string > row_prg_fieldnames
TVec< string > input_prg_fieldnames
TVec< string > output_prg_fieldnames
TVec< string > costs_prg_fieldnames
Vec row
Vec processed_row
Vec processed_input
Vec pre_output
Vec pre_costs

Private Types

typedef PLearner inherited

Private Member Functions

void build_ ()
 This does the actual building.

Detailed Description

Definition at line 52 of file VPLPreprocessedLearner.h.


Member Typedef Documentation

Reimplemented from PLearn::PLearner.

Definition at line 57 of file VPLPreprocessedLearner.h.


Constructor & Destructor Documentation

PLearn::VPLPreprocessedLearner::VPLPreprocessedLearner ( )

Default constructor.

Definition at line 51 of file VPLPreprocessedLearner.cc.


Member Function Documentation

string PLearn::VPLPreprocessedLearner::_classname_ ( ) [static]

Reimplemented from PLearn::PLearner.

Definition at line 62 of file VPLPreprocessedLearner.cc.

OptionList & PLearn::VPLPreprocessedLearner::_getOptionList_ ( ) [static]

Reimplemented from PLearn::PLearner.

Definition at line 62 of file VPLPreprocessedLearner.cc.

RemoteMethodMap & PLearn::VPLPreprocessedLearner::_getRemoteMethodMap_ ( ) [static]

Reimplemented from PLearn::PLearner.

Definition at line 62 of file VPLPreprocessedLearner.cc.

bool PLearn::VPLPreprocessedLearner::_isa_ ( const Object o) [static]

Reimplemented from PLearn::PLearner.

Definition at line 62 of file VPLPreprocessedLearner.cc.

Object * PLearn::VPLPreprocessedLearner::_new_instance_for_typemap_ ( ) [static]

Reimplemented from PLearn::Object.

Definition at line 62 of file VPLPreprocessedLearner.cc.

StaticInitializer VPLPreprocessedLearner::_static_initializer_ & PLearn::VPLPreprocessedLearner::_static_initialize_ ( ) [static]

Reimplemented from PLearn::PLearner.

Definition at line 62 of file VPLPreprocessedLearner.cc.

void PLearn::VPLPreprocessedLearner::build ( ) [virtual]

Simply calls inherited::build() then build_().

Reimplemented from PLearn::PLearner.

Definition at line 149 of file VPLPreprocessedLearner.cc.

References PLearn::PLearner::build(), and build_().

Here is the call graph for this function:

void PLearn::VPLPreprocessedLearner::build_ ( ) [private]

This does the actual building.

Reimplemented from PLearn::PLearner.

Definition at line 144 of file VPLPreprocessedLearner.cc.

Referenced by build().

{
}

Here is the caller graph for this function:

string PLearn::VPLPreprocessedLearner::classname ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 62 of file VPLPreprocessedLearner.cc.

bool PLearn::VPLPreprocessedLearner::computeConfidenceFromOutput ( const Vec input,
const Vec output,
real  probability,
TVec< pair< real, real > > &  intervals 
) const [virtual]

Compute a confidence intervals for the output, given the input and the pre-computed output (resulting from computeOutput or similar).

The probability level of the confidence interval must be specified. (e.g. 0.95). Result is stored in a TVec of pairs low:high for each output variable (this is a "box" interval; it does not account for correlations among the output variables).

If the interval can be computed, the function returns TRUE; otherwise (i.e. interval computation is not available), it returns FALSE. The default implementation in PLearner is to return FALSE (with missing values in the returned intervals).

Reimplemented from PLearn::PLearner.

Definition at line 385 of file VPLPreprocessedLearner.cc.

References d, PLearn::TVec< T >::first(), input_prg, input_prg_fieldnames, learner_, PLearn::TVec< T >::length(), MISSING_VALUE, output_prg, outputsize(), PLASSERT, PLERROR, pre_output, processed_input, and PLearn::TVec< T >::resize().

{
    int d = outputsize();
    if(d!=output.length())
        PLERROR("In VPLPreprocessedLearner::computeConfidenceFromOutput, length of passed output (%d)"
                "differes from outputsize (%d)!",output.length(),d);

    PLASSERT( learner_ );
    Vec newinput = input;
    if(input_prg && *input_prg)
    {
        processed_input.resize(input_prg_fieldnames.length());
        input_prg->run(input, processed_input);
        newinput = processed_input;
    }

    bool status = false;
    if(!output_prg || !(*output_prg)) // output is already the output of the underlying learner
        status = learner_->computeConfidenceFromOutput(newinput, output, probability, intervals);
    else // must recompute the output of underlying learner, and post-process returned intervals
    {
        learner_->computeOutput(newinput, pre_output);
        TVec< pair<real,real> > pre_intervals;
        status = learner_->computeConfidenceFromOutput(newinput, pre_output, probability, pre_intervals);
        if(!status) // no confidence computation available
        {
            intervals.resize(d);
            for(int k=0; k<d; k++)
                intervals[k] = pair<real,real>(MISSING_VALUE,MISSING_VALUE);
        }
        else // postprocess low and high vectors
        {
            int ud = learner_->outputsize(); // dimension of underlying learner's output
            // first build low and high vectors
            Vec low(ud);
            Vec high(ud);
            for(int k=0; k<ud; k++)
            {
                pair<real,real> p = pre_intervals[k];
                low[k] = p.first;
                high[k] = p.second;
            }
            Vec post_low(d); // postprocesed low
            Vec post_high(d); // postprocessed high

            // Put original input vector as context for output postproc
            output_prg->setMemory(input);
            output_prg->run(low, post_low);

            // Put original input vector as context for output postproc
            output_prg->setMemory(input);
            output_prg->run(high, post_high);

            // Now copy post_low and post_high to intervals
            intervals.resize(d);
            for(int k=0; k<d; k++)
                intervals[k] = pair<real,real>(post_low[k],post_high[k]);
        }
    }
    return status;
}

Here is the call graph for this function:

void PLearn::VPLPreprocessedLearner::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 378 of file VPLPreprocessedLearner.cc.

References computeOutputAndCosts().

{ 
    Vec nonconst_output = output; // to make the constipated compiler happy
    computeOutputAndCosts(input, target, nonconst_output, costs); 
}

Here is the call graph for this function:

void PLearn::VPLPreprocessedLearner::computeOutput ( const Vec input,
Vec output 
) const [virtual]

*** SUBCLASS WRITING: ***

This should be defined in subclasses to compute the output from the input.

Reimplemented from PLearn::PLearner.

Definition at line 309 of file VPLPreprocessedLearner.cc.

References input_prg, input_prg_fieldnames, learner_, PLearn::TVec< T >::length(), output_prg, outputsize(), PLASSERT, pre_output, processed_input, and PLearn::TVec< T >::resize().

{
    PLASSERT( learner_ );
    output.resize(outputsize());
    Vec newinput = input;
    if(input_prg && *input_prg)
    {
        processed_input.resize(input_prg_fieldnames.length());
        input_prg->run(input, processed_input);
        newinput = processed_input;
    }

    if(output_prg && *output_prg)
    {
        learner_->computeOutput(newinput, pre_output);
        output_prg->setMemory(input);           // Put original input vector
        // as context for output postproc
        output_prg->run(pre_output, output);
    }
    else
        learner_->computeOutput(newinput, output);
    
}

Here is the call graph for this function:

void PLearn::VPLPreprocessedLearner::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 333 of file VPLPreprocessedLearner.cc.

References PLearn::TVec< T >::append(), costs_prg, PLearn::PLearner::inputsize(), learner_, PLearn::TVec< T >::length(), newextrasize, newtargetsize, newweightsize, PLearn::PLearner::nTestCosts(), output_prg, outputsize(), PLASSERT, pre_costs, pre_output, processed_input, processed_row, PLearn::TVec< T >::resize(), row, row_prg, row_prg_fieldnames, PLearn::TVec< T >::subVec(), PLearn::PLearner::targetsize(), and PLearn::PLearner::weightsize().

Referenced by computeCostsFromOutputs().

{ 
    output.resize(outputsize());
    costs.resize(nTestCosts());

    PLASSERT( learner_ );
    int ilen = input.length();
    int tlen = target.length();
    PLASSERT(ilen==inputsize());
    PLASSERT(tlen==targetsize());

    if(row_prg && *row_prg)
    {
        row.resize(ilen+tlen);
        row.subVec(0,ilen) << input;
        row.subVec(ilen,tlen) << target;
        if(weightsize()==1)
            row.append(1.0);

        int newrowsize = row_prg_fieldnames.length();
        processed_row.resize(newrowsize);
        row_prg->run(row, processed_row);
        int newinputsize = newrowsize-(newtargetsize+newweightsize+newextrasize);
        Vec processed_input = processed_row.subVec(0,newinputsize);
        Vec processed_target = processed_row.subVec(newinputsize,newtargetsize);
        learner_->computeOutputAndCosts(processed_input, processed_target, pre_output, pre_costs);
    }
    else
        learner_->computeOutputAndCosts(input, target, pre_output, pre_costs);

    if(output_prg && *output_prg) {
        output_prg->setMemory(input);           // Put original input vector
        // as context for output postproc
        output_prg->run(pre_output, output);
    }
    else
        output << pre_output;

    if(costs_prg && *costs_prg)
        costs_prg->run(pre_costs, costs);
    else
        costs << pre_costs;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void PLearn::VPLPreprocessedLearner::declareOptions ( OptionList ol) [static, protected]

Declares this class' options.

Reimplemented from PLearn::PLearner.

Definition at line 64 of file VPLPreprocessedLearner.cc.

References PLearn::OptionBase::buildoption, costs_postproc, costs_prg, costs_prg_fieldnames, PLearn::declareOption(), PLearn::PLearner::declareOptions(), input_preproc, input_prg, input_prg_fieldnames, learner_, PLearn::OptionBase::learntoption, newextrasize, newtargetsize, newweightsize, output_postproc, output_prg, output_prg_fieldnames, row_prg, row_prg_fieldnames, and trainset_preproc.

{
    // ### 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", &VPLPreprocessedLearner::myoption, OptionBase::buildoption,
    //               "Help text describing this option");
    // ...

    declareOption(ol, "learner", &VPLPreprocessedLearner::learner_,
                  OptionBase::buildoption,
                  "The embedded learner");

    declareOption(ol, "trainset_preproc", &VPLPreprocessedLearner::trainset_preproc, OptionBase::buildoption,
                  "Program string in VPL language to be applied to each row of the initial\n"
                  "training set to generate the new preprocessed training set.\n"
                  "This should generate preprocessed input and target (and weight if any).\n"
                  "Note that names must be given to the generated values with :fieldname VPL syntax.\n"
                  "An empty string means NO PREPROCESSING. (initial training set is used as is)");
    declareOption(ol, "newtargetsize", &VPLPreprocessedLearner::newtargetsize, OptionBase::buildoption,
                  "Size of target produced by trainset_preproc (target must follow preprocessed input).");
    declareOption(ol, "newweightsize", &VPLPreprocessedLearner::newweightsize, OptionBase::buildoption,
                  "0 or 1, depending on whether trainset_preproc generates a weight or not after the target.");
    declareOption(ol, "newextrasize", &VPLPreprocessedLearner::newextrasize, OptionBase::buildoption,
                  "size of extra fields generated by trainset_preproc after target and wright.");

    declareOption(ol, "input_preproc", &VPLPreprocessedLearner::input_preproc, OptionBase::buildoption,
                  "Program string in VPL language to be applied to a new input.\n"
                  "This must produce exactly the same thing as the preprocessed.\n"
                  "input part produced by trainset_preproc\n"
                  "Note that names must be given to the generated values with :fieldname VPL syntax.\n");
  
    declareOption(ol, "output_postproc", &VPLPreprocessedLearner::output_postproc, OptionBase::buildoption,
                  "Program string in VPL language to optain postprocessed output\n"
                  "from the underlying learner's output.\n"
                  "Note that names must be given to the generated values with :fieldname VPL syntax.\n"
                  "An empty string means NO OUTPUT POSTPROCESSING.\n\n"
                  "Additional Note: when this snippet of VPL starts executing, the\n"
                  "ORIGINAL (not preprocessed) input row is stored in VPL memory, starting\n"
                  "from memory location 0 until inputsize-1 (inclusive).  You can access these\n"
                  "memory locations using VPL instructions of the form:\n"
                  "\n"
                  "    <memory_location> memget\n"
                  "\n"
                  "This lets the output postprocessor use some information from the input\n"
                  "vector to construct the output (e.g. put back some data that was hidden\n"
                  "from the embedded learner.)");
    declareOption(ol, "costs_postproc", &VPLPreprocessedLearner::costs_postproc, OptionBase::buildoption,
                  "Program string in VPL language to optain postprocessed test costs\n"
                  "from the underlying learner's test costs.\n"
                  "Note that names must be given to the generated values with :fieldname VPL syntax.\n"
                  "An empty string means NO COSTS POSTPROCESSING.\n"
                  "Note that the *train* costs are those of the underlying learner. No postproc is applied to those.");

    declareOption(ol, "row_prg", &VPLPreprocessedLearner::row_prg, OptionBase::learntoption,
                  "Compiled trainset_preproc program");
    declareOption(ol, "input_prg", &VPLPreprocessedLearner::input_prg, OptionBase::learntoption,
                  "Compiled input_preproc program");
    declareOption(ol, "output_prg", &VPLPreprocessedLearner::output_prg, OptionBase::learntoption,
                  "Compiled output_postproc program");
    declareOption(ol, "costs_prg", &VPLPreprocessedLearner::costs_prg, OptionBase::learntoption,
                  "Compiled costs_postproc program");

    declareOption(ol, "row_prg_fieldnames", &VPLPreprocessedLearner::row_prg_fieldnames, OptionBase::learntoption,
                  "names of fields produced by row_prg");
    declareOption(ol, "input_prg_fieldnames", &VPLPreprocessedLearner::input_prg_fieldnames, OptionBase::learntoption,
                  "names of fields produced by input_prg");
    declareOption(ol, "output_prg_fieldnames", &VPLPreprocessedLearner::output_prg_fieldnames, OptionBase::learntoption,
                  "names of fields produced by output_prg");
    declareOption(ol, "costs_prg_fieldnames", &VPLPreprocessedLearner::costs_prg_fieldnames, OptionBase::learntoption,
                  "names of fields produced by costs_prg");

    // Now call the parent class' declareOptions
    inherited::declareOptions(ol);
}

Here is the call graph for this function:

static const PPath& PLearn::VPLPreprocessedLearner::declaringFile ( ) [inline, static]

Reimplemented from PLearn::PLearner.

Definition at line 141 of file VPLPreprocessedLearner.h.

VPLPreprocessedLearner * PLearn::VPLPreprocessedLearner::deepCopy ( CopiesMap copies) const [virtual]

Reimplemented from PLearn::PLearner.

Definition at line 62 of file VPLPreprocessedLearner.cc.

void PLearn::VPLPreprocessedLearner::forget ( ) [virtual]

Forwarded to inner learner.

Reimplemented from PLearn::PLearner.

Definition at line 220 of file VPLPreprocessedLearner.cc.

References learner_, PLASSERT, and PLearn::PLearner::stage.

{
    PLASSERT( learner_);
    learner_->forget();
    stage = 0;
}
OptionList & PLearn::VPLPreprocessedLearner::getOptionList ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 62 of file VPLPreprocessedLearner.cc.

OptionMap & PLearn::VPLPreprocessedLearner::getOptionMap ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 62 of file VPLPreprocessedLearner.cc.

TVec< string > PLearn::VPLPreprocessedLearner::getOutputNames ( ) const [virtual]

If there's an output_prg, it returns output_prg_fieldnames If there's no output_prg, the call is forwarded to the inner learner.

Reimplemented from PLearn::PLearner.

Definition at line 449 of file VPLPreprocessedLearner.cc.

References learner_, output_prg, and output_prg_fieldnames.

{
    if(output_prg && *output_prg)
        return output_prg_fieldnames;
    else
        return learner_->getOutputNames();
}
RemoteMethodMap & PLearn::VPLPreprocessedLearner::getRemoteMethodMap ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 62 of file VPLPreprocessedLearner.cc.

TVec< string > PLearn::VPLPreprocessedLearner::getTestCostNames ( ) const [virtual]

*** SUBCLASS WRITING: ***

This should return the names of the costs computed by computeCostsFromOutputs.

Implements PLearn::PLearner.

Definition at line 458 of file VPLPreprocessedLearner.cc.

References costs_prg, costs_prg_fieldnames, and learner_.

{
    if(costs_prg && *costs_prg)
        return costs_prg_fieldnames;
    else
        return learner_->getTestCostNames();
}
TVec< string > PLearn::VPLPreprocessedLearner::getTrainCostNames ( ) const [virtual]

Forwarded to inner learner.

Implements PLearn::PLearner.

Definition at line 466 of file VPLPreprocessedLearner.cc.

References learner_, and PLASSERT.

{
    PLASSERT( learner_ );
    return learner_->getTrainCostNames();
}
bool PLearn::VPLPreprocessedLearner::isStatefulLearner ( ) const [virtual]

Forwarded to inner learner.

Reimplemented from PLearn::PLearner.

Definition at line 478 of file VPLPreprocessedLearner.cc.

References learner_, and PLASSERT.

{
    PLASSERT( learner_ );
    return learner_->isStatefulLearner();
}
void PLearn::VPLPreprocessedLearner::makeDeepCopyFromShallowCopy ( CopiesMap copies) [virtual]

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::PLearner.

Definition at line 156 of file VPLPreprocessedLearner.cc.

References costs_prg, costs_prg_fieldnames, PLearn::deepCopyField(), input_prg, input_prg_fieldnames, learner_, PLearn::PLearner::makeDeepCopyFromShallowCopy(), output_prg, output_prg_fieldnames, pre_costs, pre_output, processed_input, processed_row, row, row_prg, and row_prg_fieldnames.

{
    inherited::makeDeepCopyFromShallowCopy(copies);

    // ### Call deepCopyField on all "pointer-like" fields 
    // ### that you wish to be deepCopied rather than 
    // ### shallow-copied.

    deepCopyField(learner_, copies);    

    deepCopyField(row_prg, copies);
    deepCopyField(input_prg, copies);
    deepCopyField(output_prg, copies);
    deepCopyField(costs_prg, copies);
/*
    row_prg.makeDeepCopyFromShallowCopy(copies);
    input_prg.makeDeepCopyFromShallowCopy(copies);
    output_prg.makeDeepCopyFromShallowCopy(copies);
    costs_prg.makeDeepCopyFromShallowCopy(copies);
*/
 
    deepCopyField(row_prg_fieldnames, copies); 
    deepCopyField(input_prg_fieldnames, copies);
    deepCopyField(output_prg_fieldnames, copies);
    deepCopyField(costs_prg_fieldnames, copies);
    deepCopyField(row, copies);
    deepCopyField(processed_row, copies);
    deepCopyField(processed_input, copies);
    deepCopyField(pre_output, copies);
    deepCopyField(pre_costs, copies);
}

Here is the call graph for this function:

int PLearn::VPLPreprocessedLearner::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 202 of file VPLPreprocessedLearner.cc.

References learner_, PLearn::TVec< T >::length(), output_prg, output_prg_fieldnames, and PLASSERT.

Referenced by computeConfidenceFromOutput(), computeOutput(), and computeOutputAndCosts().

{
    if(output_prg && *output_prg)
        return output_prg_fieldnames.length();
    else
    {
        PLASSERT( learner_ );
        return learner_->outputsize();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void PLearn::VPLPreprocessedLearner::resetInternalState ( ) [virtual]

Forwarded to inner learner.

Reimplemented from PLearn::PLearner.

Definition at line 472 of file VPLPreprocessedLearner.cc.

References learner_, and PLASSERT.

{
    PLASSERT( learner_ );
    learner_->resetInternalState();
}
void PLearn::VPLPreprocessedLearner::setExperimentDirectory ( const PPath the_expdir) [virtual]

Forwarded to inner learner.

Reimplemented from PLearn::PLearner.

Definition at line 213 of file VPLPreprocessedLearner.cc.

References learner_, PLASSERT, and PLearn::PLearner::setExperimentDirectory().

{
    PLASSERT( learner_ );
    inherited::setExperimentDirectory(the_expdir);
    learner_->setExperimentDirectory(the_expdir);
}

Here is the call graph for this function:

void PLearn::VPLPreprocessedLearner::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 234 of file VPLPreprocessedLearner.cc.

References costs_postproc, costs_prg, costs_prg_fieldnames, input_preproc, input_prg, input_prg_fieldnames, learner_, PLearn::TVec< T >::length(), newextrasize, newtargetsize, newweightsize, output_postproc, output_prg, output_prg_fieldnames, PLASSERT, PLearn::TVec< T >::resize(), row_prg, row_prg_fieldnames, PLearn::PLearner::setTrainingSet(), PLearn::tostring(), PLearn::PLearner::train_set, and trainset_preproc.

{
    PLASSERT( learner_ );

    if(!row_prg) 
        row_prg= new VMatLanguage();
    if(trainset_preproc!="")
    {
        row_prg->setSource(training_set);
        row_prg->compileString(trainset_preproc, row_prg_fieldnames);
        int newinputsize = row_prg_fieldnames.length()-(newtargetsize+newweightsize+newextrasize);
        VMat processed_trainset = new ProcessingVMatrix(training_set, trainset_preproc);
        processed_trainset->defineSizes(newinputsize,newtargetsize,newweightsize,newextrasize);
        learner_->setTrainingSet(processed_trainset, false);
    }
    else
    {
        row_prg->clear();
        row_prg_fieldnames.resize(0);
        learner_->setTrainingSet(training_set, false);
    }
    bool training_set_has_changed = !train_set || !(train_set->looksTheSameAs(training_set));
    if (call_forget && !training_set_has_changed)
        // In this case, learner_->build() will not have been called, which may
        // cause trouble if it updates data from the training set.
        learner_->build();
    inherited::setTrainingSet(training_set, call_forget); // will call forget if needed

    if(!input_prg) 
        input_prg= new VMatLanguage();
    if(input_preproc!="")
    {
        int insize = training_set->inputsize();
        TVec<string> infieldnames = training_set->fieldNames().subVec(0,insize);
        input_prg->setSourceFieldNames(infieldnames);
        input_prg->compileString(input_preproc, input_prg_fieldnames);
    }
    else
    {
        input_prg->clear();
        input_prg_fieldnames.resize(0);
    }

    if(!output_prg) 
        output_prg= new VMatLanguage();
    if(output_postproc!="")
    {
        int outsize = learner_->outputsize();
        TVec<string> outfieldnames(outsize);
        for(int k=0; k<outsize; k++)
            outfieldnames[k] = "output"+tostring(k);
        output_prg->setSourceFieldNames(outfieldnames);
        output_prg->compileString(output_postproc, output_prg_fieldnames);
    }
    else
    {
        output_prg->clear();
        output_prg_fieldnames.resize(0);
    }

    if(!costs_prg) 
        costs_prg= new VMatLanguage();
    if(costs_postproc!="")
    {
        costs_prg->setSourceFieldNames(learner_->getTestCostNames());
        costs_prg->compileString(costs_postproc, costs_prg_fieldnames);
    }
    else
    {
        costs_prg->clear();
        costs_prg_fieldnames.resize(0);
    }
}

Here is the call graph for this function:

void PLearn::VPLPreprocessedLearner::setTrainStatsCollector ( PP< VecStatsCollector statscol) [virtual]

Forwarded to inner learner.

Reimplemented from PLearn::PLearner.

Definition at line 195 of file VPLPreprocessedLearner.cc.

References learner_, PLASSERT, and PLearn::PLearner::setTrainStatsCollector().

{
    PLASSERT( learner_ );
    inherited::setTrainStatsCollector(statscol);
    learner_->setTrainStatsCollector(statscol);
}

Here is the call graph for this function:

void PLearn::VPLPreprocessedLearner::setValidationSet ( VMat  validset) [virtual]

Forwarded to inner learner.

Reimplemented from PLearn::PLearner.

Definition at line 188 of file VPLPreprocessedLearner.cc.

References learner_, PLASSERT, and PLearn::PLearner::setValidationSet().

{
    PLASSERT( learner_ );
    inherited::setValidationSet(validset);
    learner_->setValidationSet(validset);
}

Here is the call graph for this function:

void PLearn::VPLPreprocessedLearner::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 227 of file VPLPreprocessedLearner.cc.

References learner_, PLASSERT, and PLearn::PLearner::stage.

{
    PLASSERT( learner_ );
    learner_->train();
    stage = learner_->stage;
}

Member Data Documentation

Reimplemented from PLearn::PLearner.

Definition at line 141 of file VPLPreprocessedLearner.h.

Definition at line 98 of file VPLPreprocessedLearner.h.

Referenced by declareOptions(), and setTrainingSet().

Definition at line 96 of file VPLPreprocessedLearner.h.

Referenced by declareOptions(), and setTrainingSet().

Definition at line 94 of file VPLPreprocessedLearner.h.

Referenced by computeOutputAndCosts(), declareOptions(), and setTrainingSet().

Definition at line 92 of file VPLPreprocessedLearner.h.

Referenced by computeOutputAndCosts(), declareOptions(), and setTrainingSet().

Definition at line 93 of file VPLPreprocessedLearner.h.

Referenced by computeOutputAndCosts(), declareOptions(), and setTrainingSet().

Definition at line 97 of file VPLPreprocessedLearner.h.

Referenced by declareOptions(), and setTrainingSet().

Definition at line 80 of file VPLPreprocessedLearner.h.

Referenced by computeOutputAndCosts(), and makeDeepCopyFromShallowCopy().

Definition at line 77 of file VPLPreprocessedLearner.h.

Referenced by computeOutputAndCosts(), and makeDeepCopyFromShallowCopy().

Definition at line 76 of file VPLPreprocessedLearner.h.

Referenced by computeOutputAndCosts(), and makeDeepCopyFromShallowCopy().

Definition at line 91 of file VPLPreprocessedLearner.h.

Referenced by declareOptions(), and setTrainingSet().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines