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

Generate samples from a mixture of two gaussians. More...

#include <ComputeDond2Target.h>

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

List of all members.

Public Member Functions

 ComputeDond2Target ()
 Default constructor.
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.
void train ()
 *** SUBCLASS WRITING: ***
void computeOutput (const Vec &, Vec &) const
 *** SUBCLASS WRITING: ***
void computeCostsFromOutputs (const Vec &, const Vec &, const Vec &, Vec &) const
 *** SUBCLASS WRITING: ***
TVec< string > getTestCostNames () const
 *** SUBCLASS WRITING: ***
TVec< string > getTrainCostNames () const
 *** SUBCLASS WRITING: ***
VMat getOutputFile ()
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual ComputeDond2TargetdeepCopy (CopiesMap &copies) const
virtual void build ()
 Finish building the object; just call inherited::build followed by build_()
virtual void makeDeepCopyFromShallowCopy (CopiesMap &copies)
 Transforms a shallow copy into a deep copy.

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

TVec< string > input_vector
 ### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //!
int unknown_sales
 If set to 1 and annual sales attribute is missing, the class will be set to missing.
int target_sales
 The column of the real annual sales used to compute the real class target.
int predicted_sales
 The column of the predicted annual sales used to compute the predicted class target.
int margin
 The column of the total authorized margins including SLA.
int loan
 The column of the total loan balances excluding mortgages.
string output_path
 The file path for the targeted output file.

Static Public Attributes

static StaticInitializer _static_initializer_

Static Protected Member Functions

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

Private Types

typedef PLearner inherited

Private Member Functions

void build_ ()
 This does the actual building.
void computeTarget ()

Private Attributes

int ins_width
int main_length
Vec main_input
TVec< string > main_names
int target_class
int predicted_class
int output_width
real commitment
Vec output_vec
TVec< string > output_names
TVec< intoutput_variable_src
VMat output_file

Detailed Description

Generate samples from a mixture of two gaussians.

Definition at line 52 of file ComputeDond2Target.h.


Member Typedef Documentation

Reimplemented from PLearn::PLearner.

Definition at line 54 of file ComputeDond2Target.h.


Constructor & Destructor Documentation

PLearn::ComputeDond2Target::ComputeDond2Target ( )

Default constructor.

Definition at line 60 of file ComputeDond2Target.cc.

  : unknown_sales(0)
{
}

Member Function Documentation

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

Reimplemented from PLearn::PLearner.

Definition at line 55 of file ComputeDond2Target.cc.

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

Reimplemented from PLearn::PLearner.

Definition at line 55 of file ComputeDond2Target.cc.

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

Reimplemented from PLearn::PLearner.

Definition at line 55 of file ComputeDond2Target.cc.

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

Reimplemented from PLearn::PLearner.

Definition at line 55 of file ComputeDond2Target.cc.

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

Reimplemented from PLearn::Object.

Definition at line 55 of file ComputeDond2Target.cc.

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

Reimplemented from PLearn::PLearner.

Definition at line 55 of file ComputeDond2Target.cc.

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

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

Reimplemented from PLearn::PLearner.

Definition at line 122 of file ComputeDond2Target.cc.

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

{
    // ### Nothing to add here, simply calls build_().
    inherited::build();
    build_();
}

Here is the call graph for this function:

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

This does the actual building.

Reimplemented from PLearn::PLearner.

Definition at line 132 of file ComputeDond2Target.cc.

References computeTarget(), PLearn::endl(), and PLearn::PLearner::train_set.

Referenced by build().

{
    MODULE_LOG << "build_() called" << endl;
    if (train_set)
    {
        computeTarget();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 55 of file ComputeDond2Target.cc.

void PLearn::ComputeDond2Target::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 219 of file ComputeDond2Target.cc.

{}
void PLearn::ComputeDond2Target::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 218 of file ComputeDond2Target.cc.

{}
void PLearn::ComputeDond2Target::computeTarget ( ) [private]

Definition at line 141 of file ComputeDond2Target.cc.

References commitment, input_vector, ins_width, PLearn::is_missing(), PLearn::VMat::length(), loan, main_input, main_length, main_names, margin, output_file, output_names, output_path, output_variable_src, output_vec, output_width, PLERROR, predicted_class, predicted_sales, PLearn::TVec< T >::resize(), PLearn::TVec< T >::size(), target_class, target_sales, PLearn::PLearner::train_set, unknown_sales, PLearn::ProgressBar::update(), and PLearn::VMat::width().

Referenced by build_().

{    
    // initialize primary dataset
    int main_col = 0;
    main_length = train_set->length();
    int main_width = train_set->width();
    main_input.resize(main_width);
    main_names.resize(main_width);
    ins_width = input_vector.size();
    predicted_class = ins_width;
    target_class = ins_width + 1;
    output_width = ins_width + 2;
    output_variable_src.resize(ins_width);
    output_names.resize(output_width);
    output_vec.resize(output_width);
    main_names << train_set->fieldNames();
    for (int ins_col = 0; ins_col < ins_width; ins_col++)
    {
        for (main_col = 0; main_col < main_width; main_col++)
        {
            if (input_vector[ins_col] == main_names[main_col]) break;
        }
        if (main_col >= main_width) PLERROR("In ComputeDond2Target: no field with this name in input dataset: %s", (input_vector[ins_col]).c_str());
        output_variable_src[ins_col] = main_col;
        output_names[ins_col] = input_vector[ins_col];
    }
    output_names[predicted_class] = "CLASSE_PRED";
    output_names[target_class] = "CLASSE_REEL";
    
    // initialize output datasets
    output_file = new FileVMatrix(output_path + ".pmat", main_length, output_names);
    output_file->defineSizes(output_width, 0, 0);
    
    //Now, we can group the input and compute the class target
    ProgressBar* pb = 0;
    pb = new ProgressBar( "Computing target classes", main_length);
    for (int main_row = 0; main_row < main_length; main_row++)
    {
        train_set->getRow(main_row, main_input);
        for (int ins_col = 0; ins_col < ins_width; ins_col++)
        {
            output_vec[ins_col] = main_input[output_variable_src[ins_col]];
        }
        if (is_missing(main_input[predicted_sales])) main_input[predicted_sales] = 0.0;
        commitment = 0.0;
        if (!is_missing(main_input[margin])) commitment += main_input[margin];
        if (!is_missing(main_input[loan])) commitment += main_input[loan];
        if (main_input[predicted_sales] < 1000000.0 && commitment < 200000.0) output_vec[predicted_class] = 1.0;
        else if (main_input[predicted_sales] < 10000000.0 && commitment < 1000000.0) output_vec[predicted_class] = 2.0;
        else if (main_input[predicted_sales] < 100000000.0 && commitment < 20000000.0) output_vec[predicted_class] = 3.0;
        else output_vec[predicted_class] = 4.0;
        if (is_missing(main_input[target_sales]) && unknown_sales == 0)
            PLERROR("In ComputeDond2Target: no target information for record: %i", main_row);
        commitment = 0.0;
        if (!is_missing(main_input[margin])) commitment += main_input[margin];
        if (!is_missing(main_input[loan])) commitment += main_input[loan];
        if (is_missing(main_input[target_sales]))  output_vec[target_class] = main_input[target_sales];
        else if (main_input[target_sales] < 1000000.0 && commitment < 200000.0) output_vec[target_class] = 1.0;
        else if (main_input[target_sales] < 10000000.0 && commitment < 1000000.0) output_vec[target_class] = 2.0;
        else if (main_input[target_sales] < 100000000.0 && commitment < 20000000.0) output_vec[target_class] = 3.0;
        else output_vec[target_class] = 4.0;
        output_file->putRow(main_row, output_vec);
        pb->update( main_row );
    }
    delete pb;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Declares the class options.

Reimplemented from PLearn::PLearner.

Definition at line 68 of file ComputeDond2Target.cc.

References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::PLearner::declareOptions(), input_vector, loan, margin, output_path, predicted_sales, target_sales, and unknown_sales.

{
    declareOption(ol, "input_vector", &ComputeDond2Target::input_vector,
                  OptionBase::buildoption,
                  "The variables to assemble in the input vector by names.\n"
                  "To ease the following steps they are grouped with the binary variables first,\n"
                  "the discrete variables, the continuous variables and finally some variables unused in the training.\n");

    declareOption(ol, "unknown_sales", &ComputeDond2Target::unknown_sales,
                  OptionBase::buildoption,
                  "If set to 1 and annual sales attribute is missing, the class will be set to missing.");

    declareOption(ol, "target_sales", &ComputeDond2Target::target_sales,
                  OptionBase::buildoption,
                  "The column of the real annual sales used to compute the real class target.");

    declareOption(ol, "predicted_sales", &ComputeDond2Target::predicted_sales,
                  OptionBase::buildoption,
                  "The column of the predicted annual sales used to compute the predicted class target.");

    declareOption(ol, "margin", &ComputeDond2Target::margin,
                  OptionBase::buildoption,
                  "The column of the total authorized margins including SLA.");

    declareOption(ol, "loan", &ComputeDond2Target::loan,
                  OptionBase::buildoption,
                  "The column of the total loan balances excluding mortgages.");

    declareOption(ol, "output_path", &ComputeDond2Target::output_path,
                  OptionBase::buildoption,
                  "The file path for the targeted output file.");

    inherited::declareOptions(ol);
}

Here is the call graph for this function:

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

Reimplemented from PLearn::PLearner.

Definition at line 107 of file ComputeDond2Target.h.

:
    //#####  Protected Member Functions  ######################################
ComputeDond2Target * PLearn::ComputeDond2Target::deepCopy ( CopiesMap copies) const [virtual]

Reimplemented from PLearn::PLearner.

Definition at line 55 of file ComputeDond2Target.cc.

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

Reimplemented from PLearn::Object.

Definition at line 55 of file ComputeDond2Target.cc.

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

Reimplemented from PLearn::Object.

Definition at line 55 of file ComputeDond2Target.cc.

VMat PLearn::ComputeDond2Target::getOutputFile ( )

Definition at line 208 of file ComputeDond2Target.cc.

References output_file.

{
    return output_file;
}
RemoteMethodMap & PLearn::ComputeDond2Target::getRemoteMethodMap ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 55 of file ComputeDond2Target.cc.

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

*** SUBCLASS WRITING: ***

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

Implements PLearn::PLearner.

Definition at line 220 of file ComputeDond2Target.cc.

References PLearn::TVec< T >::append().

{
    TVec<string> result;
    result.append( "MSE" );
    return result;
}

Here is the call graph for this function:

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

References PLearn::TVec< T >::append().

{
    TVec<string> result;
    result.append( "MSE" );
    return result;
}

Here is the call graph for this function:

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

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::PLearner.

Definition at line 106 of file ComputeDond2Target.cc.

References PLearn::deepCopyField(), input_vector, loan, PLearn::PLearner::makeDeepCopyFromShallowCopy(), margin, output_path, predicted_sales, target_sales, and unknown_sales.

Here is the call graph for this function:

int PLearn::ComputeDond2Target::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 213 of file ComputeDond2Target.cc.

{return 0;}
void PLearn::ComputeDond2Target::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 214 of file ComputeDond2Target.cc.

References PLERROR.

{
    PLERROR("ComputeDond2Target: we are done here");
}

Member Data Documentation

Reimplemented from PLearn::PLearner.

Definition at line 107 of file ComputeDond2Target.h.

Definition at line 146 of file ComputeDond2Target.h.

Referenced by computeTarget().

### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //!

The variables to assemble in the input vector by names. To ease the following steps they are grouped with the binary variables first, the discrete variables, the continuous variables and finally some variables unused in the training.

Definition at line 66 of file ComputeDond2Target.h.

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

Definition at line 135 of file ComputeDond2Target.h.

Referenced by computeTarget().

The column of the total loan balances excluding mortgages.

Definition at line 81 of file ComputeDond2Target.h.

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

Definition at line 139 of file ComputeDond2Target.h.

Referenced by computeTarget().

Definition at line 138 of file ComputeDond2Target.h.

Referenced by computeTarget().

Definition at line 140 of file ComputeDond2Target.h.

Referenced by computeTarget().

The column of the total authorized margins including SLA.

Definition at line 78 of file ComputeDond2Target.h.

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

Definition at line 150 of file ComputeDond2Target.h.

Referenced by computeTarget(), and getOutputFile().

Definition at line 148 of file ComputeDond2Target.h.

Referenced by computeTarget().

The file path for the targeted output file.

Definition at line 84 of file ComputeDond2Target.h.

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

Definition at line 149 of file ComputeDond2Target.h.

Referenced by computeTarget().

Definition at line 147 of file ComputeDond2Target.h.

Referenced by computeTarget().

Definition at line 145 of file ComputeDond2Target.h.

Referenced by computeTarget().

Definition at line 144 of file ComputeDond2Target.h.

Referenced by computeTarget().

The column of the predicted annual sales used to compute the predicted class target.

Definition at line 75 of file ComputeDond2Target.h.

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

Definition at line 143 of file ComputeDond2Target.h.

Referenced by computeTarget().

The column of the real annual sales used to compute the real class target.

Definition at line 72 of file ComputeDond2Target.h.

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

If set to 1 and annual sales attribute is missing, the class will be set to missing.

Definition at line 69 of file ComputeDond2Target.h.

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


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