PLearn 0.1
|
The first sentence should be a BRIEF DESCRIPTION of what the class does. More...
#include <MissingInstructionVMatrix.h>
Public Member Functions | |
MissingInstructionVMatrix () | |
Default constructor. | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual MissingInstructionVMatrix * | 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, string > > | missing_instructions |
### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //! | |
string | default_instruction |
If some field in the source matrix have no instruction, we will use this instruction. | |
bool | missing_field_error |
If true will generate an error if some instruction reference missing field. | |
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< string > | ins |
Vec | tmp2 |
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 MissingInstructionVMatrix.h.
typedef SourceVMatrix PLearn::MissingInstructionVMatrix::inherited [private] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 59 of file MissingInstructionVMatrix.h.
PLearn::MissingInstructionVMatrix::MissingInstructionVMatrix | ( | ) |
Default constructor.
Definition at line 52 of file MissingInstructionVMatrix.cc.
: default_instruction(""), 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::MissingInstructionVMatrix::_classname_ | ( | ) | [static] |
Declares name and deepCopy methods.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 50 of file MissingInstructionVMatrix.cc.
OptionList & PLearn::MissingInstructionVMatrix::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 50 of file MissingInstructionVMatrix.cc.
RemoteMethodMap & PLearn::MissingInstructionVMatrix::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 50 of file MissingInstructionVMatrix.cc.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 50 of file MissingInstructionVMatrix.cc.
Object * PLearn::MissingInstructionVMatrix::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 50 of file MissingInstructionVMatrix.cc.
StaticInitializer MissingInstructionVMatrix::_static_initializer_ & PLearn::MissingInstructionVMatrix::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 50 of file MissingInstructionVMatrix.cc.
void PLearn::MissingInstructionVMatrix::build | ( | ) | [virtual] |
Simply calls inherited::build() then build_().
Reimplemented from PLearn::SourceVMatrix.
Definition at line 277 of file MissingInstructionVMatrix.cc.
References PLearn::SourceVMatrix::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::MissingInstructionVMatrix::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 135 of file MissingInstructionVMatrix.cc.
References PLearn::TVec< T >::append(), default_instruction, PLearn::VMatrix::defineSizes(), PLearn::VMatrix::extrasize_, PLearn::VMatrix::fieldinfos, PLearn::TVec< T >::fill(), PLearn::TVec< T >::first(), PLearn::VMatrix::inputsize(), PLearn::VMatrix::inputsize_, ins, PLearn::TVec< T >::length(), PLearn::VMat::length(), PLearn::VMatrix::length_, m, missing_field_error, missing_instructions, PLERROR, PLWARNING, PLearn::TVec< T >::resize(), PLearn::SourceVMatrix::setMetaInfoFromSource(), PLearn::TVec< T >::size(), PLearn::SourceVMatrix::source, PLearn::string_begins_with(), PLearn::VMatrix::targetsize_, tmp2, PLearn::tostring(), PLearn::VMatrix::updateMtime(), PLearn::VMatrix::weightsize_, 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); length_ = source->length(); ins.resize(source->width()); tmp2.resize(source->width()); TVec<string> source_names = source->fieldNames(); //set default instruction ins.fill(default_instruction); int skip_instruction_input = 0; int skip_instruction_target = 0; int skip_instruction_weight = 0; int skip_instruction_extra = 0; if(default_instruction!="skip") width_=source->width(); else{ width_=missing_instructions.size(); PLWARNING("MissingInstructionVMatrix::build_() - " "we suppose that the default instruction apply only to input fields"); skip_instruction_input = source->width() - missing_instructions.size(); } TVec< pair<string, string> > not_used_spec; for (int ins_col = 0; ins_col < missing_instructions.size(); ins_col++) { int source_col = 0; pair<string, string> mis_ins=missing_instructions[ins_col]; for (source_col = 0; source_col < source->width(); source_col++) { if (mis_ins.first == source_names[source_col]) break; } if (source_col >= source->width() && mis_ins.first[mis_ins.first.size()-1]=='*') { string sub_name=mis_ins.first.substr(0,mis_ins.first.size()-1); for (source_col = 0; source_col < source->width(); source_col++) { if (string_begins_with(source_names[source_col],sub_name)){ missing_instructions.append( make_pair(source_names[source_col],mis_ins.second)); } } continue; } else if (source_col >= source->width()) { if(missing_instructions[ins_col].second!="skip"){ //if the instruction is skip, we don't care that it is missing in the source! not_used_spec.append(missing_instructions[ins_col]); } continue; } if (missing_instructions[ins_col].second == "skip") ins[source_col] = "skip"; else if (missing_instructions[ins_col].second == "as_is") ins[source_col] = "as_is"; else if (missing_instructions[ins_col].second == "zero_is_missing") ins[source_col] = "zero_is_missing"; else if (missing_instructions[ins_col].second == "zero_or_neg_is_missing") ins[source_col] = "zero_or_neg_is_missing"; else if (missing_instructions[ins_col].second == "2436935_is_missing" || missing_instructions[ins_col].second == "jdate_is_missing") ins[source_col] = "2436935_is_missing"; else if (missing_instructions[ins_col].second == "present") ins[source_col] = "present"; else if (missing_instructions[ins_col].second.empty()) PLWARNING("In MissingInstructionVMatrix::build_() -" " merge instruction empty for field '%s'," " we keep the previous instruction who could be" " the default_instruction", (missing_instructions[source_col].first).c_str()); else PLERROR("In MissingInstructionVMatrix::build_() -" " unsupported merge instruction: '%s'", (missing_instructions[ins_col].second).c_str()); if (ins[source_col] == "skip"){ if(source_col<source->inputsize()) skip_instruction_input++; else if(source_col<(source->inputsize() + source->targetsize())) skip_instruction_target++; else if (source_col<(source->inputsize() + source->targetsize() + source->weightsize())) skip_instruction_weight++; else skip_instruction_extra++; } } if(not_used_spec.length()>0){ TVec< pair<string, string> > m; PLWARNING("In MissingInstructionVMatrix::build_() -" " There is %d instructions where the field are not in the source: %s" ,not_used_spec.length(),tostring(not_used_spec).c_str()); } setMetaInfoFromSource(); defineSizes(source->inputsize() - skip_instruction_input, source->targetsize() - skip_instruction_target, source->weightsize() - skip_instruction_weight, source->extrasize() - skip_instruction_extra); width_ = inputsize_ + targetsize_ + weightsize_ + extrasize_; int missing_instruction = 0; for (int col = 0; col < source->width(); col++) { if(ins[col].empty()) { PLWARNING("In MissingInstructionVMatrix::build_ -" " their is no instruction for the field '%s'", source_names[col].c_str()); missing_instruction++; } } if(missing_instruction) PLERROR("In MissingInstructionVMatrix::build_ -" " Their have been %d field in the source" " matrix that have no instruction. Do you want" " to set the default_instruction option?",missing_instruction); if(not_used_spec.length()>0 && missing_field_error) PLERROR("In MissingInstructionVMatrix::build_ - Their have been %d" " instruction that have no correcponding field in the" " source matrix",not_used_spec.length()); // Copy the appropriate VMFields fieldinfos.resize(width()); if (source->getFieldInfos().size() > 0) { for (int source_col=0,merge_col=0; source_col<source->width(); ++source_col) { if(ins[source_col]!="skip"){ fieldinfos[merge_col] = source->getFieldInfos(source_col); merge_col++; } } } }
string PLearn::MissingInstructionVMatrix::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 50 of file MissingInstructionVMatrix.cc.
void PLearn::MissingInstructionVMatrix::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares the class options.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 99 of file MissingInstructionVMatrix.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::SourceVMatrix::declareOptions(), default_instruction, missing_field_error, and missing_instructions.
{ // ### 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) // ### ex: // declareOption(ol, "myoption", &MissingInstructionVMatrix::myoption, // OptionBase::buildoption, // "Help text describing this option"); // ... // Now call the parent class' declareOptions inherited::declareOptions(ol); declareOption(ol, "missing_instructions", &MissingInstructionVMatrix::missing_instructions, OptionBase::buildoption, "The variable missing regeneration instructions in the form of pairs field : instruction.\n" "Supported instructions are skip, as_is, zero_is_missing, zero_or_neg_is_missing, 2436935_is_missing(01JAN1960 in julian day), jdate_is_missing(idem as 2436935_is_missing), present.\n" "If the instruction fieldname end with '*' we will extend it to all the source matrix fieldname that match the regex.\n" "No other regex are supported"); declareOption(ol, "default_instruction", &MissingInstructionVMatrix::default_instruction, OptionBase::buildoption, "If some field in the source matrix have no instruction," " we will use this instruction. We will warn about field" " with empty instruction then will stop."); declareOption(ol, "missing_field_error", &MissingInstructionVMatrix::missing_field_error , OptionBase::buildoption, "If true will generate an error if some instruction reference missing field" ); }
static const PPath& PLearn::MissingInstructionVMatrix::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 90 of file MissingInstructionVMatrix.h.
:
//##### Protected Options ###############################################
MissingInstructionVMatrix * PLearn::MissingInstructionVMatrix::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 50 of file MissingInstructionVMatrix.cc.
void PLearn::MissingInstructionVMatrix::getNewRow | ( | int | i, |
const Vec & | v | ||
) | const [protected, virtual] |
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 64 of file MissingInstructionVMatrix.cc.
References ins, PLearn::is_missing(), MISSING_VALUE, PLearn::SourceVMatrix::source, tmp2, and PLearn::VMat::width().
{ // ... source->getRow(i,tmp2); for (int col = 0,merge_col = 0; col < source->width(); col++) { if (ins[col] == "skip") continue; else if (ins[col] == "as_is") { v[merge_col] = tmp2[col]; } else if (ins[col] == "zero_is_missing") { if (tmp2[col] == 0.0) v[merge_col] = MISSING_VALUE; else v[merge_col] = tmp2[col]; } else if (ins[col] == "zero_or_neg_is_missing") { if (tmp2[col] <= 0.0) v[merge_col] = MISSING_VALUE; else v[merge_col] = tmp2[col]; } else if (ins[col] == "2436935_is_missing") { if (tmp2[col] == 2436935.0) v[merge_col] = MISSING_VALUE; else v[merge_col] = tmp2[col]; } else if (ins[col] == "present") { if (is_missing(tmp2[col])) v[merge_col] = 0.0; else v[merge_col] = 1.0; } merge_col +=1; } }
OptionList & PLearn::MissingInstructionVMatrix::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 50 of file MissingInstructionVMatrix.cc.
OptionMap & PLearn::MissingInstructionVMatrix::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 50 of file MissingInstructionVMatrix.cc.
RemoteMethodMap & PLearn::MissingInstructionVMatrix::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 50 of file MissingInstructionVMatrix.cc.
void PLearn::MissingInstructionVMatrix::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 283 of file MissingInstructionVMatrix.cc.
References PLearn::deepCopyField(), PLearn::SourceVMatrix::makeDeepCopyFromShallowCopy(), and missing_instructions.
{ inherited::makeDeepCopyFromShallowCopy(copies); deepCopyField(missing_instructions, copies); }
Reimplemented from PLearn::SourceVMatrix.
Definition at line 90 of file MissingInstructionVMatrix.h.
If some field in the source matrix have no instruction, we will use this instruction.
Will warn about field with empty instruction then stop.
Definition at line 73 of file MissingInstructionVMatrix.h.
Referenced by build_(), and declareOptions().
TVec<string> PLearn::MissingInstructionVMatrix::ins [private] |
Definition at line 128 of file MissingInstructionVMatrix.h.
Referenced by build_(), and getNewRow().
If true will generate an error if some instruction reference missing field.
Definition at line 76 of file MissingInstructionVMatrix.h.
Referenced by build_(), and declareOptions().
TVec< pair<string, string> > PLearn::MissingInstructionVMatrix::missing_instructions |
### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //!
The variable missing regeneration instructions in the form of pairs field : instruction. Supported instructions are skip, as_is, zero_is_missing, 2436935_is_missing.
Definition at line 69 of file MissingInstructionVMatrix.h.
Referenced by build_(), declareOptions(), and makeDeepCopyFromShallowCopy().
Vec PLearn::MissingInstructionVMatrix::tmp2 [mutable, private] |
Definition at line 129 of file MissingInstructionVMatrix.h.
Referenced by build_(), and getNewRow().