|
PLearn 0.1
|
The first sentence should be a BRIEF DESCRIPTION of what the class does. More...
#include <DichotomizeVMatrix.h>


Public Member Functions | |
| DichotomizeVMatrix () | |
| Default constructor. | |
| virtual string | classname () const |
| virtual OptionList & | getOptionList () const |
| virtual OptionMap & | getOptionMap () const |
| virtual RemoteMethodMap & | getRemoteMethodMap () const |
| virtual DichotomizeVMatrix * | deepCopy (CopiesMap &copies) const |
| virtual void | build () |
| Simply calls inherited::build() then build_(). | |
| virtual void | makeDeepCopyFromShallowCopy (CopiesMap &copies) |
| Transforms a shallow copy into a deep copy. | |
Static Public Member Functions | |
| static string | _classname_ () |
| Declares name and deepCopy methods. | |
| static OptionList & | _getOptionList_ () |
| static RemoteMethodMap & | _getRemoteMethodMap_ () |
| static Object * | _new_instance_for_typemap_ () |
| static bool | _isa_ (const Object *o) |
| static void | _static_initialize_ () |
| static const PPath & | declaringFile () |
Public Attributes | |
| TVec< pair< string, TVec< pair < real, real > > > > | discrete_variable_instructions |
| ### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //! | |
| int | verbose |
| bool | missing_field_error |
Static Public Attributes | |
| static StaticInitializer | _static_initializer_ |
Protected Member Functions | |
| virtual void | getNewRow (int i, const Vec &v) const |
| Fill the vector 'v' with the content of the i-th row. | |
Static Protected Member Functions | |
| static void | declareOptions (OptionList &ol) |
| Declares the class options. | |
Private Types | |
| typedef SourceVMatrix | inherited |
Private Member Functions | |
| void | build_ () |
| This does the actual building. | |
Private Attributes | |
| TVec< int > | instruction_index |
The first sentence should be a BRIEF DESCRIPTION of what the class does.
Place the rest of the class programmer documentation here. Doxygen supports Javadoc-style comments. See http://www.doxygen.org/manual.html
Definition at line 57 of file DichotomizeVMatrix.h.
typedef SourceVMatrix PLearn::DichotomizeVMatrix::inherited [private] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 59 of file DichotomizeVMatrix.h.
| PLearn::DichotomizeVMatrix::DichotomizeVMatrix | ( | ) |
Default constructor.
Definition at line 54 of file DichotomizeVMatrix.cc.
:
verbose(3),
missing_field_error(true)
/* ### Initialize all fields to their default value */
{
// ...
// ### You may (or not) want to call build_() to finish building the object
// ### (doing so assumes the parent classes' build_() have been called too
// ### in the parent classes' constructors, something that you must ensure)
}
| string PLearn::DichotomizeVMatrix::_classname_ | ( | ) | [static] |
Declares name and deepCopy methods.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 52 of file DichotomizeVMatrix.cc.
| OptionList & PLearn::DichotomizeVMatrix::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 52 of file DichotomizeVMatrix.cc.
| RemoteMethodMap & PLearn::DichotomizeVMatrix::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 52 of file DichotomizeVMatrix.cc.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 52 of file DichotomizeVMatrix.cc.
| Object * PLearn::DichotomizeVMatrix::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 52 of file DichotomizeVMatrix.cc.
| StaticInitializer DichotomizeVMatrix::_static_initializer_ & PLearn::DichotomizeVMatrix::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 52 of file DichotomizeVMatrix.cc.
| void PLearn::DichotomizeVMatrix::build | ( | ) | [virtual] |
Simply calls inherited::build() then build_().
Reimplemented from PLearn::SourceVMatrix.
Definition at line 272 of file DichotomizeVMatrix.cc.
References PLearn::SourceVMatrix::build(), and build_().
{
inherited::build();
build_();
}

| void PLearn::DichotomizeVMatrix::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 141 of file DichotomizeVMatrix.cc.
References PLearn::VMatrix::declareFieldNames(), PLearn::VMatrix::defineSizes(), discrete_variable_instructions, PLearn::TVec< T >::fill(), instruction_index, PLearn::VMat::length(), PLearn::VMatrix::length_, missing_field_error, PLERROR, PLWARNING, PLearn::TVec< T >::resize(), PLearn::TVec< T >::size(), PLearn::SourceVMatrix::source, PLearn::tostring(), PLearn::VMatrix::updateMtime(), PLearn::VMatrix::width(), PLearn::VMat::width(), and PLearn::VMatrix::width_.
Referenced by build().
{
// ### This method should do the real building of the object,
// ### according to set 'options', in *any* situation.
// ### Typical situations include:
// ### - Initial building of an object from a few user-specified options
// ### - Building of a "reloaded" object: i.e. from the complete set of
// ### all serialised options.
// ### - Updating or "re-building" of an object after a few "tuning"
// ### options have been modified.
// ### You should assume that the parent class' build_() has already been
// ### called.
updateMtime(source);
TVec<string> source_names = source->fieldNames();
instruction_index.resize(source->width());
instruction_index.fill(-1);
//validate the instruction and order them as in the source matrix
for (int ins_col = 0; ins_col < discrete_variable_instructions.size();
ins_col++)
{
int source_col;
for (source_col = 0; source_col < source->width(); source_col++)
{
if (discrete_variable_instructions[ins_col].first == source_names[source_col]) break;
}
if (source_col >= source->width()){
if(missing_field_error)
PLERROR("In DichotomizeVMatrix::build_() - "
"no field with this name in the source data set: %s",
(discrete_variable_instructions[ins_col].first).c_str());
else
PLWARNING("In DichotomizeVMatrix::build_() - "
"no field with this name in the source data set: %s",
(discrete_variable_instructions[ins_col].first).c_str());
}
else instruction_index[source_col] = ins_col;
}
// initialize inputsize_,targetsize_,weightsize_, width_,length()
length_=source->length();
int sisize=source->inputsize();
int stsize=source->targetsize();
int swsize=source->weightsize();
int isize=0;
int tsize=0;
int wsize=0;
int esize=0;
for (int source_col = 0; source_col < sisize; source_col++)
{
if (instruction_index[source_col] < 0) isize++;
else
{
TVec<pair<real, real> > instruction_ptr =
discrete_variable_instructions[instruction_index[source_col]].second;
isize += instruction_ptr.size();
}
}
for (int source_col = sisize;
source_col < sisize + stsize; source_col++)
{
if (instruction_index[source_col] < 0) tsize++;
else
{
TVec<pair<real, real> > instruction_ptr =
discrete_variable_instructions[instruction_index[source_col]].second;
tsize += instruction_ptr.size();
}
}
for (int source_col = sisize + stsize;
source_col < sisize + stsize + swsize ; source_col++)
{
if (instruction_index[source_col] < 0) wsize++;
else
{
TVec<pair<real, real> > instruction_ptr =
discrete_variable_instructions[instruction_index[source_col]].second;
wsize += instruction_ptr.size();
}
}
for (int source_col = sisize + stsize + swsize;
source_col < sisize + stsize + swsize + source->extrasize() ; source_col++)
{
if (instruction_index[source_col] < 0) esize++;
else
{
TVec<pair<real, real> > instruction_ptr =
discrete_variable_instructions[instruction_index[source_col]].second;
esize += instruction_ptr.size();
}
}
defineSizes(isize, tsize, wsize, esize);
width_ = isize + tsize + wsize + esize;
//get the fieldnames
TVec<string> fnames(width());
int field_col = 0;
for (int source_col = 0; source_col < source->width(); source_col++)
{
if (instruction_index[source_col] < 0)
{
fnames[field_col] = source_names[source_col];
field_col += 1;
}
else
{
TVec<pair<real, real> > instruction_ptr =
discrete_variable_instructions[instruction_index[source_col]].second;
if (instruction_ptr.size() == 0)
{
PLWARNING("In DichotomizeVMatrix::build_() -"
"instruction for field %s have no range!",
discrete_variable_instructions[instruction_index[source_col]].first.c_str());
continue;
}
for (int ins_col = 0; ins_col < instruction_ptr.size(); ins_col++)
{
fnames[field_col] = source_names[source_col] + "_"
+ tostring(instruction_ptr[ins_col].first) + "_"
+ tostring(instruction_ptr[ins_col].second);
field_col += 1;
}
}
}
declareFieldNames(fnames);
}


| string PLearn::DichotomizeVMatrix::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 52 of file DichotomizeVMatrix.cc.
| void PLearn::DichotomizeVMatrix::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares the class options.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 111 of file DichotomizeVMatrix.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::SourceVMatrix::declareOptions(), discrete_variable_instructions, instruction_index, PLearn::OptionBase::learntoption, and missing_field_error.
{
// ### Declare all of this object's options here.
// ### For the "flags" of each option, you should typically specify
// ### one of OptionBase::buildoption, OptionBase::learntoption or
// ### OptionBase::tuningoption. If you don't provide one of these three,
// ### this option will be ignored when loading values from a script.
// ### You can also combine flags, for example with OptionBase::nosave:
// ### (OptionBase::buildoption | OptionBase::nosave)
declareOption(ol, "discrete_variable_instructions", &DichotomizeVMatrix::discrete_variable_instructions,
OptionBase::buildoption,
"The instructions to dichotomize the variables in the form of field_name : TVec<pair>.\n"
"The pairs are values from : to, each creating a 0, 1 variable.\n"
"Variables with no specification will be kept as_is.\n");
declareOption(ol, "instruction_index", &DichotomizeVMatrix::instruction_index,
OptionBase::learntoption,
"An array that point each columns of the source matrix to its instruction.");
declareOption(ol, "missing_field_error", &DichotomizeVMatrix::missing_field_error,
OptionBase::buildoption,
"If true we will generate an error is a field is"
" in the instruction but not in the source."
" Otherwise will generate a warning.");
// Now call the parent class' declareOptions
inherited::declareOptions(ol);
}

| static const PPath& PLearn::DichotomizeVMatrix::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 83 of file DichotomizeVMatrix.h.
:
//##### Protected Options ###############################################
| DichotomizeVMatrix * PLearn::DichotomizeVMatrix::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 52 of file DichotomizeVMatrix.cc.
Fill the vector 'v' with the content of the i-th row.
'v' is assumed to be the right size.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 66 of file DichotomizeVMatrix.cc.
References discrete_variable_instructions, PLearn::VMat::fieldName(), instruction_index, PLearn::is_missing(), MISSING_VALUE, PLWARNING, PLearn::TVec< T >::size(), PLearn::SourceVMatrix::source, verbose, and PLearn::VMat::width().
{
Vec source_row(source->width());
source->getRow(i,source_row);
for (int source_col = 0,output_col = 0; source_col < source->width(); source_col++)
{
if (instruction_index[source_col] < 0)
{
v[output_col] = source_row[source_col];
output_col += 1;
}
else
{
TVec<pair<real, real> > instruction_ptr = discrete_variable_instructions[instruction_index[source_col]].second;
if (instruction_ptr.size() == 0) continue;
bool missing = is_missing(source_row[source_col]);
bool found_range = false;
if(missing)
found_range=true;
for (int ins_col = 0; ins_col < instruction_ptr.size(); ins_col++)
{
if (missing)
v[output_col] = MISSING_VALUE;
else if (source_row[source_col] < instruction_ptr[ins_col].first
|| source_row[source_col] > instruction_ptr[ins_col].second)
v[output_col] = 0.0;
else
{
v[output_col] = 1.0;
found_range=true;
}
output_col += 1;
}
if(found_range==false && verbose>2)
{
PLWARNING("DichotomizeVMatrix::getNewRow() - "
"row %d, fields %s, have a value (%f) that are outside all dichotomize range",
i,source->fieldName(source_col).c_str(),source_row[source_col]);
}
}
}
}

| OptionList & PLearn::DichotomizeVMatrix::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 52 of file DichotomizeVMatrix.cc.
| OptionMap & PLearn::DichotomizeVMatrix::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 52 of file DichotomizeVMatrix.cc.
| RemoteMethodMap & PLearn::DichotomizeVMatrix::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 52 of file DichotomizeVMatrix.cc.
| void PLearn::DichotomizeVMatrix::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 278 of file DichotomizeVMatrix.cc.
References PLearn::deepCopyField(), discrete_variable_instructions, instruction_index, and PLearn::SourceVMatrix::makeDeepCopyFromShallowCopy().
{
inherited::makeDeepCopyFromShallowCopy(copies);
deepCopyField(discrete_variable_instructions, copies);
deepCopyField(instruction_index, copies);
}

Reimplemented from PLearn::SourceVMatrix.
Definition at line 83 of file DichotomizeVMatrix.h.
| TVec< pair<string, TVec< pair<real, real> > > > PLearn::DichotomizeVMatrix::discrete_variable_instructions |
### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //!
Definition at line 66 of file DichotomizeVMatrix.h.
Referenced by build_(), declareOptions(), getNewRow(), and makeDeepCopyFromShallowCopy().
TVec<int> PLearn::DichotomizeVMatrix::instruction_index [private] |
Definition at line 121 of file DichotomizeVMatrix.h.
Referenced by build_(), declareOptions(), getNewRow(), and makeDeepCopyFromShallowCopy().
Definition at line 69 of file DichotomizeVMatrix.h.
Referenced by build_(), and declareOptions().
Definition at line 68 of file DichotomizeVMatrix.h.
Referenced by getNewRow().
1.7.4