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

#include <StatsIterator.h>

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

List of all members.

Public Member Functions

virtual string info () const
 Returns a bit more informative string about object (default returns classname())
virtual void init (int inputsize)
 Call this method once with the correct inputsize.
virtual void update (const Vec &input)
 Then iterate over the data set and call this method for each row.
virtual bool finish ()
 LiftStatsIterator (int the_index=0, real the_fraction=0.1)
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual LiftStatsIteratordeepCopy (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 oldwrite (ostream &out) 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 Public Attributes

static StaticInitializer _static_initializer_

Static Protected Member Functions

static void declareOptions (OptionList &ol)
 Declare options (data fields) for the class.

Protected Attributes

int nsamples
int lift_index
real lift_fraction
Mat output_and_pos
Vec targets

Private Types

typedef StatsIterator inherited

Detailed Description

result Vec has size 2: result[0] = lift result[1] = lift/lift_maximum

Definition at line 307 of file StatsIterator.h.


Member Typedef Documentation

Reimplemented from PLearn::StatsIterator.

Definition at line 309 of file StatsIterator.h.


Constructor & Destructor Documentation

PLearn::LiftStatsIterator::LiftStatsIterator ( int  the_index = 0,
real  the_fraction = 0.1 
)

Definition at line 536 of file StatsIterator.cc.

    : nsamples(-1),
      lift_index(the_index),
      lift_fraction(the_fraction)
{}

Member Function Documentation

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

Reimplemented from PLearn::StatsIterator.

Definition at line 528 of file StatsIterator.cc.

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

Reimplemented from PLearn::StatsIterator.

Definition at line 528 of file StatsIterator.cc.

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

Reimplemented from PLearn::StatsIterator.

Definition at line 528 of file StatsIterator.cc.

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

Reimplemented from PLearn::StatsIterator.

Definition at line 528 of file StatsIterator.cc.

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

Reimplemented from PLearn::Object.

Definition at line 528 of file StatsIterator.cc.

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

Reimplemented from PLearn::StatsIterator.

Definition at line 528 of file StatsIterator.cc.

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

Reimplemented from PLearn::Object.

Definition at line 528 of file StatsIterator.cc.

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

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::StatsIterator.

Definition at line 596 of file StatsIterator.cc.

References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::StatsIterator::declareOptions(), PLearn::OptionBase::learntoption, lift_fraction, lift_index, nsamples, output_and_pos, and targets.

Here is the call graph for this function:

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

Reimplemented from PLearn::StatsIterator.

Definition at line 325 of file StatsIterator.h.

:
    static void declareOptions(OptionList& ol);
LiftStatsIterator * PLearn::LiftStatsIterator::deepCopy ( CopiesMap copies) const [virtual]

Reimplemented from PLearn::StatsIterator.

Definition at line 528 of file StatsIterator.cc.

bool PLearn::LiftStatsIterator::finish ( ) [virtual]

Call this method when all the data has been shown (through update) If the method returns false, then a further pass through the data is required.

Implements PLearn::StatsIterator.

Definition at line 568 of file StatsIterator.cc.

References lift_fraction, MIN, nsamples, output_and_pos, PLearn::TMat< T >::resize(), PLearn::TVec< T >::resize(), PLearn::StatsIterator::result, PLearn::selectAndOrder(), PLearn::TMat< T >::subMat(), PLearn::sum(), and targets.

{
    output_and_pos.resize(nsamples,2);
    targets.resize(nsamples);

    const int n_first_samples = int(lift_fraction*nsamples);
    const int n_last_samples = nsamples - n_first_samples;
    selectAndOrder(output_and_pos, n_last_samples);
    /*
      Vec first_samples_index =
      output_and_pos.subMat(n_last_samples,1,n_first_samples,1).toVecCopy();
    */
    TVec<int> first_samples_index(n_first_samples);
    first_samples_index << output_and_pos.subMat(n_last_samples,1,n_first_samples,1);

    Vec first_samples_targets = targets(first_samples_index);
    real first_samples_perf = sum(first_samples_targets)/n_first_samples;
    real targets_perf = sum(targets)/nsamples;
    real lift = first_samples_perf/targets_perf*100.0;
    result[0] = lift;
    real nones = sum(targets);
    real max_first_samples_perf = MIN(nones,(real)n_first_samples)/n_first_samples;
    real max_lift = max_first_samples_perf/targets_perf*100.0;
    result[1] = lift/max_lift;

    return true;
}

Here is the call graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 528 of file StatsIterator.cc.

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

Reimplemented from PLearn::Object.

Definition at line 528 of file StatsIterator.cc.

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

Reimplemented from PLearn::Object.

Definition at line 528 of file StatsIterator.cc.

virtual string PLearn::LiftStatsIterator::info ( ) const [inline, virtual]

Returns a bit more informative string about object (default returns classname())

Returns:
Information about the object

Reimplemented from PLearn::Object.

Definition at line 319 of file StatsIterator.h.

{ return "lift"; }
void PLearn::LiftStatsIterator::init ( int  inputsize) [virtual]

Call this method once with the correct inputsize.

Implements PLearn::StatsIterator.

Definition at line 542 of file StatsIterator.cc.

References nsamples, output_and_pos, PLearn::TVec< T >::resize(), PLearn::TMat< T >::resize(), PLearn::StatsIterator::result, and targets.

{
    // We do not use resize on purpose, so
    // that the previous result Vec does not get overwritten
    result = Vec(2);

    const int initial_length = 1000;
    output_and_pos.resize(initial_length, 2);  // 1 output + 1 pos
    targets.resize(initial_length);
    nsamples = 0;
}

Here is the call graph for this function:

void PLearn::LiftStatsIterator::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::StatsIterator.

Definition at line 529 of file StatsIterator.cc.

References PLearn::deepCopyField(), and PLearn::StatsIterator::makeDeepCopyFromShallowCopy().

Here is the call graph for this function:

void PLearn::LiftStatsIterator::oldwrite ( ostream &  out) const [virtual]

Reimplemented from PLearn::StatsIterator.

Definition at line 616 of file StatsIterator.cc.

References lift_fraction, lift_index, nsamples, output_and_pos, targets, PLearn::Object::write(), PLearn::writeField(), PLearn::writeFooter(), and PLearn::writeHeader().

{
    writeHeader(out,"LiftStatsIterator");
    inherited::write(out);
    writeField(out,"nsamples",nsamples);
    writeField(out,"lift_index",lift_index);
    writeField(out,"lift_fraction",lift_fraction);
    writeField(out,"output_and_pos",output_and_pos);
    writeField(out,"targets",targets);
    writeFooter(out,"LiftStatsIterator");
}

Here is the call graph for this function:

void PLearn::LiftStatsIterator::update ( const Vec input) [virtual]

Then iterate over the data set and call this method for each row.

Implements PLearn::StatsIterator.

Definition at line 554 of file StatsIterator.cc.

References PLearn::FABS(), PLearn::TMat< T >::length(), lift_index, nsamples, output_and_pos, PLearn::TVec< T >::resize(), PLearn::TMat< T >::resize(), and targets.

{
    if (nsamples == output_and_pos.length())
    {
        output_and_pos.resize(10*output_and_pos.length(), 2);
        targets.resize(10*output_and_pos.length());
    }

    output_and_pos(nsamples, 0) = FABS(input[lift_index]);
    output_and_pos(nsamples, 1) = nsamples;
    targets[nsamples] = (input[lift_index]>0) ? 1 : 0;
    nsamples++;
}

Here is the call graph for this function:


Member Data Documentation

Reimplemented from PLearn::StatsIterator.

Definition at line 325 of file StatsIterator.h.

Definition at line 314 of file StatsIterator.h.

Referenced by declareOptions(), finish(), and oldwrite().

Definition at line 313 of file StatsIterator.h.

Referenced by declareOptions(), oldwrite(), and update().

Definition at line 312 of file StatsIterator.h.

Referenced by declareOptions(), finish(), init(), oldwrite(), and update().

Definition at line 315 of file StatsIterator.h.

Referenced by declareOptions(), finish(), init(), oldwrite(), and update().

Definition at line 316 of file StatsIterator.h.

Referenced by declareOptions(), finish(), init(), oldwrite(), and update().


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