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

#include <ConditionalMeanImputationVMatrix.h>

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

List of all members.

Public Member Functions

 ConditionalMeanImputationVMatrix ()
virtual ~ConditionalMeanImputationVMatrix ()
virtual void build ()
 Simply calls inherited::build() then build_().
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 getExample (int i, Vec &input, Vec &target, real &weight)
 Default version calls getSubRow based on inputsize_ targetsize_ weightsize_ But exotic subclasses may construct, input, target and weight however they please.
virtual real get (int i, int j) const
 This method must be implemented in all subclasses.
virtual void put (int i, int j, real value)
 This method must be implemented in all subclasses of writable matrices.
virtual void getSubRow (int i, int j, Vec v) const
 It is suggested that this method be implemented in subclasses to speed up accesses (default version repeatedly calls get(i,j) which may have a significant overhead).
virtual void putSubRow (int i, int j, Vec v)
 It is suggested that this method be implemented in subclasses of writable matrices to speed up accesses (default version repeatedly calls put(i,j,value) which may have a significant overhead)
virtual void appendRow (Vec v)
 This method must be implemented for matrices that are allowed to grow.
virtual void insertRow (int i, Vec v)
 This method must be implemented for matrices that are allowed to grow.
virtual void getRow (int i, Vec v) const
 These methods do not usually need to be overridden in subclasses (default versions call getSubRow, which should do just fine)
virtual void putRow (int i, Vec v)
virtual void getColumn (int i, Vec v) const
 Copies column i into v (which must have appropriate length equal to the VMat's length).
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual
ConditionalMeanImputationVMatrix
deepCopy (CopiesMap &copies) const

Static Public Member Functions

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

string condmean_dir
 The directory in the source metadatadir housing the variable conditional mean files.
Mat condmean
 The matrix of conditional means.
TVec< intcondmean_col_ref
 The cross reference between columns of source and condmean.

Static Public Attributes

static StaticInitializer _static_initializer_

Private Types

typedef ImputationVMatrix inherited

Private Member Functions

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

Private Attributes

int source_length
int source_width
int source_inputsize
int source_targetsize
int source_weightsize
int source_row
int source_col
PPath source_metadata
TVec< string > source_names
StatsCollector source_stats

Detailed Description

Definition at line 53 of file ConditionalMeanImputationVMatrix.h.


Member Typedef Documentation

Reimplemented from PLearn::ImputationVMatrix.

Definition at line 55 of file ConditionalMeanImputationVMatrix.h.


Constructor & Destructor Documentation

PLearn::ConditionalMeanImputationVMatrix::ConditionalMeanImputationVMatrix ( )

Definition at line 60 of file ConditionalMeanImputationVMatrix.cc.

{
}
PLearn::ConditionalMeanImputationVMatrix::~ConditionalMeanImputationVMatrix ( ) [virtual]

Definition at line 64 of file ConditionalMeanImputationVMatrix.cc.

{
}

Member Function Documentation

string PLearn::ConditionalMeanImputationVMatrix::_classname_ ( ) [static]
OptionList & PLearn::ConditionalMeanImputationVMatrix::_getOptionList_ ( ) [static]

Reimplemented from PLearn::ImputationVMatrix.

Definition at line 58 of file ConditionalMeanImputationVMatrix.cc.

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

Reimplemented from PLearn::ImputationVMatrix.

Definition at line 58 of file ConditionalMeanImputationVMatrix.cc.

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

Reimplemented from PLearn::ImputationVMatrix.

Definition at line 58 of file ConditionalMeanImputationVMatrix.cc.

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

Reimplemented from PLearn::Object.

Definition at line 58 of file ConditionalMeanImputationVMatrix.cc.

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

Reimplemented from PLearn::ImputationVMatrix.

Definition at line 58 of file ConditionalMeanImputationVMatrix.cc.

void PLearn::ConditionalMeanImputationVMatrix::appendRow ( Vec  v) [virtual]

This method must be implemented for matrices that are allowed to grow.

Reimplemented from PLearn::VMatrix.

Definition at line 127 of file ConditionalMeanImputationVMatrix.cc.

References PLERROR.

{
  PLERROR("In ConditionalMeanImputationVMatrix::appendRow not implemented");
}
void PLearn::ConditionalMeanImputationVMatrix::build ( ) [virtual]

Simply calls inherited::build() then build_().

Reimplemented from PLearn::ImputationVMatrix.

Definition at line 79 of file ConditionalMeanImputationVMatrix.cc.

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

This does the actual building.

Reimplemented from PLearn::ImputationVMatrix.

Definition at line 160 of file ConditionalMeanImputationVMatrix.cc.

References PLERROR.

{
    if (!source) PLERROR("In ConditionalMeanImputationVMatrix::source vmat must be supplied");
    loadCondMeanMatrix(); 
    testResultantVMatrix();
}
string PLearn::ConditionalMeanImputationVMatrix::classname ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 58 of file ConditionalMeanImputationVMatrix.cc.

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

Declares this class' options.

Reimplemented from PLearn::ImputationVMatrix.

Definition at line 68 of file ConditionalMeanImputationVMatrix.cc.

References PLearn::OptionBase::buildoption, condmean, condmean_col_ref, condmean_dir, PLearn::declareOption(), and PLearn::OptionBase::learntoption.

{
  declareOption(ol, "condmean_dir", &ConditionalMeanImputationVMatrix::condmean_dir, OptionBase::buildoption, 
                "The directory in the source metadatadir housing the variable conditional mean files.\n");
  declareOption(ol, "condmean", &ConditionalMeanImputationVMatrix::condmean, OptionBase::learntoption, 
                "The matrix of conditional means.\n");
  declareOption(ol, "condmean_col_ref", &ConditionalMeanImputationVMatrix::condmean_col_ref, OptionBase::learntoption, 
                "The cross reference between columns of source and condmean.\n");
  inherited::declareOptions(ol);
}

Here is the call graph for this function:

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

Reimplemented from PLearn::ImputationVMatrix.

Definition at line 105 of file ConditionalMeanImputationVMatrix.h.

ConditionalMeanImputationVMatrix * PLearn::ConditionalMeanImputationVMatrix::deepCopy ( CopiesMap copies) const [virtual]

Reimplemented from PLearn::ImputationVMatrix.

Definition at line 58 of file ConditionalMeanImputationVMatrix.cc.

real PLearn::ConditionalMeanImputationVMatrix::get ( int  i,
int  j 
) const [virtual]

This method must be implemented in all subclasses.

Returns element (i,j).

Implements PLearn::VMatrix.

Definition at line 101 of file ConditionalMeanImputationVMatrix.cc.

References PLearn::is_missing(), and PLERROR.

{ 
  real variable_value = source->get(i, j);
  if (is_missing(variable_value) && condmean_col_ref[j] >= 0) return condmean(i, condmean_col_ref[j]);
  else if (is_missing(variable_value)) PLERROR("In ConditionalMeanImputationVMatrix::getExample(%d,%d) we have a missing value that haven't been assigned a value",i,j);
  return variable_value;
}

Here is the call graph for this function:

void PLearn::ConditionalMeanImputationVMatrix::getColumn ( int  i,
Vec  v 
) const [virtual]

Copies column i into v (which must have appropriate length equal to the VMat's length).

Reimplemented from PLearn::VMatrix.

Definition at line 150 of file ConditionalMeanImputationVMatrix.cc.

References i, PLearn::is_missing(), PLearn::TVec< T >::length(), and PLERROR.

{  
  source-> getColumn(i, v);
  for (int source_row = 0; source_row < v->length(); source_row++)
    if (is_missing(v[source_row]) && condmean_col_ref[i] >= 0) v[source_row] = condmean(source_row, condmean_col_ref[i]);
    else if (is_missing(v[source_row])) PLERROR("In ConditionalMeanImputationVMatrix::getColumn(%d,vec) we have a missing value in row %d that haven't been assigned a value",i,source_row);
}

Here is the call graph for this function:

void PLearn::ConditionalMeanImputationVMatrix::getExample ( int  i,
Vec input,
Vec target,
real weight 
) [virtual]

Default version calls getSubRow based on inputsize_ targetsize_ weightsize_ But exotic subclasses may construct, input, target and weight however they please.

If not a weighted matrix, weight should be set to default value 1.

Reimplemented from PLearn::VMatrix.

Definition at line 93 of file ConditionalMeanImputationVMatrix.cc.

References PLearn::is_missing(), PLearn::TVec< T >::length(), and PLERROR.

{
  source->getExample(i, input, target, weight);
  for (int source_col = 0; source_col < input->length(); source_col++)
    if (is_missing(input[source_col]) && condmean_col_ref[source_col] >= 0) input[source_col] = condmean(i, condmean_col_ref[source_col]);
    else if (is_missing(input[source_col])) PLERROR("In ConditionalMeanImputationVMatrix::getExample(%d,vec,vec,vec) we have a missing value in column %d that haven't been assigned a value",i,source_col);
}

Here is the call graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 58 of file ConditionalMeanImputationVMatrix.cc.

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

Reimplemented from PLearn::Object.

Definition at line 58 of file ConditionalMeanImputationVMatrix.cc.

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

Reimplemented from PLearn::Object.

Definition at line 58 of file ConditionalMeanImputationVMatrix.cc.

void PLearn::ConditionalMeanImputationVMatrix::getRow ( int  i,
Vec  v 
) const [virtual]

These methods do not usually need to be overridden in subclasses (default versions call getSubRow, which should do just fine)

Copies row i into v (which must have appropriate length equal to the VMat's width).

Reimplemented from PLearn::VMatrix.

Definition at line 137 of file ConditionalMeanImputationVMatrix.cc.

References PLearn::is_missing(), PLearn::TVec< T >::length(), and PLERROR.

{  
  source-> getRow(i, v);
  for (int source_col = 0; source_col < v->length(); source_col++)
    if (is_missing(v[source_col]) && condmean_col_ref[source_col] >= 0) v[source_col] = condmean(i, condmean_col_ref[source_col]);
    else if (is_missing(v[source_col])) PLERROR("In ConditionalMeanImputationVMatrix::getRow(%d,vec) we have a missing value in column %d that haven't been assigned a value",i,source_col);
}

Here is the call graph for this function:

void PLearn::ConditionalMeanImputationVMatrix::getSubRow ( int  i,
int  j,
Vec  v 
) const [virtual]

It is suggested that this method be implemented in subclasses to speed up accesses (default version repeatedly calls get(i,j) which may have a significant overhead).

Fills v with the subrow i lying between columns j (inclusive) and j+v.length() (exclusive).

Reimplemented from PLearn::VMatrix.

Definition at line 114 of file ConditionalMeanImputationVMatrix.cc.

References PLearn::is_missing(), PLearn::TVec< T >::length(), and PLERROR.

{  
  source->getSubRow(i, j, v);
  for (int source_col = 0; source_col < v->length(); source_col++) 
    if (is_missing(v[source_col])) v[source_col] = condmean(i, condmean_col_ref[source_col + j]);
    else if (is_missing(v[source_col])) PLERROR("In ConditionalMeanImputationVMatrix::getSubRow(%d,%d,vec) we have a missing value in colomn %d that haven't been assigned a value",i,j,source_col);
}

Here is the call graph for this function:

void PLearn::ConditionalMeanImputationVMatrix::insertRow ( int  i,
Vec  v 
) [virtual]

This method must be implemented for matrices that are allowed to grow.

Reimplemented from PLearn::VMatrix.

Definition at line 132 of file ConditionalMeanImputationVMatrix.cc.

References PLERROR.

{
  PLERROR("In ConditionalMeanImputationVMatrix::insertRow not implemented");
}
void PLearn::ConditionalMeanImputationVMatrix::loadCondMeanMatrix ( ) [private]

Definition at line 167 of file ConditionalMeanImputationVMatrix.cc.

References PLearn::isfile(), PLearn::VMat::length(), and PLERROR.

{
    // initialize source dataset
    source_length = source->length();
    source_width = source->width();
    source_inputsize = source->inputsize();
    source_targetsize = source->targetsize();
    source_weightsize = source->weightsize();
    source_names.resize(source_width);
    source_names = source->fieldNames();
    source_metadata = source->getMetaDataDir();
    length_ = source_length;
    width_ = source_width;
    inputsize_ = source_inputsize;
    targetsize_ = source_targetsize;
    weightsize_ = source_weightsize;
    declareFieldNames(source_names);
    
    // count the # of variables with missing values in the source datasets.
    // create a matrix in memory with this number of columns and keep cross reference of columns.
    int count_variable_with_missing = 0;
    condmean_col_ref.resize(source_width);
    condmean_col_ref.fill(-1);
    for (source_col = 0; source_col < source_width; source_col++)
    {
        source_stats = source->getStats(source_col);
        if (source_stats.nmissing() <= 0) continue;
        condmean_col_ref[source_col] = count_variable_with_missing;
        count_variable_with_missing += 1;
    }
    condmean.resize(source_length, count_variable_with_missing);
    
    // for each variable with missing value, 
    // look for the (cond_mean_dir (/TreeCondMean/dir/) + field_name + /Split0/test1_outputs.pmat) file in the metadatadir;
    // add its column 0 as a column of the condmean matrix.
    for (source_col = 0; source_col < source_width; source_col++)
    {
        source_stats = source->getStats(source_col);
        if (source_stats.nmissing() <= 0) continue;
        int condmean_col = condmean_col_ref[source_col];
        PPath condmean_variable_file_name = source_metadata + "/" + condmean_dir + "/dir/" + source_names[source_col] + "/Split0/test1_outputs.pmat";
        if (!isfile(condmean_variable_file_name)) PLERROR("In ConditionalMeanImputationVMatrix::A conditional mean file(%s) was not found for variable %s",
                                                          condmean_variable_file_name.c_str(),source_names[source_col].c_str());
        VMat condmean_variable_file = new FileVMatrix(condmean_variable_file_name, false);
        if (condmean_variable_file->length() != source_length)
            PLERROR("In ConditionalMeanImputationVMatrix::Source and conditional mean file length are not equal for variable %s", source_names[source_col].c_str());
        for (source_row = 0; source_row < source_length; source_row++)
            condmean(source_row, condmean_col) = condmean_variable_file->get(source_row, 0);
    }
}

Here is the call graph for this function:

void PLearn::ConditionalMeanImputationVMatrix::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::ImputationVMatrix.

Definition at line 85 of file ConditionalMeanImputationVMatrix.cc.

References PLearn::deepCopyField().

Here is the call graph for this function:

void PLearn::ConditionalMeanImputationVMatrix::put ( int  i,
int  j,
real  value 
) [virtual]

This method must be implemented in all subclasses of writable matrices.

Sets element (i,j) to value.

Reimplemented from PLearn::VMatrix.

Definition at line 109 of file ConditionalMeanImputationVMatrix.cc.

References PLERROR.

{
  PLERROR("In ConditionalMeanImputationVMatrix::put not implemented");
}
void PLearn::ConditionalMeanImputationVMatrix::putRow ( int  i,
Vec  v 
) [virtual]

Reimplemented from PLearn::VMatrix.

Definition at line 145 of file ConditionalMeanImputationVMatrix.cc.

References PLERROR.

{
  PLERROR("In ConditionalMeanImputationVMatrix::putRow not implemented");
}
void PLearn::ConditionalMeanImputationVMatrix::putSubRow ( int  i,
int  j,
Vec  v 
) [virtual]

It is suggested that this method be implemented in subclasses of writable matrices to speed up accesses (default version repeatedly calls put(i,j,value) which may have a significant overhead)

Reimplemented from PLearn::VMatrix.

Definition at line 122 of file ConditionalMeanImputationVMatrix.cc.

References PLERROR.

{
  PLERROR("In ConditionalMeanImputationVMatrix::putSubRow not implemented");
}

Member Data Documentation

Reimplemented from PLearn::ImputationVMatrix.

Definition at line 105 of file ConditionalMeanImputationVMatrix.h.

The matrix of conditional means.

Definition at line 63 of file ConditionalMeanImputationVMatrix.h.

Referenced by declareOptions().

The cross reference between columns of source and condmean.

Definition at line 66 of file ConditionalMeanImputationVMatrix.h.

Referenced by declareOptions().

The directory in the source metadatadir housing the variable conditional mean files.

Definition at line 60 of file ConditionalMeanImputationVMatrix.h.

Referenced by declareOptions().

Definition at line 96 of file ConditionalMeanImputationVMatrix.h.

Definition at line 92 of file ConditionalMeanImputationVMatrix.h.

Definition at line 90 of file ConditionalMeanImputationVMatrix.h.

Definition at line 97 of file ConditionalMeanImputationVMatrix.h.

Definition at line 98 of file ConditionalMeanImputationVMatrix.h.

Definition at line 95 of file ConditionalMeanImputationVMatrix.h.

Definition at line 99 of file ConditionalMeanImputationVMatrix.h.

Definition at line 93 of file ConditionalMeanImputationVMatrix.h.

Definition at line 94 of file ConditionalMeanImputationVMatrix.h.

Definition at line 91 of file ConditionalMeanImputationVMatrix.h.


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