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::FixDond2BinaryVariables Class Reference

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

#include <FixDond2BinaryVariables.h>

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

List of all members.

Public Member Functions

 FixDond2BinaryVariables ()
 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 FixDond2BinaryVariablesdeepCopy (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< pair< string, string > > binary_variable_instructions
 ### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //!
string output_path
 The file path for the fixed 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 fixBinaryVariables ()

Private Attributes

int ins_width
int ins_col
int main_length
int main_width
int main_row
int main_col
Vec main_input
TVec< string > main_names
TVec< string > main_ins
VMat output_file

Detailed Description

Generate samples from a mixture of two gaussians.

Definition at line 52 of file FixDond2BinaryVariables.h.


Member Typedef Documentation

Reimplemented from PLearn::PLearner.

Definition at line 54 of file FixDond2BinaryVariables.h.


Constructor & Destructor Documentation

PLearn::FixDond2BinaryVariables::FixDond2BinaryVariables ( )

Default constructor.

Definition at line 56 of file FixDond2BinaryVariables.cc.

{
}

Member Function Documentation

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

Reimplemented from PLearn::PLearner.

Definition at line 51 of file FixDond2BinaryVariables.cc.

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

Reimplemented from PLearn::PLearner.

Definition at line 51 of file FixDond2BinaryVariables.cc.

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

Reimplemented from PLearn::PLearner.

Definition at line 51 of file FixDond2BinaryVariables.cc.

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

Reimplemented from PLearn::PLearner.

Definition at line 51 of file FixDond2BinaryVariables.cc.

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

Reimplemented from PLearn::Object.

Definition at line 51 of file FixDond2BinaryVariables.cc.

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

Reimplemented from PLearn::PLearner.

Definition at line 51 of file FixDond2BinaryVariables.cc.

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

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

Reimplemented from PLearn::PLearner.

Definition at line 92 of file FixDond2BinaryVariables.cc.

{
    // ### Nothing to add here, simply calls build_().
    inherited::build();
    build_();
}
void PLearn::FixDond2BinaryVariables::build_ ( ) [private]

This does the actual building.

Reimplemented from PLearn::PLearner.

Definition at line 102 of file FixDond2BinaryVariables.cc.

References PLearn::endl().

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

Here is the call graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 51 of file FixDond2BinaryVariables.cc.

void PLearn::FixDond2BinaryVariables::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 194 of file FixDond2BinaryVariables.cc.

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

{}
void PLearn::FixDond2BinaryVariables::declareOptions ( OptionList ol) [static, protected]

Declares the class options.

Reimplemented from PLearn::PLearner.

Definition at line 63 of file FixDond2BinaryVariables.cc.

References binary_variable_instructions, PLearn::OptionBase::buildoption, PLearn::declareOption(), and output_path.

{
    declareOption(ol, "binary_variable_instructions", &FixDond2BinaryVariables::binary_variable_instructions,
                  OptionBase::buildoption,
                  "The instructions to fix the binary variables in the form of field_name : instruction.\n"
                  "Supported instructions are 9_is_one, not_0_is_one, not_missing_is_one, not_1000_is_one.\n"
                  "Variables with no specification will be kept as_is.\n");

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

    inherited::declareOptions(ol);
}

Here is the call graph for this function:

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

Reimplemented from PLearn::PLearner.

Definition at line 92 of file FixDond2BinaryVariables.h.

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

Reimplemented from PLearn::PLearner.

Definition at line 51 of file FixDond2BinaryVariables.cc.

void PLearn::FixDond2BinaryVariables::fixBinaryVariables ( ) [private]

Definition at line 111 of file FixDond2BinaryVariables.cc.

References PLearn::is_missing(), PLERROR, and PLearn::ProgressBar::update().

{    
    // initialize primary dataset
    main_row = 0;
    main_col = 0;
    main_length = train_set->length();
    main_width = train_set->width();
    main_input.resize(main_width);
    main_names.resize(main_width);
    main_ins.resize(main_width);
    ins_width = binary_variable_instructions.size();
    main_names << train_set->fieldNames();
    for (main_col = 0; main_col < main_width; main_col++)
    {
        main_ins[main_col] = "as_is";
    }
    for (ins_col = 0; ins_col < ins_width; ins_col++)
    {
        for (main_col = 0; main_col < main_width; main_col++)
        {
            if (binary_variable_instructions[ins_col].first == main_names[main_col]) break;
        }
        if (main_col >= main_width) PLERROR("In FixDond2BinaryVariables: no field with this name in train data set: %s", (binary_variable_instructions[ins_col].first).c_str());
        if (binary_variable_instructions[ins_col].second == "9_is_one") main_ins[main_col] = "9_is_one";
        else if (binary_variable_instructions[ins_col].second == "not_0_is_one") main_ins[main_col] = "not_0_is_one";
        else if (binary_variable_instructions[ins_col].second == "not_missing_is_one") main_ins[main_col] = "not_missing_is_one";
        else if (binary_variable_instructions[ins_col].second == "not_1000_is_one") main_ins[main_col] = "not_1000_is_one";
        else PLERROR("In FixDond2BinaryVariables: unsupported instruction: %s", (binary_variable_instructions[ins_col].second).c_str());
    }
    
    // initialize output datasets
    output_file = new FileVMatrix(output_path + ".pmat", main_length, main_names);
    output_file->defineSizes(main_width, 0, 0);
    
    //Now, we can process the binary variables.
    ProgressBar* pb = 0;
    pb = new ProgressBar( "Fixing the binary variables", main_length);
    for (main_row = 0; main_row < main_length; main_row++)
    {
        train_set->getRow(main_row, main_input);
        for (main_col = 0; main_col < main_width; main_col++)
        {
            if (main_ins[main_col] == "not_missing_is_one")
            {
                if (is_missing(main_input[main_col])) main_input[main_col] = 0.0;
                else  main_input[main_col] = 1.0;
            }
            else if (main_ins[main_col] == "not_0_is_one")
            {
                if (is_missing(main_input[main_col])) continue;
                if (main_input[main_col] != 0.0)  main_input[main_col] = 1.0;
                else  main_input[main_col] = 0.0;
            }
            else if (main_ins[main_col] == "9_is_one")
            {
                if (is_missing(main_input[main_col])) continue;
                if (main_input[main_col] == 9.0)  main_input[main_col] = 1.0;
                else  main_input[main_col] = 0.0;
            }
            else if (main_ins[main_col] == "not_1000_is_one")
            {
                if (is_missing(main_input[main_col])) continue;
                if (main_input[main_col] != -1000.0)  main_input[main_col] = 1.0;
                else  main_input[main_col] = 0.0;
            }
        }
        output_file->putRow(main_row, main_input);
        pb->update( main_row );
    }
    delete pb;
}

Here is the call graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 51 of file FixDond2BinaryVariables.cc.

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

Reimplemented from PLearn::Object.

Definition at line 51 of file FixDond2BinaryVariables.cc.

VMat PLearn::FixDond2BinaryVariables::getOutputFile ( )

Definition at line 183 of file FixDond2BinaryVariables.cc.

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

Reimplemented from PLearn::Object.

Definition at line 51 of file FixDond2BinaryVariables.cc.

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

*** SUBCLASS WRITING: ***

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

Implements PLearn::PLearner.

Definition at line 195 of file FixDond2BinaryVariables.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::FixDond2BinaryVariables::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 201 of file FixDond2BinaryVariables.cc.

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

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

Here is the call graph for this function:

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

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::PLearner.

Definition at line 81 of file FixDond2BinaryVariables.cc.

References PLearn::deepCopyField().

Here is the call graph for this function:

int PLearn::FixDond2BinaryVariables::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 188 of file FixDond2BinaryVariables.cc.

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

References PLERROR.

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

Member Data Documentation

Reimplemented from PLearn::PLearner.

Definition at line 92 of file FixDond2BinaryVariables.h.

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

The instructions to fix the binary variables in the form of field_name : instruction. Supported instructions are 9_is_one, not_0_is_one, not_missing_is_one, not_1000_is_one. Variables with no specification will be kept as_is.

Definition at line 66 of file FixDond2BinaryVariables.h.

Referenced by declareOptions().

Definition at line 121 of file FixDond2BinaryVariables.h.

Definition at line 120 of file FixDond2BinaryVariables.h.

Definition at line 127 of file FixDond2BinaryVariables.h.

Definition at line 128 of file FixDond2BinaryVariables.h.

Definition at line 130 of file FixDond2BinaryVariables.h.

Definition at line 124 of file FixDond2BinaryVariables.h.

Definition at line 129 of file FixDond2BinaryVariables.h.

Definition at line 126 of file FixDond2BinaryVariables.h.

Definition at line 125 of file FixDond2BinaryVariables.h.

Definition at line 133 of file FixDond2BinaryVariables.h.

The file path for the fixed output file.

Definition at line 69 of file FixDond2BinaryVariables.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