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

#include <RegressionTreeMulticlassLeaveProb.h>

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

List of all members.

Public Member Functions

 RegressionTreeMulticlassLeaveProb ()
virtual ~RegressionTreeMulticlassLeaveProb ()
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual
RegressionTreeMulticlassLeaveProb
deepCopy (CopiesMap &copies) const
virtual void makeDeepCopyFromShallowCopy (CopiesMap &copies)
 Does the necessary operations to transform a shallow copy (this) into a deep copy by deep-copying all the members that need to be.
virtual void build ()
 Post-constructor.
virtual int outputsize () const
void initStats ()
void addRow (int row)
void addRow (int row, real target, real weight)
void addRow (int row, Vec outputv, Vec errorv)
void addRow (int row, real target, real weight, Vec outputv, Vec errorv)
void removeRow (int row, real target, real weight)
void removeRow (int row, Vec outputv, Vec errorv)
void removeRow (int row, real target, real weight, Vec outputv, Vec errorv)
void getOutputAndError (Vec &output, Vec &error) const
TVec< string > getOutputNames () const
void printStats ()
virtual void addLeave (PP< RegressionTreeLeave > leave)
virtual void removeLeave (PP< RegressionTreeLeave > leave)

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)
 Declare options (data fields) for the class.

Static Public Attributes

static StaticInitializer _static_initializer_

Private Types

typedef RegressionTreeLeave inherited

Private Member Functions

void build_ ()
 Object-specific post-constructor.

Private Attributes

int nb_class
string objective_function
Vec multiclass_weights_sum

Detailed Description

Definition at line 50 of file RegressionTreeMulticlassLeaveProb.h.


Member Typedef Documentation

Reimplemented from PLearn::RegressionTreeLeave.

Definition at line 52 of file RegressionTreeMulticlassLeaveProb.h.


Constructor & Destructor Documentation

PLearn::RegressionTreeMulticlassLeaveProb::RegressionTreeMulticlassLeaveProb ( )

Definition at line 55 of file RegressionTreeMulticlassLeaveProb.cc.

References build().

    : nb_class(-1),
      objective_function("l1")
{
    build();
}

Here is the call graph for this function:

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

Definition at line 62 of file RegressionTreeMulticlassLeaveProb.cc.

{
}

Member Function Documentation

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

Reimplemented from PLearn::RegressionTreeLeave.

Definition at line 53 of file RegressionTreeMulticlassLeaveProb.cc.

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

Reimplemented from PLearn::RegressionTreeLeave.

Definition at line 53 of file RegressionTreeMulticlassLeaveProb.cc.

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

Reimplemented from PLearn::RegressionTreeLeave.

Definition at line 53 of file RegressionTreeMulticlassLeaveProb.cc.

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

Reimplemented from PLearn::RegressionTreeLeave.

Definition at line 53 of file RegressionTreeMulticlassLeaveProb.cc.

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

Reimplemented from PLearn::RegressionTreeLeave.

Definition at line 53 of file RegressionTreeMulticlassLeaveProb.cc.

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

Reimplemented from PLearn::RegressionTreeLeave.

Definition at line 53 of file RegressionTreeMulticlassLeaveProb.cc.

void PLearn::RegressionTreeMulticlassLeaveProb::addLeave ( PP< RegressionTreeLeave leave) [virtual]

Reimplemented from PLearn::RegressionTreeLeave.

Definition at line 248 of file RegressionTreeMulticlassLeaveProb.cc.

References classname(), PLearn::RegressionTreeLeave::length_, multiclass_weights_sum, PLERROR, and PLearn::RegressionTreeLeave::weights_sum.

                                                                              {
    PP<RegressionTreeMulticlassLeaveProb> leave = (PP<RegressionTreeMulticlassLeaveProb>) leave_;

    if(leave->classname() == classname()){
        length_ += leave->length_;
        weights_sum += leave->weights_sum;
        multiclass_weights_sum += leave->multiclass_weights_sum;
    }else
        PLERROR("In %s::addLeave the leave to add should have the same class. It have %s.",
                classname().c_str(), leave->classname().c_str());
}

Here is the call graph for this function:

void PLearn::RegressionTreeMulticlassLeaveProb::addRow ( int  row) [virtual]

Reimplemented from PLearn::RegressionTreeLeave.

Definition at line 129 of file RegressionTreeMulticlassLeaveProb.cc.

References PLearn::RegressionTreeLeave::train_set.

Referenced by addRow().

{
    real weight = train_set->getWeight(row);
    real target = train_set->getTarget(row);
    RegressionTreeMulticlassLeaveProb::addRow(row, target, weight);
}

Here is the caller graph for this function:

void PLearn::RegressionTreeMulticlassLeaveProb::addRow ( int  row,
real  target,
real  weight 
) [virtual]
void PLearn::RegressionTreeMulticlassLeaveProb::addRow ( int  row,
Vec  outputv,
Vec  errorv 
) [virtual]

Reimplemented from PLearn::RegressionTreeLeave.

Definition at line 150 of file RegressionTreeMulticlassLeaveProb.cc.

References addRow(), and getOutputAndError().

Here is the call graph for this function:

void PLearn::RegressionTreeMulticlassLeaveProb::addRow ( int  row,
real  target,
real  weight,
Vec  outputv,
Vec  errorv 
) [virtual]

Reimplemented from PLearn::RegressionTreeLeave.

Definition at line 136 of file RegressionTreeMulticlassLeaveProb.cc.

References addRow(), and getOutputAndError().

Here is the call graph for this function:

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

Post-constructor.

The normal implementation should call simply inherited::build(), then this class's build_(). This method should be callable again at later times, after modifying some option fields to change the "architecture" of the object.

Reimplemented from PLearn::RegressionTreeLeave.

Definition at line 100 of file RegressionTreeMulticlassLeaveProb.cc.

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

Referenced by RegressionTreeMulticlassLeaveProb().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Object-specific post-constructor.

This method should be redefined in subclasses and do the actual building of the object according to previously set option fields. Constructors can just set option fields, and then call build_. This method is NOT virtual, and will typically be called only from three places: a constructor, the public virtual build() method, and possibly the public virtual read method (which calls its parent's read). build_() can assume that its parent's build_() has already been called.

Reimplemented from PLearn::RegressionTreeLeave.

Definition at line 106 of file RegressionTreeMulticlassLeaveProb.cc.

Referenced by build().

{
}

Here is the caller graph for this function:

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

Reimplemented from PLearn::RegressionTreeLeave.

Definition at line 53 of file RegressionTreeMulticlassLeaveProb.cc.

Referenced by addLeave(), and removeLeave().

Here is the caller graph for this function:

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

Declare options (data fields) for the class.

Redefine this in subclasses: call declareOption(...) for each option, and then call inherited::declareOptions(options). Please call the inherited method AT THE END to get the options listed in a consistent order (from most recently defined to least recently defined).

  static void MyDerivedClass::declareOptions(OptionList& ol)
  {
      declareOption(ol, "inputsize", &MyObject::inputsize_,
                    OptionBase::buildoption,
                    "The size of the input; it must be provided");
      declareOption(ol, "weights", &MyObject::weights,
                    OptionBase::learntoption,
                    "The learned model weights");
      inherited::declareOptions(ol);
  }
Parameters:
olList of options that is progressively being constructed for the current class.

Reimplemented from PLearn::RegressionTreeLeave.

Definition at line 66 of file RegressionTreeMulticlassLeaveProb.cc.

References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::RegressionTreeLeave::declareOptions(), PLearn::OptionBase::learntoption, PLearn::RegressionTreeLeave::loss_function_factor, multiclass_weights_sum, nb_class, objective_function, and PLearn::redeclareOption().

{ 
    inherited::declareOptions(ol);

    declareOption(ol, "nb_class", 
                  &RegressionTreeMulticlassLeaveProb::nb_class,
                  OptionBase::buildoption,
                  "The number of class. Should be numbered from 0 to nb_class -1.\n"
        );

    declareOption(ol, "objective_function",
                  &RegressionTreeMulticlassLeaveProb::objective_function,
                  OptionBase::buildoption,
                  "The function to be used to compute the leave error.\n"
                  "Current supported values are l1 and l2 (default is l1).");
      
    declareOption(ol, "multiclass_weights_sum",
                  &RegressionTreeMulticlassLeaveProb::multiclass_weights_sum,
                  OptionBase::learntoption,
                  "A vector to count the weight sum of each possible output "
                  "for the sample in this leave.\n");
    redeclareOption(ol, "loss_function_factor",
                  &RegressionTreeMulticlassLeaveProb::loss_function_factor,
                  OptionBase::learntoption,
                  "The loss fct factor. Depend of the objective_function.\n");
}

Here is the call graph for this function:

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

Reimplemented from PLearn::RegressionTreeLeave.

Definition at line 72 of file RegressionTreeMulticlassLeaveProb.h.

{return nb_class+1;}
RegressionTreeMulticlassLeaveProb * PLearn::RegressionTreeMulticlassLeaveProb::deepCopy ( CopiesMap copies) const [virtual]

Reimplemented from PLearn::RegressionTreeLeave.

Definition at line 53 of file RegressionTreeMulticlassLeaveProb.cc.

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

Reimplemented from PLearn::RegressionTreeLeave.

Definition at line 53 of file RegressionTreeMulticlassLeaveProb.cc.

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

Reimplemented from PLearn::RegressionTreeLeave.

Definition at line 53 of file RegressionTreeMulticlassLeaveProb.cc.

void PLearn::RegressionTreeMulticlassLeaveProb::getOutputAndError ( Vec output,
Vec error 
) const [virtual]

Reimplemented from PLearn::RegressionTreeLeave.

Definition at line 179 of file RegressionTreeMulticlassLeaveProb.cc.

References PLearn::abs(), PLearn::TVec< T >::clear(), PLearn::TVec< T >::fill(), PLearn::RegressionTreeLeave::length_, PLearn::RegressionTreeLeave::loss_function_factor, PLearn::RegressionTreeLeave::missing_leave, MISSING_VALUE, multiclass_weights_sum, nb_class, objective_function, PLERROR, PLearn::pow(), and PLearn::RegressionTreeLeave::weights_sum.

Referenced by addRow(), printStats(), and removeRow().

{
#ifdef BOUNDCHECK
    if(nb_class<=0)
        PLERROR("In RegressionTreeMulticlassLeaveProb::getOutputAndError() -"
                " nb_class must be set.");
#endif
    if(length_==0){        
        output.fill(MISSING_VALUE);
        error.clear();
        return;
    }
    int mc_winer = 0;
    real conf = 0;
    //index of the max. Is their an optimized version?
    output[1] = multiclass_weights_sum[0] / weights_sum;
    for (int mc_ind = 1; mc_ind < nb_class; mc_ind++)
    {
        output[mc_ind+1]=multiclass_weights_sum[mc_ind] / weights_sum;
        if (multiclass_weights_sum[mc_ind] > multiclass_weights_sum[mc_winer])
            mc_winer = mc_ind;
    }
    output[0] = mc_winer;
    if (missing_leave)
    {
        error[0] = 0.0;
        error[1] = weights_sum;
        error[2] = 0.0;
    }
    else
    {
        conf = multiclass_weights_sum[mc_winer] / weights_sum;
        error[0] = 0.0;
        if (objective_function == "l1")
        {
            for (int mc_ind = 0; mc_ind < nb_class;mc_ind++)
            {
                error[0] += abs(mc_winer - mc_ind) 
                    * multiclass_weights_sum[mc_ind];
            }
        }
        else
        {
            for (int mc_ind = 0; mc_ind < nb_class;mc_ind++)
            {
                error[0] += pow(mc_winer - mc_ind, 2.) 
                    * multiclass_weights_sum[mc_ind];
            }
        }
        error[0] *= loss_function_factor * length_ / weights_sum;
        if (error[0] < 1E-10) error[0] = 0.0;
        if (error[0] > weights_sum * loss_function_factor)
            error[2] = weights_sum * loss_function_factor;
        else error[2] = error[0];
        error[1] = (1.0 - conf) * length_;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from PLearn::RegressionTreeLeave.

Definition at line 237 of file RegressionTreeMulticlassLeaveProb.cc.

References nb_class, and PLearn::tostring().

{
    TVec<string> ret(nb_class+1);
    ret[0]="class_pred";
    for (int mc_ind = 0; mc_ind < nb_class;mc_ind++)
    {
        ret[mc_ind+1]="prob_class_"+tostring(mc_ind);
    }
    return ret;
}

Here is the call graph for this function:

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

Reimplemented from PLearn::RegressionTreeLeave.

Definition at line 53 of file RegressionTreeMulticlassLeaveProb.cc.

void PLearn::RegressionTreeMulticlassLeaveProb::initStats ( ) [virtual]
void PLearn::RegressionTreeMulticlassLeaveProb::makeDeepCopyFromShallowCopy ( CopiesMap copies) [virtual]

Does the necessary operations to transform a shallow copy (this) into a deep copy by deep-copying all the members that need to be.

This needs to be overridden by every class that adds "complex" data members to the class, such as Vec, Mat, PP<Something>, etc. Typical implementation:

  void CLASS_OF_THIS::makeDeepCopyFromShallowCopy(CopiesMap& copies)
  {
      inherited::makeDeepCopyFromShallowCopy(copies);
      deepCopyField(complex_data_member1, copies);
      deepCopyField(complex_data_member2, copies);
      ...
  }
Parameters:
copiesA map used by the deep-copy mechanism to keep track of already-copied objects.

Reimplemented from PLearn::RegressionTreeLeave.

Definition at line 93 of file RegressionTreeMulticlassLeaveProb.cc.

References PLearn::deepCopyField(), PLearn::RegressionTreeLeave::makeDeepCopyFromShallowCopy(), multiclass_weights_sum, and objective_function.

Here is the call graph for this function:

virtual int PLearn::RegressionTreeMulticlassLeaveProb::outputsize ( ) const [inline, virtual]

Reimplemented from PLearn::RegressionTreeLeave.

Definition at line 77 of file RegressionTreeMulticlassLeaveProb.h.

{return nb_class+1;}
void PLearn::RegressionTreeMulticlassLeaveProb::printStats ( ) [virtual]

Reimplemented from PLearn::RegressionTreeLeave.

Definition at line 272 of file RegressionTreeMulticlassLeaveProb.cc.

References PLearn::endl(), getOutputAndError(), PLearn::RegressionTreeLeave::length_, multiclass_weights_sum, and PLearn::RegressionTreeLeave::weights_sum.

{
    cout << " l " << length_;
    Vec output(2);
    Vec error(3);
    getOutputAndError(output,error);
    cout << " o0 " << output[0];
    cout << " o1 " << output[1];
    cout << " e0 " << error[0];
    cout << " e1 " << error[1];
    cout << " ws " << weights_sum;
    cout << endl;
    cout << " mws " << multiclass_weights_sum << endl;
}

Here is the call graph for this function:

void PLearn::RegressionTreeMulticlassLeaveProb::removeLeave ( PP< RegressionTreeLeave leave) [virtual]

Reimplemented from PLearn::RegressionTreeLeave.

Definition at line 260 of file RegressionTreeMulticlassLeaveProb.cc.

References classname(), PLearn::RegressionTreeLeave::length_, multiclass_weights_sum, PLERROR, and PLearn::RegressionTreeLeave::weights_sum.

                                                                                 {
    PP<RegressionTreeMulticlassLeaveProb> leave = (PP<RegressionTreeMulticlassLeaveProb>) leave_;

    if(leave->classname() == classname()){
        length_ -= leave->length_;
        weights_sum -= leave->weights_sum;
        multiclass_weights_sum -= leave->multiclass_weights_sum;
    }else
        PLERROR("In %s::addLeave the leave to add should have the same class. It have %s.",
                classname().c_str(), leave->classname().c_str());
}

Here is the call graph for this function:

void PLearn::RegressionTreeMulticlassLeaveProb::removeRow ( int  row,
real  target,
real  weight 
) [virtual]

Reimplemented from PLearn::RegressionTreeLeave.

Definition at line 169 of file RegressionTreeMulticlassLeaveProb.cc.

References PLearn::RegressionTreeLeave::length_, multiclass_weights_sum, PLASSERT, and PLearn::RegressionTreeLeave::weights_sum.

Referenced by removeRow().

{
    length_ -= 1;
    weights_sum -= weight;
    PLASSERT(length_>=0);
    PLASSERT(weights_sum>=0);
    PLASSERT(length_>0 || weights_sum==0);
    multiclass_weights_sum[int(target)] -= weight;
}

Here is the caller graph for this function:

void PLearn::RegressionTreeMulticlassLeaveProb::removeRow ( int  row,
Vec  outputv,
Vec  errorv 
) [virtual]

Reimplemented from PLearn::RegressionTreeLeave.

Definition at line 156 of file RegressionTreeMulticlassLeaveProb.cc.

References removeRow(), and PLearn::RegressionTreeLeave::train_set.

{
    real weight = train_set->getWeight(row);
    real target = train_set->getTarget(row);
    RegressionTreeMulticlassLeaveProb::removeRow(row,target,weight,outputv,errorv);
}

Here is the call graph for this function:

void PLearn::RegressionTreeMulticlassLeaveProb::removeRow ( int  row,
real  target,
real  weight,
Vec  outputv,
Vec  errorv 
) [virtual]

Reimplemented from PLearn::RegressionTreeLeave.

Definition at line 163 of file RegressionTreeMulticlassLeaveProb.cc.

References getOutputAndError(), and removeRow().

Here is the call graph for this function:


Member Data Documentation

Reimplemented from PLearn::RegressionTreeLeave.

Definition at line 72 of file RegressionTreeMulticlassLeaveProb.h.


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