PLearn 0.1
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | Friends
PLearn::RegressionTree Class Reference

#include <RegressionTree.h>

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

List of all members.

Public Member Functions

 RegressionTree ()
virtual ~RegressionTree ()
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual RegressionTreedeepCopy (CopiesMap &copies) const
virtual void makeDeepCopyFromShallowCopy (CopiesMap &copies)
 Transforms a shallow copy into a deep copy.
virtual void build ()
 Finish building the object; just call inherited::build followed by build_()
virtual void train ()
 *** SUBCLASS WRITING: ***
virtual void finalize ()
 *** SUBCLASS WRITING: ***
virtual void forget ()
 *** SUBCLASS WRITING: ***
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 TVec< string > getTrainCostNames () const
 *** SUBCLASS WRITING: ***
virtual TVec< string > getTestCostNames () const
 *** SUBCLASS WRITING: ***
virtual TVec< string > getOutputNames () const
 Returns a vector of length outputsize() containing the outputs' names.
PP< RegressionTreeRegistersgetSortedTrainingSet () const
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 computeOutputAndNodes (const Vec &input, Vec &output, TVec< PP< RegressionTreeNode > > *nodes=0) const
virtual void computeCostsFromOutputs (const Vec &input, const Vec &output, const Vec &target, Vec &costs) const
 *** SUBCLASS WRITING: ***
virtual void computeCostsFromOutputsAndNodes (const Vec &input, const Vec &output, const Vec &target, const TVec< PP< RegressionTreeNode > > &nodes, Vec &costs) const

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 ()
static void declareOptions (OptionList &ol)
 Declares this class' options.

Static Public Attributes

static StaticInitializer _static_initializer_

Private Types

typedef PLearner inherited

Private Member Functions

void build_ ()
 **** SUBCLASS WRITING: ****
void initialiseTree ()
PP< RegressionTreeNodeexpandTree ()
void verbose (string msg, int level)

Private Attributes

bool missing_is_valid
real loss_function_weight
int maximum_number_of_nodes
int compute_train_stats
real complexity_penalty_factor
Vec multiclass_outputs
PP< RegressionTreeLeaveleave_template
PP< RegressionTreeRegisterssorted_train_set
PP< RegressionTreeNoderoot
PP< RegressionTreeLeavefirst_leave
PP< RegressionTreeQueuepriority_queue
int length
real l2_loss_function_factor
real l1_loss_function_factor
TVec< intsplit_cols
Vec split_values
TVec< PP< RegressionTreeNode > > * nodes
Vec tmp_vec
Vec tmp_computeCostsFromOutput

Static Private Attributes

static bool output_confidence_target = false

Friends

class RegressionTreeNode

Detailed Description

Definition at line 55 of file RegressionTree.h.


Member Typedef Documentation

Reimplemented from PLearn::PLearner.

Definition at line 58 of file RegressionTree.h.


Constructor & Destructor Documentation

PLearn::RegressionTree::RegressionTree ( )
PLearn::RegressionTree::~RegressionTree ( ) [virtual]

Definition at line 75 of file RegressionTree.cc.

{
}

Member Function Documentation

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

Reimplemented from PLearn::PLearner.

Definition at line 62 of file RegressionTree.cc.

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

Reimplemented from PLearn::PLearner.

Definition at line 62 of file RegressionTree.cc.

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

Reimplemented from PLearn::PLearner.

Definition at line 62 of file RegressionTree.cc.

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

Reimplemented from PLearn::PLearner.

Definition at line 62 of file RegressionTree.cc.

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

Reimplemented from PLearn::Object.

Definition at line 62 of file RegressionTree.cc.

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

Reimplemented from PLearn::PLearner.

Definition at line 62 of file RegressionTree.cc.

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

Finish building the object; just call inherited::build followed by build_()

Reimplemented from PLearn::PLearner.

Definition at line 156 of file RegressionTree.cc.

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

Here is the call graph for this function:

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

**** SUBCLASS WRITING: ****

This method should finish building of the object, according to set 'options', in *any* situation.

Typical situations include:

  • Initial building of an object from a few user-specified options
  • Building of a "reloaded" object: i.e. from the complete set of all serialised options.
  • Updating or "re-building" of an object after a few "tuning" options (such as hyper-parameters) have been modified.

You can assume that the parent class' build_() has already been called.

A typical build method will want to know the inputsize(), targetsize() and outputsize(), and may also want to check whether train_set->hasWeights(). All these methods require a train_set to be set, so the first thing you may want to do, is check if(train_set), before doing any heavy building...

Note: build() is always called by setTrainingSet.

Reimplemented from PLearn::PLearner.

Definition at line 162 of file RegressionTree.cc.

References PLearn::PLearner::inputsize(), l1_loss_function_factor, l2_loss_function_factor, length, loss_function_weight, max, maximum_number_of_nodes, nodes, outputsize(), PLCHECK, PLERROR, PLearn::pow(), PLearn::TVec< T >::resize(), sorted_train_set, PLearn::PLearner::targetsize(), tmp_computeCostsFromOutput, PLearn::PLearner::train_set, and PLearn::PLearner::weightsize().

Referenced by build().

{
    PLCHECK(maximum_number_of_nodes<=std::numeric_limits<RTR_type_id>::max());

    PP<VMatrix> the_train_set;
    if(sorted_train_set)
    {
        the_train_set = sorted_train_set;
    }
    else if (train_set)
    { 
        the_train_set = train_set;
    }
    if(the_train_set)
    {
        length = the_train_set->length();
        int inputsize = the_train_set->inputsize();
        int targetsize = the_train_set->targetsize();
        int weightsize = the_train_set->weightsize();

        if (length < 1)
            PLERROR("RegressionTree: the training set must contain at least one"
                    " sample, got %d", length);
        if (inputsize < 1)
            PLERROR("RegressionTree: expected  inputsize greater than 0, got %d",
                    inputsize);
        if (targetsize != 1)
            PLERROR("RegressionTree: expected targetsize to be 1,"" got %d",
                    targetsize);
        if (weightsize != 1 && weightsize != 0)
            PLERROR("RegressionTree: expected weightsize to be 1 or 0, got %d",
                    weightsize);
    }

    nodes = new TVec<PP<RegressionTreeNode> >();
    tmp_computeCostsFromOutput.resize(outputsize());
    
    if (loss_function_weight != 0.0)
    {
        l2_loss_function_factor = 2.0 / pow(loss_function_weight, 2);
        l1_loss_function_factor = 2.0 / loss_function_weight;
    }
    else
    {
        l2_loss_function_factor = 1.0;
        l1_loss_function_factor = 1.0;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 62 of file RegressionTree.cc.

void PLearn::RegressionTree::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 446 of file RegressionTree.cc.

References computeOutputAndCosts(), PLASSERT, and tmp_computeCostsFromOutput.

Here is the call graph for this function:

void PLearn::RegressionTree::computeCostsFromOutputsAndNodes ( const Vec input,
const Vec output,
const Vec target,
const TVec< PP< RegressionTreeNode > > &  nodes,
Vec costs 
) const [virtual]

Definition at line 428 of file RegressionTree.cc.

References PLearn::abs(), PLearn::TVec< T >::clear(), PLearn::fast_is_equal(), i, l1_loss_function_factor, l2_loss_function_factor, leave_template, PLearn::TVec< T >::length(), MISSING_VALUE, nodes, and PLearn::pow().

Referenced by computeOutputAndCosts().

{
    costs.clear();
    costs[0] = pow((output[0] - target[0]), 2);
    if(leave_template->output_confidence_target) costs[1] = output[1];
    else costs[1] = MISSING_VALUE;
    costs[2] = 1.0 - (l2_loss_function_factor * costs[0]);
    costs[3] = 1.0 - (l1_loss_function_factor * abs(output[0] - target[0]));
    costs[4] = !fast_is_equal(target[0],output[0]);

    for(int i=0;i<nodes.length();i++)
        costs[5+nodes[i]->getSplitCol()]++;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void PLearn::RegressionTree::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 403 of file RegressionTree.cc.

References computeOutputAndNodes().

{
    computeOutputAndNodes(inputv, outputv);
}

Here is the call graph for this function:

void PLearn::RegressionTree::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 415 of file RegressionTree.cc.

References computeCostsFromOutputsAndNodes(), computeOutputAndNodes(), nodes, PLearn::PLearner::nTestCosts(), PLASSERT, PLearn::TVec< T >::resize(), and PLearn::TVec< T >::size().

Referenced by computeCostsFromOutputs(), and train().

{
    PLASSERT(costs.size()==nTestCosts());
    PLASSERT(nodes);
    nodes->resize(0);

    computeOutputAndNodes(input, output, nodes);

    computeCostsFromOutputsAndNodes(input, output, target, *nodes, costs);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void PLearn::RegressionTree::computeOutputAndNodes ( const Vec input,
Vec output,
TVec< PP< RegressionTreeNode > > *  nodes = 0 
) const [virtual]

Definition at line 408 of file RegressionTree.cc.

References nodes, and root.

Referenced by computeOutput(), and computeOutputAndCosts().

{
    root->computeOutputAndNodes(inputv, outputv, nodes);
    return;
}

Here is the caller graph for this function:

void PLearn::RegressionTree::declareOptions ( OptionList ol) [static]

Declares this class' options.

Reimplemented from PLearn::PLearner.

Definition at line 79 of file RegressionTree.cc.

References PLearn::OptionBase::buildoption, complexity_penalty_factor, compute_train_stats, PLearn::declareOption(), PLearn::PLearner::declareOptions(), PLearn::declareStaticOption(), first_leave, PLearn::OptionBase::learntoption, leave_template, loss_function_weight, maximum_number_of_nodes, missing_is_valid, multiclass_outputs, PLearn::OptionBase::nosave, output_confidence_target, priority_queue, root, sorted_train_set, split_cols, split_values, and tmp_vec.

{ 
    declareOption(ol, "missing_is_valid", &RegressionTree::missing_is_valid, OptionBase::buildoption,
                  "If set to 1, missing values will be treated as valid, and missing nodes will be potential for splits.\n");
    declareOption(ol, "loss_function_weight", &RegressionTree::loss_function_weight, OptionBase::buildoption,
                  "The hyper parameter to balance the error and the confidence factor.\n");
    declareOption(ol, "maximum_number_of_nodes", &RegressionTree::maximum_number_of_nodes, OptionBase::buildoption,
                  "The maximum number of nodes for this tree.\n"
                  "(If less than nstages, nstages will be used).");
    declareOption(ol, "compute_train_stats", &RegressionTree::compute_train_stats, OptionBase::buildoption,
                  "If set to 1 (the default value) the train statistics are computed.\n"
                  "(When using the tree as a base regressor, we dont need the stats and it goes quicker when computations are suppressed).");
    declareOption(ol, "complexity_penalty_factor", &RegressionTree::complexity_penalty_factor, OptionBase::buildoption,
                  "A factor that is multiplied with the square root of the number of leaves.\n"
                  "If the error inprovement for the next split is less than the result, the algorithm proceed to an early stop."
                  "(When set to 0.0, the default value, it has no impact).");

    declareStaticOption(ol, "output_confidence_target",
                  &RegressionTree::output_confidence_target,
                  OptionBase::buildoption,
                  "to reload old learner.");

    declareOption(ol, "multiclass_outputs", &RegressionTree::multiclass_outputs, OptionBase::buildoption,
                  "A vector of possible output values when solving a multiclass problem.\n"
                  "When making a prediction, the tree will adjust the output value of each leave to the closest value provided in this vector.");
    declareOption(ol, "leave_template", &RegressionTree::leave_template, OptionBase::buildoption,
                  "The template for the leave objects to create.\n");
    declareOption(ol, "sorted_train_set", &RegressionTree::sorted_train_set,
                  OptionBase::buildoption | OptionBase::nosave, 
                  "The train set sorted on all columns. If it is not provided by a\n"
                  " wrapping algorithm, it is created at stage 0.\n");
      
    declareOption(ol, "root", &RegressionTree::root, OptionBase::learntoption,
                  "The root node of the tree being built\n");
    declareOption(ol, "priority_queue", &RegressionTree::priority_queue, OptionBase::learntoption,
                  "The heap to store potential nodes to expand\n");
    declareOption(ol, "first_leave", &RegressionTree::first_leave, OptionBase::learntoption,
                  "The first leave built with the root containing all train set rows at the beginning\n");
    declareOption(ol, "split_cols", &RegressionTree::split_cols,
                  OptionBase::learntoption,
                  "Contain in order of addition of node the columns used to"
                  " split the tree.\n");
    declareOption(ol, "split_values", &RegressionTree::split_values,
                  OptionBase::learntoption,
                  "Contain in order of addition of node the split value.\n");

    declareOption(ol, "first_leave_output", &RegressionTree::tmp_vec,
                  OptionBase::learntoption | OptionBase::nosave,
                  "DEPRECATED\n");
    declareOption(ol, "first_leave_error", &RegressionTree::tmp_vec,
                  OptionBase::learntoption | OptionBase::nosave,
                  "DEPRECATED\n");


    inherited::declareOptions(ol);
}

Here is the call graph for this function:

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

Reimplemented from PLearn::PLearner.

Definition at line 101 of file RegressionTree.h.

{return leave_template->outputsize();}
RegressionTree * PLearn::RegressionTree::deepCopy ( CopiesMap copies) const [virtual]

Reimplemented from PLearn::PLearner.

Definition at line 62 of file RegressionTree.cc.

PP< RegressionTreeNode > PLearn::RegressionTree::expandTree ( ) [private]

Definition at line 338 of file RegressionTree.cc.

References complexity_penalty_factor, missing_is_valid, priority_queue, PLearn::sqrt(), PLearn::PLearner::stage, PLearn::tostring(), and verbose().

Referenced by train().

{
    if (priority_queue->isEmpty() <= 0)
    {
        verbose("RegressionTree: priority queue empty, stage: " + tostring(stage), 3);
        return NULL;
    }
    PP<RegressionTreeNode> node = priority_queue->popHeap();
    if (node->getErrorImprovment() < complexity_penalty_factor * sqrt((real)stage))
    {
        verbose("RegressionTree: early stopping at stage: " + tostring(stage)
                + ", error improvement: " + tostring(node->getErrorImprovment())
                + ", penalty: " + tostring(complexity_penalty_factor * sqrt((real)stage)), 3);
        return NULL;
    }
    int split_col = node->expandNode();
    if (split_col < 0)
    {
        verbose("RegressionTree: expand is negative?", 3);
        return NULL;
    }

    priority_queue->addHeap(node->left_node); 
    priority_queue->addHeap(node->right_node);
    if (missing_is_valid) priority_queue->addHeap(node->missing_node);
    return node; 
}

Here is the call graph for this function:

Here is the caller graph for this function:

void PLearn::RegressionTree::finalize ( ) [virtual]

*** SUBCLASS WRITING: ***

When this method is called the learner know it we will never train it again. So it can free resources that are needed only during the training. The functions test()/computeOutputs()/... should continue to work.

Reimplemented from PLearn::PLearner.

Definition at line 275 of file RegressionTree.cc.

References PLearn::PLearner::finalize(), first_leave, priority_queue, root, split_cols, and split_values.

{
    inherited::finalize();
    root->finalize();
    priority_queue = 0;
    split_cols = TVec<int>();
    split_values = Vec();
//    leave_template = 0; we need it to reload a saved learner.
    first_leave = 0;
    //we should not finalize the train_set and the sorted_train_set here 
    //as AdaBoost share it between different weak_learners!
    //AdaBoost will finalize.
//    if(sorted_train_set)
//        sorted_train_set->finalize();
//    if(train_set->classname()=="RegressionTreeRegisters")
//        ((PP<RegressionTreeRegisters>)train_set)->finalize();
}

Here is the call graph for this function:

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

*** SUBCLASS WRITING: ***

(Re-)initializes the PLearner in its fresh state (that state may depend on the 'seed' option) and sets 'stage' back to 0 (this is the stage of a fresh learner!)

A typical forget() method should do the following:

  • initialize the learner's parameters, using this random generator
  • stage = 0;

This method is typically called by the build_() method, after it has finished setting up the parameters, and if it deemed useful to set or reset the learner in its fresh state. (remember build may be called after modifying options that do not necessarily require the learner to restart from a fresh state...) forget is also called by the setTrainingSet method, after calling build(), so it will generally be called TWICE during setTrainingSet!

Reimplemented from PLearn::PLearner.

Definition at line 293 of file RegressionTree.cc.

References PLearn::PLearner::stage.

{
    stage = 0;
}
OptionList & PLearn::RegressionTree::getOptionList ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 62 of file RegressionTree.cc.

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

Reimplemented from PLearn::Object.

Definition at line 62 of file RegressionTree.cc.

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

Returns a vector of length outputsize() containing the outputs' names.

Default version returns ["out0", "out1", ...] Don't forget name should not have space or it will cause trouble when they are saved in the file {metadatadir}/fieldnames

Reimplemented from PLearn::PLearner.

Definition at line 393 of file RegressionTree.cc.

References leave_template.

{
    return leave_template->getOutputNames();
}
RemoteMethodMap & PLearn::RegressionTree::getRemoteMethodMap ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 62 of file RegressionTree.cc.

PP< RegressionTreeRegisters > PLearn::RegressionTree::getSortedTrainingSet ( ) const

Definition at line 398 of file RegressionTree.cc.

References sorted_train_set.

{
    return sorted_train_set;
}
TVec< string > PLearn::RegressionTree::getTestCostNames ( ) const [virtual]

*** SUBCLASS WRITING: ***

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

Implements PLearn::PLearner.

Definition at line 377 of file RegressionTree.cc.

References PLearn::TVec< T >::append(), getTrainCostNames(), i, PLCHECK_MSG, sorted_train_set, and PLearn::PLearner::train_set.

{ 
    TVec<string> costs=getTrainCostNames();
    PP<VMatrix> the_train_set=train_set;
    if(sorted_train_set)
        the_train_set = sorted_train_set;

    PLCHECK_MSG(the_train_set,"In RegressionTree::getTestCostNames() - "
                "a train set is needed!");
    for(int i=0;i<the_train_set->inputsize();i++)
    {
        costs.append("SPLIT_VAR_"+the_train_set->fieldName(i));
    }
    return costs;
}

Here is the call graph for this function:

TVec< string > PLearn::RegressionTree::getTrainCostNames ( ) const [virtual]

*** SUBCLASS WRITING: ***

This should return the names of the objective costs that the train method computes and for which it updates the VecStatsCollector train_stats.

Implements PLearn::PLearner.

Definition at line 366 of file RegressionTree.cc.

Referenced by getTestCostNames().

{
    TVec<string> return_msg(5);
    return_msg[0] = "mse";
    return_msg[1] = "base_confidence";
    return_msg[2] = "base_reward_l2";
    return_msg[3] = "base_reward_l1";
    return_msg[4] = "class_error";
    return return_msg;
}

Here is the caller graph for this function:

void PLearn::RegressionTree::initialiseTree ( ) [private]

Definition at line 298 of file RegressionTree.cc.

References PLearn::deepCopy(), first_leave, leave_template, length, loss_function_weight, maximum_number_of_nodes, missing_is_valid, PLearn::PLearner::nstages, priority_queue, RegressionTreeNode, PLearn::PLearner::report_progress, root, sorted_train_set, PLearn::PLearner::train_set, and PLearn::PLearner::verbosity.

Referenced by train().

{
    if (!sorted_train_set && train_set->classname()=="RegressionTreeRegisters")
    {
        sorted_train_set=(PP<RegressionTreeRegisters>)train_set;
        sorted_train_set->reinitRegisters();
    }
    else if(!sorted_train_set)
        sorted_train_set = new RegressionTreeRegisters(train_set,
                                                       report_progress,
                                                       verbosity);
    else
    {
        sorted_train_set->reinitRegisters();
    }
    //Set value common value of all leave
    // for optimisation, by default they aren't missing leave
    leave_template->missing_leave = 0;
    leave_template->loss_function_weight = loss_function_weight;
    leave_template->verbosity = verbosity;
    leave_template->initStats();

    first_leave = ::PLearn::deepCopy(leave_template);
    first_leave->initLeave(sorted_train_set, sorted_train_set->getNextId());

    for (int train_sample_index = 0; train_sample_index < length;
         train_sample_index++)
    {
        first_leave->addRow(train_sample_index);
        first_leave->registerRow(train_sample_index);
    }
    root = new RegressionTreeNode(missing_is_valid);
    root->initNode(this, first_leave);
    root->lookForBestSplit();

    if (maximum_number_of_nodes < nstages) maximum_number_of_nodes = nstages;
    priority_queue = new RegressionTreeQueue(verbosity,maximum_number_of_nodes);
    priority_queue->addHeap(root);
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::PLearner.

Definition at line 136 of file RegressionTree.cc.

References complexity_penalty_factor, compute_train_stats, PLearn::deepCopyField(), first_leave, loss_function_weight, PLearn::PLearner::makeDeepCopyFromShallowCopy(), maximum_number_of_nodes, missing_is_valid, multiclass_outputs, priority_queue, root, sorted_train_set, split_cols, and split_values.

{
    inherited::makeDeepCopyFromShallowCopy(copies);
    deepCopyField(missing_is_valid, copies);
    deepCopyField(loss_function_weight, copies);
    deepCopyField(maximum_number_of_nodes, copies);
    deepCopyField(compute_train_stats, copies);
    deepCopyField(complexity_penalty_factor, copies);
    deepCopyField(multiclass_outputs, copies);
//    deepCopyField(leave_template, copies);We don't need to deepCopy it as we only read it
    deepCopyField(sorted_train_set, copies);
    deepCopyField(root, copies);
    deepCopyField(priority_queue, copies);
    deepCopyField(first_leave, copies);
    deepCopyField(split_cols, copies);
    deepCopyField(split_values, copies);
    //deepCopyField(tmp_vec, copies); not needed as we don't use it.
    
}

Here is the call graph for this function:

virtual int PLearn::RegressionTree::outputsize ( ) const [inline, 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 109 of file RegressionTree.h.

Referenced by build_(), and train().

{return leave_template->outputsize();}

Here is the caller graph for this function:

void PLearn::RegressionTree::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 211 of file RegressionTree.cc.

References PLearn::TVec< T >::append(), compute_train_stats, computeOutputAndCosts(), expandTree(), initialiseTree(), length, max, missing_is_valid, PLearn::PLearner::nstages, PLearn::PLearner::nTestCosts(), outputsize(), PLearn::Profiler::pl_profile_end(), PLearn::Profiler::pl_profile_start(), PLERROR, PLearn::PLearner::report_progress, sorted_train_set, split_cols, split_values, PLearn::PLearner::stage, PLearn::tostring(), PLearn::PLearner::train_stats, and verbose().

{
    Profiler::pl_profile_start("RegressionTree::train");

    if(std::numeric_limits<RTR_type_id>::max() < nstages*(missing_is_valid?9:6))
        PLERROR("The type of RTR_type_id(%s) doesn't have enought capacity","RTR_type_id");

    if (stage == 0) initialiseTree();
    PP<ProgressBar> pb;
    if (report_progress)
    {
        pb = new ProgressBar("RegressionTree : train stages: ", nstages);
    }
    for (; stage < nstages; stage++)
    {    
        if (stage > 0)
        {
            PP<RegressionTreeNode> node= expandTree();
            if (node == NULL) break;
            split_cols.append(node->getSplitCol());
            split_values.append(node->getSplitValue());
        }
        if (report_progress) pb->update(stage);
    }
    pb = NULL;
#ifndef _OPENMP
    verbose("split_cols: "+tostring(split_cols),2);
    verbose("split_values: "+tostring(split_values),2);
#endif
    if (compute_train_stats < 1){
        Profiler::pl_profile_end("RegressionTree::train");
        return;
    }
    if (report_progress)
    {
        pb = new ProgressBar("RegressionTree : computing the statistics: ", length);
    } 
    train_stats->forget();

    real sample_weight;
    Vec sample_input(sorted_train_set->inputsize());
    Vec sample_output(outputsize());
    Vec sample_target(sorted_train_set->targetsize());
    Vec sample_costs(nTestCosts());

    for (int train_sample_index = 0; train_sample_index < length;
         train_sample_index++)
    {  
        sorted_train_set->getExample(train_sample_index, sample_input, sample_target, sample_weight);
        computeOutputAndCosts(sample_input,sample_target,sample_output,sample_costs);
        train_stats->update(sample_costs);
        if (report_progress) pb->update(train_sample_index);
    }
    train_stats->finalize();

    Profiler::pl_profile_end("RegressionTree::train");
}

Here is the call graph for this function:

void PLearn::RegressionTree::verbose ( string  msg,
int  level 
) [private]

Definition at line 269 of file RegressionTree.cc.

References PLearn::endl(), PLearn::pout, and PLearn::PLearner::verbosity.

Referenced by expandTree(), and train().

{
    if (verbosity >= the_level)
        pout << the_msg << endl;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class RegressionTreeNode [friend]

Definition at line 57 of file RegressionTree.h.

Referenced by initialiseTree().


Member Data Documentation

Reimplemented from PLearn::PLearner.

Definition at line 101 of file RegressionTree.h.

Definition at line 70 of file RegressionTree.h.

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

Definition at line 69 of file RegressionTree.h.

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

Definition at line 89 of file RegressionTree.h.

Referenced by build_(), and computeCostsFromOutputsAndNodes().

Definition at line 88 of file RegressionTree.h.

Referenced by build_(), and computeCostsFromOutputsAndNodes().

Definition at line 87 of file RegressionTree.h.

Referenced by build_(), initialiseTree(), and train().

Definition at line 71 of file RegressionTree.h.

Referenced by declareOptions(), and makeDeepCopyFromShallowCopy().

Definition at line 74 of file RegressionTree.h.

Referenced by declareOptions().

Definition at line 90 of file RegressionTree.h.

Referenced by declareOptions(), finalize(), makeDeepCopyFromShallowCopy(), and train().

Definition at line 91 of file RegressionTree.h.

Referenced by declareOptions(), finalize(), makeDeepCopyFromShallowCopy(), and train().

Definition at line 95 of file RegressionTree.h.

Referenced by build_(), and computeCostsFromOutputs().

Definition at line 94 of file RegressionTree.h.

Referenced by declareOptions().


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