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


Public Member Functions | |
| MixUnlabeledNeighbourVMatrix () | |
| Default constructor. | |
| virtual string | classname () const |
| virtual OptionList & | getOptionList () const |
| virtual OptionMap & | getOptionMap () const |
| virtual RemoteMethodMap & | getRemoteMethodMap () const |
| virtual MixUnlabeledNeighbourVMatrix * | 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 | |
| long | seed |
| ### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //! | |
| TVec< int > | indices |
| VMat | source_select |
| double | frac |
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. | |
Protected Attributes | |
| PP< PRandom > | random_generator |
| Used to shuffle the related unlabeled examples. | |
| PP< SortRowsVMatrix > | sorted_source_select |
| The sorted source_select. | |
| Vec | row_buffer |
| Used to store temporary data. | |
| Vec | neighbor_weights |
| The weights for each neighbor (set equal to the weight of the original sample). | |
Private Types | |
| typedef SourceVMatrix | inherited |
Private Member Functions | |
| void | build_ () |
| This does the actual building. | |
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 60 of file MixUnlabeledNeighbourVMatrix.h.
typedef SourceVMatrix PLearn::MixUnlabeledNeighbourVMatrix::inherited [private] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 62 of file MixUnlabeledNeighbourVMatrix.h.
| PLearn::MixUnlabeledNeighbourVMatrix::MixUnlabeledNeighbourVMatrix | ( | ) |
Default constructor.
Definition at line 60 of file MixUnlabeledNeighbourVMatrix.cc.
: /* ### Initialize all fields to their default value */ seed(-1), frac(1), random_generator(new PRandom()) { // ... // ### 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::MixUnlabeledNeighbourVMatrix::_classname_ | ( | ) | [static] |
Declares name and deepCopy methods.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 55 of file MixUnlabeledNeighbourVMatrix.cc.
| OptionList & PLearn::MixUnlabeledNeighbourVMatrix::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 55 of file MixUnlabeledNeighbourVMatrix.cc.
| RemoteMethodMap & PLearn::MixUnlabeledNeighbourVMatrix::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 55 of file MixUnlabeledNeighbourVMatrix.cc.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 55 of file MixUnlabeledNeighbourVMatrix.cc.
| Object * PLearn::MixUnlabeledNeighbourVMatrix::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 55 of file MixUnlabeledNeighbourVMatrix.cc.
| StaticInitializer MixUnlabeledNeighbourVMatrix::_static_initializer_ & PLearn::MixUnlabeledNeighbourVMatrix::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 55 of file MixUnlabeledNeighbourVMatrix.cc.
| void PLearn::MixUnlabeledNeighbourVMatrix::build | ( | ) | [virtual] |
Simply calls inherited::build() then build_().
Reimplemented from PLearn::SourceVMatrix.
Definition at line 94 of file MixUnlabeledNeighbourVMatrix.cc.
References PLearn::SourceVMatrix::build(), and build_().
{
// ### Nothing to add here, simply calls build_
inherited::build();
build_();
}

| void PLearn::MixUnlabeledNeighbourVMatrix::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 104 of file MixUnlabeledNeighbourVMatrix.cc.
References PLearn::TVec< T >::append(), PLearn::VMatrix::declareFieldNames(), frac, PLearn::VMat::getExample(), i, indices, PLearn::VMatrix::inputsize(), PLearn::VMatrix::inputsize_, PLearn::TVec< T >::lastElement(), PLearn::TVec< T >::length(), PLearn::VMat::length(), PLearn::VMatrix::length(), PLearn::VMatrix::length_, neighbor_weights, PLASSERT, PLERROR, PLearn::TVec< T >::push_back(), random_generator, PLearn::TVec< T >::remove(), PLearn::TVec< T >::resize(), seed, PLearn::SourceVMatrix::setMetaInfoFromSource(), sorted_source_select, PLearn::SourceVMatrix::source, source_select, PLearn::VMatrix::targetsize(), PLearn::VMatrix::targetsize_, PLearn::VMatrix::updateMtime(), PLearn::VMatrix::weightsize_, 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.
random_generator->manual_seed(seed);
if (!source)
return;
if (source && ( source->targetsize() < 1))
PLERROR("In MixUnlabeledNeighbourVMatrix::build_ - We need a key column for 'source'");
if (source_select && (source_select->targetsize() < 1))
PLERROR("In MixUnlabeledNeighbourVMatrix::build_ - We need a key column for 'source_select'");
if (source_select && source && source_select->inputsize() != source->inputsize())
PLERROR("In MixUnlabeledNeighbourVMatrix::build_ - VMats 'source_select'"
"and 'source' should have the same inputsize().");
indices.resize(0); // This get rid of the user's build option value.
TVec<int> bag_indices;
Vec input,target,targetSel;
string lastKey;
real weight;
bool sourceFound;
int rowSel,row;
int keyCol = source->inputsize() + source->targetsize()-1;
neighbor_weights.resize(0);
if (source_select){ // If it was given, find the related example
int keyCol_select = source_select->inputsize() + source_select->targetsize()-1;
sorted_source_select = new SortRowsVMatrix();
sorted_source_select->source = source_select;
sorted_source_select->sort_columns = TVec<int>(1,keyCol_select);
sorted_source_select->build();
sorted_source_select->getExample(0,input,targetSel,weight);
lastKey = sorted_source_select->getValString(keyCol_select,targetSel.lastElement());
rowSel = 0;
bag_indices.resize(0);
while(rowSel < sorted_source_select->length()){
sorted_source_select->getExample(rowSel,input,targetSel,weight);
if (lastKey == sorted_source_select->getValString(keyCol_select,
targetSel.lastElement())){
bag_indices.push_back(rowSel);
}else{
sourceFound = (lastKey == "all");
for(row=0; row < source->length() && !sourceFound; row++){
source->getExample(row,input,target,weight);
if(lastKey == source->getValString(keyCol,target.lastElement())) sourceFound=true;
}
if (sourceFound){
random_generator->shuffleElements(bag_indices);
int n_kept = int(round(frac*bag_indices.length()));
for(int i=0; i < n_kept; i++) {
if (source->weightsize() > 0) {
PLASSERT( source->weightsize() == 1 );
neighbor_weights.append(weight); // normally still pointing to the correct weight
}
indices.push_back(bag_indices[i]);
}
}
bag_indices.resize(0);
lastKey = sorted_source_select->getValString(keyCol_select,targetSel.lastElement());
bag_indices.push_back(rowSel);
}
rowSel++;
if (rowSel == sorted_source_select->length()){
sourceFound = (lastKey == "all");
for(row=0; row < source->length() && !sourceFound; row++){
source->getExample(row,input,target,weight);
if(lastKey == source->getValString(keyCol,target.lastElement())) sourceFound=true;
}
if (sourceFound){
random_generator->shuffleElements(bag_indices);
int n_kept = int(round(frac*bag_indices.length()));
for(int i=0; i < n_kept; i++) {
if (source->weightsize() > 0) {
PLASSERT( source->weightsize() == 1 );
neighbor_weights.append(weight); // normally still pointing to the correct weight
}
indices.push_back(bag_indices[i]);
}
}
}
}
updateMtime(source_select);
}
// ?? Modify the width, length, (targetsize, inputsize and weight) size attribute.
inputsize_ = source->inputsize();
targetsize_ = source->targetsize()-1;
weightsize_ = source->weightsize();
width_ = source->width()-1;
if(source_select) {
length_ = source->length() + indices.length();
}else{
length_ = source->length();
}
TVec<string>tempofn = source->fieldNames();
tempofn.remove(inputsize()+targetsize());
declareFieldNames(tempofn);
// ### In a SourceVMatrix, you will typically end build_() with:
setMetaInfoFromSource();
}


| string PLearn::MixUnlabeledNeighbourVMatrix::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 55 of file MixUnlabeledNeighbourVMatrix.cc.
| void PLearn::MixUnlabeledNeighbourVMatrix::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares the class options.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 75 of file MixUnlabeledNeighbourVMatrix.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::SourceVMatrix::declareOptions(), frac, seed, and source_select.
{
// ### 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. Another possible flag to be combined with
// ### is OptionBase::nosave
declareOption(ol, "seed", &MixUnlabeledNeighbourVMatrix::seed, OptionBase::buildoption, "Random generator seed (>0) (exceptions : -1 = initialized from clock, 0 = no initialization).");
declareOption(ol, "source_select", &MixUnlabeledNeighbourVMatrix::source_select, OptionBase::buildoption, "The VMat containing the related examples.");
declareOption(ol, "frac", &MixUnlabeledNeighbourVMatrix::frac, OptionBase::buildoption, "Fraction of the bag of related examples to be randomly chosen");
// Now call the parent class' declareOptions
inherited::declareOptions(ol);
}

| static const PPath& PLearn::MixUnlabeledNeighbourVMatrix::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 89 of file MixUnlabeledNeighbourVMatrix.h.
:
//##### Protected Options ###############################################
| MixUnlabeledNeighbourVMatrix * PLearn::MixUnlabeledNeighbourVMatrix::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 55 of file MixUnlabeledNeighbourVMatrix.cc.
| void PLearn::MixUnlabeledNeighbourVMatrix::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. ### This function must be overridden in your class
Reimplemented from PLearn::SourceVMatrix.
Definition at line 217 of file MixUnlabeledNeighbourVMatrix.cc.
References indices, PLearn::VMatrix::inputsize(), PLearn::TVec< T >::isEmpty(), j, PLearn::VMatrix::length(), PLearn::TVec< T >::length(), PLearn::VMat::length(), MISSING_VALUE, neighbor_weights, PLearn::TVec< T >::resize(), row_buffer, sorted_source_select, PLearn::SourceVMatrix::source, PLearn::TVec< T >::subVec(), PLearn::VMatrix::targetsize(), PLearn::VMat::width(), and PLearn::VMatrix::width().
{
if (i < source->length()) {
row_buffer.resize(source->width());
source->getRow(i, row_buffer);
int rest_size = width() - inputsize() - targetsize();
int input_target_size = inputsize() + targetsize();
v.subVec(0, input_target_size)
<< row_buffer.subVec(0, input_target_size);
v.subVec(input_target_size, rest_size)
<< row_buffer.subVec(input_target_size + 1, rest_size);
} else {
sorted_source_select->getSubRow(indices[i - source->length()],0,
v.subVec(0,inputsize()));
for (int j=inputsize(); j < inputsize() + targetsize(); j++)
v[j]=MISSING_VALUE;
if (!neighbor_weights.isEmpty())
v[v.length() - 1] = neighbor_weights[i - source->length()];
}
}

| OptionList & PLearn::MixUnlabeledNeighbourVMatrix::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 55 of file MixUnlabeledNeighbourVMatrix.cc.
| OptionMap & PLearn::MixUnlabeledNeighbourVMatrix::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 55 of file MixUnlabeledNeighbourVMatrix.cc.
| RemoteMethodMap & PLearn::MixUnlabeledNeighbourVMatrix::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 55 of file MixUnlabeledNeighbourVMatrix.cc.
| void PLearn::MixUnlabeledNeighbourVMatrix::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 241 of file MixUnlabeledNeighbourVMatrix.cc.
References PLearn::deepCopyField(), indices, PLearn::SourceVMatrix::makeDeepCopyFromShallowCopy(), neighbor_weights, random_generator, row_buffer, sorted_source_select, and source_select.
{
inherited::makeDeepCopyFromShallowCopy(copies);
deepCopyField(indices, copies);
deepCopyField(source_select, copies);
deepCopyField(sorted_source_select, copies);
deepCopyField(random_generator, copies);
deepCopyField(row_buffer, copies);
deepCopyField(neighbor_weights, copies);
}

Reimplemented from PLearn::SourceVMatrix.
Definition at line 89 of file MixUnlabeledNeighbourVMatrix.h.
Definition at line 73 of file MixUnlabeledNeighbourVMatrix.h.
Referenced by build_(), and declareOptions().
Definition at line 71 of file MixUnlabeledNeighbourVMatrix.h.
Referenced by build_(), getNewRow(), and makeDeepCopyFromShallowCopy().
The weights for each neighbor (set equal to the weight of the original sample).
Definition at line 112 of file MixUnlabeledNeighbourVMatrix.h.
Referenced by build_(), getNewRow(), and makeDeepCopyFromShallowCopy().
Used to shuffle the related unlabeled examples.
Definition at line 103 of file MixUnlabeledNeighbourVMatrix.h.
Referenced by build_(), and makeDeepCopyFromShallowCopy().
Vec PLearn::MixUnlabeledNeighbourVMatrix::row_buffer [mutable, protected] |
Used to store temporary data.
Definition at line 108 of file MixUnlabeledNeighbourVMatrix.h.
Referenced by getNewRow(), and makeDeepCopyFromShallowCopy().
### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //!
Definition at line 70 of file MixUnlabeledNeighbourVMatrix.h.
Referenced by build_(), and declareOptions().
The sorted source_select.
Definition at line 106 of file MixUnlabeledNeighbourVMatrix.h.
Referenced by build_(), getNewRow(), and makeDeepCopyFromShallowCopy().
Definition at line 72 of file MixUnlabeledNeighbourVMatrix.h.
Referenced by build_(), declareOptions(), and makeDeepCopyFromShallowCopy().
1.7.4