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

#include <PLearnerOutputVMatrix.h>

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

List of all members.

Public Member Functions

 PLearnerOutputVMatrix (bool call_build_=false)
 PLearnerOutputVMatrix (VMat source_, TVec< PP< PLearner > > learners_, bool put_raw_input_=false, bool train_learners_=false, bool compute_output_once_=false, bool put_non_input_=true, bool call_build_=true)
 PLearnerOutputVMatrix (VMat source_, PP< PLearner > learner, bool put_raw_input_=false, bool train_learners_=false, bool compute_output_once_=false, bool put_non_input_=true, bool call_build_=true)
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 PLearnerOutputVMatrixdeepCopy (CopiesMap &copies) const

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

Public Attributes

VMat fieldinfos_source
VMat data_train
TVec< PP< PLearner > > learners
bool put_raw_input
bool put_non_input
bool train_learners
bool compute_output_once

Static Public Attributes

static StaticInitializer _static_initializer_

Protected Member Functions

virtual void getNewRow (int i, const Vec &v) const
 This is the only method requiring implementation.

Static Protected Member Functions

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

Protected Attributes

Vec row
Vec learner_input
TVec< Veclearners_output
 Instead of Mat to allow learners of various outputsizes.
Vec learner_target
Vec non_input_part_of_source_row
bool learners_need_train
 Used to keep track of whether learners need training or not.
TVec< Matcomplete_learners_output

Private Types

typedef SourceVMatrix inherited

Private Member Functions

void build_ ()
 This does the actual building.

Detailed Description

Definition at line 54 of file PLearnerOutputVMatrix.h.


Member Typedef Documentation

Reimplemented from PLearn::SourceVMatrix.

Definition at line 56 of file PLearnerOutputVMatrix.h.


Constructor & Destructor Documentation

PLearn::PLearnerOutputVMatrix::PLearnerOutputVMatrix ( bool  call_build_ = false)

Definition at line 50 of file PLearnerOutputVMatrix.cc.

References build_().

    :inherited(call_build_),
     put_raw_input(false),
     put_non_input(true),
     train_learners(false),
     compute_output_once(false)
    /* ### Initialize all fields to their default value */
{
    if( call_build_ )
        build_();
}

Here is the call graph for this function:

PLearn::PLearnerOutputVMatrix::PLearnerOutputVMatrix ( VMat  source_,
TVec< PP< PLearner > >  learners_,
bool  put_raw_input_ = false,
bool  train_learners_ = false,
bool  compute_output_once_ = false,
bool  put_non_input_ = true,
bool  call_build_ = true 
)

Definition at line 62 of file PLearnerOutputVMatrix.cc.

References build_().

    : inherited(source_, call_build_),
      learners(learners_),
      put_raw_input(put_raw_input_),
      put_non_input(put_non_input_),
      train_learners(train_learners_),
      compute_output_once(compute_output_once_)
{
    if( call_build_ )
        build_();
}

Here is the call graph for this function:

PLearn::PLearnerOutputVMatrix::PLearnerOutputVMatrix ( VMat  source_,
PP< PLearner learner,
bool  put_raw_input_ = false,
bool  train_learners_ = false,
bool  compute_output_once_ = false,
bool  put_non_input_ = true,
bool  call_build_ = true 
)

Definition at line 80 of file PLearnerOutputVMatrix.cc.

References build_(), learners, and PLearn::TVec< T >::resize().

    : inherited(source_, call_build_),
      put_raw_input(put_raw_input_),
      put_non_input(put_non_input_),
      train_learners(train_learners_),
      compute_output_once(compute_output_once_)
{
    learners.resize(1);
    learners[0] = learner;
    if( call_build_ )
        build_();
}

Here is the call graph for this function:


Member Function Documentation

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

Declares name and deepCopy methods.

Reimplemented from PLearn::SourceVMatrix.

Definition at line 123 of file PLearnerOutputVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 123 of file PLearnerOutputVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 123 of file PLearnerOutputVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 123 of file PLearnerOutputVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 123 of file PLearnerOutputVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 123 of file PLearnerOutputVMatrix.cc.

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

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 365 of file PLearnerOutputVMatrix.cc.

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

Here is the call graph for this function:

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

This does the actual building.

Reimplemented from PLearn::SourceVMatrix.

Definition at line 236 of file PLearnerOutputVMatrix.cc.

References PLearn::TVec< T >::append(), complete_learners_output, compute_output_once, data_train, PLearn::VMatrix::declareFieldNames(), PLearn::VMatrix::extrasize_, fieldinfos_source, i, PLearn::VMatrix::inputsize_, j, learner_input, learner_target, learners, learners_need_train, learners_output, PLearn::VMat::length(), PLearn::TVec< T >::length(), PLearn::VMatrix::length_, non_input_part_of_source_row, PLERROR, put_non_input, put_raw_input, PLearn::TVec< T >::resize(), row, PLearn::VMatrix::setFieldInfos(), PLearn::SourceVMatrix::source, PLearn::TVec< T >::subVec(), PLearn::VMatrix::targetsize_, train_learners, PLearn::VMatrix::updateMtime(), PLearn::VMatrix::weightsize_, PLearn::VMat::width(), and PLearn::VMatrix::width_.

Referenced by build(), and PLearnerOutputVMatrix().

{
    updateMtime(source);
        
    if (source && learners.length()>0 && learners[0])
    {
        learners_need_train = train_learners;
        row.resize(source->width());

        if (train_learners) {
            // Set the learners' training set.
            for (int i = 0; i < learners.length(); i++) {
                if (data_train)
                    learners[i]->setTrainingSet(data_train);
                else
                    learners[i]->setTrainingSet(source);
            }

            // Note that the learners will be train only if we actually
            // call getRow() or if compute_output_once is true
        }

        if(compute_output_once)
        {
            complete_learners_output.resize(learners.length());
            for (int i = 0; i < learners.length(); i++) {
                if(train_learners)
                {
                    PP<VecStatsCollector> stats = new VecStatsCollector();
                    learners[i]->setTrainStatsCollector(stats);
                    learners[i]->train();
                    stats->finalize();
                }
                complete_learners_output[i].resize(source->length(),
                                                   learners[i]->outputsize());
            }
            learners_need_train = false;

            Vec input_row = row.subVec(0,source->inputsize());

            for(int i=0; i<source->length();i++)
            {
                source->getRow(i,row);
                for (int j=0;j<learners.length();j++)
                {
                    Vec out_j = complete_learners_output[j](i);
                    learners[j]->computeOutput(input_row,out_j);
                }
            }
        }

        if (source->inputsize() < 0)
            PLERROR("In PLearnerOutputVMatrix::build_ - The 'source' matrix"
                    " has a negative inputsize");
        if (source->targetsize() < 0)
            PLERROR("In PLearnerOutputVMatrix::build_ - The 'source' matrix"
                    " has a negative targetsize");
        if (source->weightsize() < 0)
            PLERROR("In PLearnerOutputVMatrix::build_ - The 'source' matrix"
                    " has a negative weightsize");

        // Some further state variable initializations
        learner_input = row.subVec(0,source->inputsize());
        learner_target = row.subVec(source->inputsize(),source->targetsize());
        non_input_part_of_source_row =
            row.subVec(source->inputsize(),
                       source->width() - source->inputsize());
        learners_output.resize(learners->length());

        // Compute the total width of the VMatrix and the width of the various
        // components
        inputsize_ = 0;
        for (int i=0;i<learners->length();i++)
            inputsize_ += learners[i]->outputsize();
        if (put_raw_input)
            inputsize_ += source->inputsize();
        if (put_non_input) {
            targetsize_ = source->targetsize();
            weightsize_ = source->weightsize();
            extrasize_  = source->extrasize();
            width_ = inputsize_ + targetsize_ + weightsize_ + extrasize_;
        }
        else {
            targetsize_ = 0;
            weightsize_ = 0;
            width_ = inputsize_;
        }
        length_ = source->length();

        // Set field info.
        if (fieldinfos_source) 
            setFieldInfos(fieldinfos_source->getFieldInfos());
        else
        {
            TVec<string> fieldnames;
            for(int k=0; k<learners.length(); k++)
                fieldnames.append(learners[k]->getOutputNames());
            if(put_raw_input)
                fieldnames.append(source->inputFieldNames());
            if(put_non_input)
            {
                fieldnames.append(source->targetFieldNames());
                fieldnames.append(source->weightFieldNames());
                fieldnames.append(source->extraFieldNames());
            }
            declareFieldNames(fieldnames);
        }
        /* OLD CODE
        else {
            fieldinfos.resize(width_);
            if (put_non_input &&
                source->getFieldInfos().size() >= source->inputsize()
                                                    + source->targetsize())
            {
                // We can retrieve the information for the target columns.
                for (int i = 0; i < source->targetsize(); i++) 
                {
                    fieldinfos[i + this->inputsize()] =
                        source->getFieldInfos()[i + source->inputsize()];
                }
            }
        }
        */
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 123 of file PLearnerOutputVMatrix.cc.

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

Declares this class' options.

Reimplemented from PLearn::SourceVMatrix.

Definition at line 178 of file PLearnerOutputVMatrix.cc.

References PLearn::OptionBase::buildoption, compute_output_once, data_train, PLearn::declareOption(), PLearn::SourceVMatrix::declareOptions(), fieldinfos_source, learners, PLearn::OptionBase::learntoption, PLearn::OptionBase::nosave, put_non_input, put_raw_input, PLearn::SourceVMatrix::source, and train_learners.

{
    // ### 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

    declareOption(ol, "data", &PLearnerOutputVMatrix::source,
                  (OptionBase::learntoption | OptionBase::nosave),
                  "DEPRECATED - Use 'source' instead.");

    declareOption(ol, "learners", &PLearnerOutputVMatrix::learners,
                  OptionBase::buildoption,
                  "The vector of PLearners which will be applied to 'source'"
                  " data set.");

    declareOption(ol, "put_raw_input", &PLearnerOutputVMatrix::put_raw_input,
                  OptionBase::buildoption,
                  "Whether to include in the input part of this VMatrix the"
                  " raw input part\n"
                  "of 'source'.\n");

    declareOption(ol, "put_non_input", &PLearnerOutputVMatrix::put_non_input,
                  OptionBase::buildoption,
                  "Whether to include in this VMatrix the original target and"
                  " weights.");

    declareOption(ol, "train_learners", &PLearnerOutputVMatrix::train_learners,
                  OptionBase::buildoption,
                  "If set to 1, the learners will be train on 'source' (or"
                  " 'data_train' if present)\n"
                  "before computing the output.\n");

    declareOption(ol, "data_train", &PLearnerOutputVMatrix::data_train,
                  OptionBase::buildoption,
                  "If provided and 'train_learners' is set to 1, the learner"
                  " will be trained\n"
                  "on this dataset.\n");

    declareOption(ol, "compute_output_once",
                  &PLearnerOutputVMatrix::compute_output_once,
                  OptionBase::buildoption,
                  "If set to 1, the output of the learners will be computed"
                  " once and stored");

    declareOption(ol, "fieldinfos_source",
                  &PLearnerOutputVMatrix::fieldinfos_source,
                  OptionBase::buildoption,
                  "If provided, the fieldnames will be copied from this VMat.");

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

Here is the call graph for this function:

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 144 of file PLearnerOutputVMatrix.h.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 123 of file PLearnerOutputVMatrix.cc.

void PLearn::PLearnerOutputVMatrix::getNewRow ( int  i,
const Vec v 
) const [protected, virtual]

This is the only method requiring implementation.

Reimplemented from PLearn::SourceVMatrix.

Definition at line 125 of file PLearnerOutputVMatrix.cc.

References c, complete_learners_output, compute_output_once, i, j, learner_input, learners, learners_need_train, learners_output, PLearn::TVec< T >::length(), non_input_part_of_source_row, put_non_input, put_raw_input, PLearn::TVec< T >::resize(), row, PLearn::SourceVMatrix::source, and PLearn::TVec< T >::subVec().

{
    int c=0;
    if (learners_need_train) {
        // We need to train the learners first.
        for (int k = 0; k < learners.length(); k++)
        {
            PP<VecStatsCollector> stats = new VecStatsCollector();
            learners[k]->setTrainStatsCollector(stats);
            learners[k]->train();
            stats->finalize();
        }
        learners_need_train = false;
    }
    source->getRow(i,row);

    if(compute_output_once)  {
        // Use precomputed outputs
        for (int j=0;j<learners.length();j++)
        {
            v.subVec(c,learners[j]->outputsize())
                << complete_learners_output[j](i);
            c += learners[j]->outputsize();
        }
    }

    else {
        // Compute output for each learner; now allow each learner to have a
        // different outputsize.  The variable 'learners_output' is kept for
        // backwards compatibility, but is no longer strictly necessary
        for (int j=0;j<learners.length();j++)
        {
            int cur_outputsize = learners[j]->outputsize();
            learners_output[j].resize(cur_outputsize);
            learners[j]->computeOutput(learner_input, learners_output[j]);
            v.subVec(c, cur_outputsize) << learners_output[j];
            c += cur_outputsize;
        }
    }

    if (put_raw_input)
    {
        v.subVec(c,learner_input->length()) << learner_input;
        c+=learner_input->length();
    }
    if (put_non_input)
        v.subVec(c,non_input_part_of_source_row.length())
            << non_input_part_of_source_row;
}

Here is the call graph for this function:

OptionList & PLearn::PLearnerOutputVMatrix::getOptionList ( ) const [virtual]

Reimplemented from PLearn::SourceVMatrix.

Definition at line 123 of file PLearnerOutputVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 123 of file PLearnerOutputVMatrix.cc.

RemoteMethodMap & PLearn::PLearnerOutputVMatrix::getRemoteMethodMap ( ) const [virtual]

Reimplemented from PLearn::SourceVMatrix.

Definition at line 123 of file PLearnerOutputVMatrix.cc.

void PLearn::PLearnerOutputVMatrix::makeDeepCopyFromShallowCopy ( CopiesMap copies) [virtual]

Member Data Documentation

Reimplemented from PLearn::SourceVMatrix.

Definition at line 144 of file PLearnerOutputVMatrix.h.

Definition at line 73 of file PLearnerOutputVMatrix.h.

Referenced by build_(), getNewRow(), and makeDeepCopyFromShallowCopy().

Definition at line 95 of file PLearnerOutputVMatrix.h.

Referenced by build_(), declareOptions(), and getNewRow().

Definition at line 85 of file PLearnerOutputVMatrix.h.

Referenced by build_(), declareOptions(), and makeDeepCopyFromShallowCopy().

Definition at line 81 of file PLearnerOutputVMatrix.h.

Referenced by build_(), and declareOptions().

Definition at line 66 of file PLearnerOutputVMatrix.h.

Referenced by build_(), getNewRow(), and makeDeepCopyFromShallowCopy().

Definition at line 69 of file PLearnerOutputVMatrix.h.

Referenced by build_(), and makeDeepCopyFromShallowCopy().

Used to keep track of whether learners need training or not.

Definition at line 72 of file PLearnerOutputVMatrix.h.

Referenced by build_(), and getNewRow().

Instead of Mat to allow learners of various outputsizes.

Definition at line 68 of file PLearnerOutputVMatrix.h.

Referenced by build_(), getNewRow(), and makeDeepCopyFromShallowCopy().

Definition at line 70 of file PLearnerOutputVMatrix.h.

Referenced by build_(), getNewRow(), and makeDeepCopyFromShallowCopy().

Definition at line 93 of file PLearnerOutputVMatrix.h.

Referenced by build_(), declareOptions(), and getNewRow().

Definition at line 92 of file PLearnerOutputVMatrix.h.

Referenced by build_(), declareOptions(), and getNewRow().

Definition at line 65 of file PLearnerOutputVMatrix.h.

Referenced by build_(), getNewRow(), and makeDeepCopyFromShallowCopy().

Definition at line 94 of file PLearnerOutputVMatrix.h.

Referenced by build_(), and declareOptions().


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