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::VPLPreprocessedLearner2 Class Reference

#include <VPLPreprocessedLearner2.h>

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

List of all members.

Public Member Functions

 VPLPreprocessedLearner2 ()
 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 VPLPreprocessedLearner2deepCopy (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 filtering_prg
string input_prg
string target_prg
string weight_prg
string extra_prg
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 input_prg_
VMatLanguage target_prg_
VMatLanguage weight_prg_
VMatLanguage extra_prg_
VMatLanguage output_prg_
VMatLanguage costs_prg_
TVec< string > input_prg_fieldnames
TVec< string > target_prg_fieldnames
TVec< string > weight_prg_fieldnames
TVec< string > extra_prg_fieldnames
TVec< string > output_prg_fieldnames
TVec< string > costs_prg_fieldnames
Vec row
Vec processed_input
Vec processed_target
Vec processed_weight
Vec processed_extra
Vec pre_output
Vec pre_costs
TVec< string > orig_fieldnames
int orig_inputsize
int orig_targetsize
bool use_filtering_prg_for_repeat
string repeat_id_field_name
string repeat_count_field_name
bool ignore_test_costs

Private Types

typedef PLearner inherited

Private Member Functions

void build_ ()
 This does the actual building.
void initializeInputPrograms ()
void initializeOutputPrograms ()

Detailed Description

Definition at line 52 of file VPLPreprocessedLearner2.h.


Member Typedef Documentation

Reimplemented from PLearn::PLearner.

Definition at line 57 of file VPLPreprocessedLearner2.h.


Constructor & Destructor Documentation

PLearn::VPLPreprocessedLearner2::VPLPreprocessedLearner2 ( )

Default constructor.

Definition at line 52 of file VPLPreprocessedLearner2.cc.


Member Function Documentation

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

Reimplemented from PLearn::PLearner.

Definition at line 67 of file VPLPreprocessedLearner2.cc.

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

Reimplemented from PLearn::PLearner.

Definition at line 67 of file VPLPreprocessedLearner2.cc.

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

Reimplemented from PLearn::PLearner.

Definition at line 67 of file VPLPreprocessedLearner2.cc.

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

Reimplemented from PLearn::PLearner.

Definition at line 67 of file VPLPreprocessedLearner2.cc.

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

Reimplemented from PLearn::Object.

Definition at line 67 of file VPLPreprocessedLearner2.cc.

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

Reimplemented from PLearn::PLearner.

Definition at line 67 of file VPLPreprocessedLearner2.cc.

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

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

Reimplemented from PLearn::PLearner.

Definition at line 173 of file VPLPreprocessedLearner2.cc.

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

Here is the call graph for this function:

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

This does the actual building.

Reimplemented from PLearn::PLearner.

Definition at line 161 of file VPLPreprocessedLearner2.cc.

References costs_prg, costs_prg_fieldnames, PLearn::VMatLanguage::getOutputFieldNamesFromString(), initializeInputPrograms(), 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 VPLPreprocessedLearner2
    {
        initializeInputPrograms();
        initializeOutputPrograms();
    }
    else if(!costs_prg.empty())
        VMatLanguage::getOutputFieldNamesFromString(costs_prg, costs_prg_fieldnames);
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 67 of file VPLPreprocessedLearner2.cc.

bool PLearn::VPLPreprocessedLearner2::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).

output_prg_) // output is already the output of the underlying learner

Reimplemented from PLearn::PLearner.

Definition at line 529 of file VPLPreprocessedLearner2.cc.

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

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

    PLASSERT( learner_ );
    Vec newinput = input;
    if(!input_prg.empty())//input_prg_)
    {
        processed_input.resize(input_prg_fieldnames.length());
        input_prg_.run(input, processed_input);
        newinput = processed_input;
    }

    bool status = false;
    if(output_prg.empty())
        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

            output_prg_.run(concat(input,low), post_low);
            output_prg_.run(concat(input,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::VPLPreprocessedLearner2::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 522 of file VPLPreprocessedLearner2.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::VPLPreprocessedLearner2::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 449 of file VPLPreprocessedLearner2.cc.

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

Referenced by computeOutputAndCosts().

{
    PLASSERT( learner_ );
    output.resize(outputsize());
    Vec newinput = input;
    if(!input_prg.empty())
    {
        processed_input.resize(input_prg_fieldnames.length());
        input_prg_.run(input, processed_input);
        newinput = processed_input;
    }

    if(!output_prg.empty())
    {
        learner_->computeOutput(newinput, pre_output);
        // as context for output postproc
        output_prg_.run(concat(input,pre_output), output);
    }
    else
        learner_->computeOutput(newinput, output);
    
}

Here is the call graph for this function:

Here is the caller graph for this function:

void PLearn::VPLPreprocessedLearner2::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 472 of file VPLPreprocessedLearner2.cc.

References computeOutput(), PLearn::concat(), costs_prg, costs_prg_, PLearn::TVec< T >::fill(), ignore_test_costs, input_prg, input_prg_, input_prg_fieldnames, PLearn::PLearner::inputsize(), learner_, PLearn::TVec< T >::length(), PLearn::PLearner::nTestCosts(), orig_fieldnames, output_prg, output_prg_, outputsize(), PLASSERT, pre_costs, pre_output, processed_input, processed_target, PLearn::TVec< T >::resize(), PLearn::VMatLanguage::run(), target_prg, target_prg_, target_prg_fieldnames, and PLearn::PLearner::targetsize().

Referenced by computeCostsFromOutputs().

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

    if(ignore_test_costs)
    {
        costs.fill(-1);
        return computeOutput(input, output);
    }

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

    Vec newinput = input;
    if(!input_prg.empty())//input_prg_)
    {
        processed_input.resize(input_prg_fieldnames.length());
        input_prg_.run(input, processed_input);
        newinput = processed_input;
    }

    Vec orig_row = concat(input,target);
    orig_row.resize(orig_fieldnames.length());

    Vec newtarget = target;
    if(!target_prg.empty())//target_prg_)
    {
        processed_target.resize(target_prg_fieldnames.length());
        target_prg_.run(orig_row, processed_target);
        newtarget = processed_target;
    }

    pre_costs.resize(learner_->nTestCosts());
    learner_->computeOutputAndCosts(newinput, newtarget, pre_output, pre_costs);

    if(!output_prg.empty())//output_prg_)
        output_prg_.run(concat(input,pre_output), output);
    else
        output << pre_output;

   
    if(!costs_prg.empty())//costs_prg_)
        costs_prg_.run(concat(input,target,pre_output,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::VPLPreprocessedLearner2::declareOptions ( OptionList ol) [static, protected]

Declares this class' options.

Reimplemented from PLearn::PLearner.

Definition at line 69 of file VPLPreprocessedLearner2.cc.

References PLearn::OptionBase::buildoption, costs_prg, PLearn::declareOption(), PLearn::PLearner::declareOptions(), extra_prg, filtering_prg, ignore_test_costs, input_prg, learner_, PLearn::OptionBase::learntoption, orig_fieldnames, orig_inputsize, orig_targetsize, output_prg, repeat_count_field_name, repeat_id_field_name, target_prg, use_filtering_prg_for_repeat, and weight_prg.

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

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

    declareOption(ol, "filtering_prg", &VPLPreprocessedLearner2::filtering_prg, OptionBase::buildoption,
                  "Optional program string in VPL language to apply as filtering on the training VMat.\n"
                  "It's the resulting filtered training set that is passed to the underlying learner.\n"
                  "This program is to produce a single value interpreted as a boolean: only the rows for which\n"
                  "it evaluates to non-zero will be kept.\n"
                  "An empty string means NO FILTERING.");

    declareOption(ol, "input_prg", &VPLPreprocessedLearner2::input_prg, OptionBase::buildoption,
                  "Program string in VPL language to be applied to each raw input \n"
                  "to generate the new preprocessed input.\n"
                  "Note that names must be given to the generated values with :fieldname VPL syntax.\n"
                  "An empty string means NO PREPROCESSING. (initial raw input is used as is)");

    declareOption(ol, "target_prg", &VPLPreprocessedLearner2::target_prg, OptionBase::buildoption,
                  "Program string in VPL language to be applied to a dataset row\n"
                  "to generate a proper target for the underlying learner.\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 use the original target from the data set");
  
    declareOption(ol, "weight_prg", &VPLPreprocessedLearner2::weight_prg, OptionBase::buildoption,
                  "Program string in VPL language to be applied to a dataset row\n"
                  "to generate a proper weight for the underlying learner.\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 use the original weight from the data set");

    declareOption(ol, "extra_prg", &VPLPreprocessedLearner2::extra_prg, OptionBase::buildoption,
                  "Program string in VPL language to be applied to a dataset row\n"
                  "to generate proper extra fields for the underlying learner.\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 use the original extra fields from the data set");

    declareOption(ol, "output_prg", &VPLPreprocessedLearner2::output_prg, OptionBase::buildoption,
                  "Program string in VPL language to obtain postprocessed output\n"
                  "from a concatenation of the raw input fields and the underlying learner's outputs\n"
                  "The underlying learner's outputs are typically named out0, out1, out2, ...\n"
                  "Note that outputnames 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 outputs.\n");

    declareOption(ol, "costs_prg", &VPLPreprocessedLearner2::costs_prg, OptionBase::buildoption,
                  "Program string in VPL language to obtain postprocessed test costs\n"
                  "from a concatenation of the raw input fields and target fields, \n"
                  "and the underlying learner's 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", &VPLPreprocessedLearner2::orig_fieldnames, OptionBase::learntoption,
                  "original fieldnames of the training set");
    declareOption(ol, "orig_inputsize", &VPLPreprocessedLearner2::orig_inputsize, OptionBase::learntoption,
                  "original inputsize of the training set");
    declareOption(ol, "orig_targetsize", &VPLPreprocessedLearner2::orig_targetsize, OptionBase::learntoption,
                  "original targetsize of the training set");


    declareOption(ol, "use_filtering_prg_for_repeat", &VPLPreprocessedLearner2::use_filtering_prg_for_repeat, OptionBase::buildoption,
                  "When true, the result of the filtering program indicates the number of times a row should be repeated (0..n).\n"
                  "(sets FilteredVMatrix::allow_repeat_rows.)");

    declareOption(ol, "repeat_id_field_name", &VPLPreprocessedLearner2::repeat_id_field_name, OptionBase::buildoption,
                  "Field name for the repetition id (0, 1, ..., n-1).  No field is added if empty.");

    declareOption(ol, "repeat_count_field_name", &VPLPreprocessedLearner2::repeat_count_field_name, OptionBase::buildoption,
                  "Field name for the number of repetitions (n).  No field is added if empty.");

    declareOption(ol, "ignore_test_costs", &VPLPreprocessedLearner2::ignore_test_costs, OptionBase::buildoption,
                  "WARNING: THIS IS AN UGLY HACK!!\n"
                  "When set to true, computeOutputAndCosts will simply call computeOutput and return bogus costs.");




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

Here is the call graph for this function:

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

Reimplemented from PLearn::PLearner.

Definition at line 157 of file VPLPreprocessedLearner2.h.

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

Reimplemented from PLearn::PLearner.

Definition at line 67 of file VPLPreprocessedLearner2.cc.

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

Forwarded to inner learner.

Reimplemented from PLearn::PLearner.

Definition at line 244 of file VPLPreprocessedLearner2.cc.

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

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

Reimplemented from PLearn::Object.

Definition at line 67 of file VPLPreprocessedLearner2.cc.

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

Reimplemented from PLearn::Object.

Definition at line 67 of file VPLPreprocessedLearner2.cc.

TVec< string > PLearn::VPLPreprocessedLearner2::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 588 of file VPLPreprocessedLearner2.cc.

References learner_, output_prg, and output_prg_fieldnames.

{
    if(!output_prg.empty())//output_prg_)
        return output_prg_fieldnames;
    else
        return learner_->getOutputNames();
}
RemoteMethodMap & PLearn::VPLPreprocessedLearner2::getRemoteMethodMap ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 67 of file VPLPreprocessedLearner2.cc.

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

*** SUBCLASS WRITING: ***

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

Implements PLearn::PLearner.

Definition at line 597 of file VPLPreprocessedLearner2.cc.

References costs_prg, costs_prg_fieldnames, and learner_.

{
    if(!costs_prg.empty())//costs_prg_)
        return costs_prg_fieldnames;
    else
        return learner_->getTestCostNames();
}
TVec< string > PLearn::VPLPreprocessedLearner2::getTrainCostNames ( ) const [virtual]

Forwarded to inner learner.

Implements PLearn::PLearner.

Definition at line 605 of file VPLPreprocessedLearner2.cc.

References learner_, and PLASSERT.

{
    PLASSERT( learner_ );
    return learner_->getTrainCostNames();
}
void PLearn::VPLPreprocessedLearner2::initializeInputPrograms ( ) [private]
void PLearn::VPLPreprocessedLearner2::initializeOutputPrograms ( ) [private]

Definition at line 306 of file VPLPreprocessedLearner2.cc.

References PLearn::VMatLanguage::clear(), PLearn::VMatLanguage::compileString(), PLearn::concat(), costs_prg, costs_prg_, costs_prg_fieldnames, learner_, orig_fieldnames, orig_inputsize, orig_targetsize, output_prg, output_prg_, output_prg_fieldnames, PLearn::TVec< T >::resize(), PLearn::VMatLanguage::setSourceFieldNames(), 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);

    if(!output_prg.empty())
    {
        output_prg_.setSourceFieldNames(concat(orig_input_fieldnames,learner_->getOutputNames()) );
        output_prg_.compileString(output_prg, output_prg_fieldnames);
    }
    else
    {
        output_prg_.clear();
        output_prg_fieldnames.resize(0);
    }

    if(!costs_prg.empty())
    {
        costs_prg_.setSourceFieldNames(concat(orig_input_fieldnames,orig_target_fieldnames,learner_->getOutputNames(),learner_->getTestCostNames()) );
        costs_prg_.compileString(costs_prg, costs_prg_fieldnames);
    }
    else
    {
        costs_prg_.clear();
        costs_prg_fieldnames.resize(0);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool PLearn::VPLPreprocessedLearner2::isStatefulLearner ( ) const [virtual]

Forwarded to inner learner.

Reimplemented from PLearn::PLearner.

Definition at line 617 of file VPLPreprocessedLearner2.cc.

References learner_, and PLASSERT.

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

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::PLearner.

Definition at line 180 of file VPLPreprocessedLearner2.cc.

References costs_prg_, costs_prg_fieldnames, PLearn::deepCopyField(), extra_prg_, extra_prg_fieldnames, input_prg_, input_prg_fieldnames, learner_, PLearn::VMatLanguage::makeDeepCopyFromShallowCopy(), PLearn::PLearner::makeDeepCopyFromShallowCopy(), output_prg_, output_prg_fieldnames, pre_costs, pre_output, processed_extra, processed_input, processed_target, processed_weight, row, target_prg_, target_prg_fieldnames, weight_prg_, and weight_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);    

    input_prg_.makeDeepCopyFromShallowCopy(copies);
    target_prg_.makeDeepCopyFromShallowCopy(copies);
    weight_prg_.makeDeepCopyFromShallowCopy(copies);
    extra_prg_.makeDeepCopyFromShallowCopy(copies);
    output_prg_.makeDeepCopyFromShallowCopy(copies);
    costs_prg_.makeDeepCopyFromShallowCopy(copies);
 
    deepCopyField(input_prg_fieldnames, copies);
    deepCopyField(target_prg_fieldnames, copies);
    deepCopyField(weight_prg_fieldnames, copies);
    deepCopyField(extra_prg_fieldnames, copies);
    deepCopyField(output_prg_fieldnames, copies);
    deepCopyField(costs_prg_fieldnames, copies);
    deepCopyField(row, copies);
    deepCopyField(processed_input, copies);
    deepCopyField(processed_target, copies);
    deepCopyField(processed_weight, copies);
    deepCopyField(processed_extra, copies);
    deepCopyField(pre_output, copies);
    deepCopyField(pre_costs, copies);
}

Here is the call graph for this function:

int PLearn::VPLPreprocessedLearner2::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 226 of file VPLPreprocessedLearner2.cc.

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

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

{
    if(!output_prg.empty())
        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::VPLPreprocessedLearner2::resetInternalState ( ) [virtual]

Forwarded to inner learner.

Reimplemented from PLearn::PLearner.

Definition at line 611 of file VPLPreprocessedLearner2.cc.

References learner_, and PLASSERT.

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

Forwarded to inner learner.

Reimplemented from PLearn::PLearner.

Definition at line 237 of file VPLPreprocessedLearner2.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::VPLPreprocessedLearner2::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 334 of file VPLPreprocessedLearner2.cc.

References extra_prg, filtering_prg, PLearn::PLearner::getExperimentDirectory(), initializeInputPrograms(), initializeOutputPrograms(), input_prg, learner_, orig_fieldnames, orig_inputsize, orig_targetsize, PLASSERT, repeat_count_field_name, repeat_id_field_name, PLearn::PLearner::setTrainingSet(), target_prg, PLearn::PLearner::train_set, use_filtering_prg_for_repeat, PLearn::PLearner::verbosity, and weight_prg.

{
    PLASSERT( learner_ );

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

    orig_fieldnames = training_set->fieldNames();
    orig_inputsize  = training_set->inputsize();
    orig_targetsize  = training_set->targetsize();
    initializeInputPrograms();

    VMat filtered_trainset = training_set;
    PPath filtered_trainset_metadatadir = getExperimentDirectory() / "filtered_train_set.metadata";
    if(!filtering_prg.empty())
        filtered_trainset = new FilteredVMatrix(training_set, filtering_prg, filtered_trainset_metadatadir, verbosity>1,
                                                use_filtering_prg_for_repeat, repeat_id_field_name, repeat_count_field_name);

    VMat processed_trainset = new ProcessingVMatrix(filtered_trainset, input_prg, target_prg, weight_prg, extra_prg);
    learner_->setTrainingSet(processed_trainset, false);
    inherited::setTrainingSet(training_set, call_forget); // will call forget if needed

    initializeOutputPrograms();
}

Here is the call graph for this function:

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

Forwarded to inner learner.

Reimplemented from PLearn::PLearner.

Definition at line 219 of file VPLPreprocessedLearner2.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::VPLPreprocessedLearner2::setValidationSet ( VMat  validset) [virtual]

Forwarded to inner learner.

Reimplemented from PLearn::PLearner.

Definition at line 212 of file VPLPreprocessedLearner2.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::VPLPreprocessedLearner2::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 251 of file VPLPreprocessedLearner2.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 157 of file VPLPreprocessedLearner2.h.

Definition at line 102 of file VPLPreprocessedLearner2.h.

Referenced by declareOptions(), and setTrainingSet().

Definition at line 78 of file VPLPreprocessedLearner2.h.

Referenced by computeOutputAndCosts(), and makeDeepCopyFromShallowCopy().

Definition at line 76 of file VPLPreprocessedLearner2.h.

Referenced by makeDeepCopyFromShallowCopy().

Definition at line 76 of file VPLPreprocessedLearner2.h.

Referenced by computeOutputAndCosts(), and makeDeepCopyFromShallowCopy().

Definition at line 76 of file VPLPreprocessedLearner2.h.

Referenced by makeDeepCopyFromShallowCopy().

Definition at line 90 of file VPLPreprocessedLearner2.h.

Referenced by declareOptions(), and setTrainingSet().

Definition at line 89 of file VPLPreprocessedLearner2.h.

Referenced by declareOptions(), and setTrainingSet().

Definition at line 75 of file VPLPreprocessedLearner2.h.

Referenced by makeDeepCopyFromShallowCopy().

Definition at line 88 of file VPLPreprocessedLearner2.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