PLearn 0.1
|
Mixes several underlying source VMat, with ponderation. More...
#include <MixtureVMatrix.h>
Public Member Functions | |
MixtureVMatrix () | |
Default constructor. | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual MixtureVMatrix * | 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_ () |
RowBufferedVMatrix. | |
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< VMat > | sources |
The sources to mix (with repetitions if needed) | |
TVec< int > | weights |
Weights of the different sources. | |
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 | |
int | n_sources |
sources.size() | |
int | period_length |
sum(weights) | |
TVec< int > | period |
Sequence of sources to select, ensuring the proportion of sources and their homogeneity. | |
TVec< int > | occurrences |
occurrences[i] is the count of element period[i] in period[0..i-1] | |
Private Types | |
typedef RowBufferedVMatrix | inherited |
Private Member Functions | |
void | build_ () |
This does the actual building. | |
void | buildPeriod () |
build period and occurrences |
Mixes several underlying source VMat, with ponderation.
Definition at line 52 of file MixtureVMatrix.h.
typedef RowBufferedVMatrix PLearn::MixtureVMatrix::inherited [private] |
Reimplemented from PLearn::RowBufferedVMatrix.
Definition at line 54 of file MixtureVMatrix.h.
PLearn::MixtureVMatrix::MixtureVMatrix | ( | ) |
Default constructor.
Definition at line 52 of file MixtureVMatrix.cc.
: n_sources(0), period_length(0) { }
string PLearn::MixtureVMatrix::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::RowBufferedVMatrix.
Definition at line 50 of file MixtureVMatrix.cc.
OptionList & PLearn::MixtureVMatrix::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::RowBufferedVMatrix.
Definition at line 50 of file MixtureVMatrix.cc.
RemoteMethodMap & PLearn::MixtureVMatrix::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::RowBufferedVMatrix.
Definition at line 50 of file MixtureVMatrix.cc.
Reimplemented from PLearn::RowBufferedVMatrix.
Definition at line 50 of file MixtureVMatrix.cc.
Object * PLearn::MixtureVMatrix::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 50 of file MixtureVMatrix.cc.
StaticInitializer MixtureVMatrix::_static_initializer_ & PLearn::MixtureVMatrix::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::RowBufferedVMatrix.
Definition at line 50 of file MixtureVMatrix.cc.
void PLearn::MixtureVMatrix::build | ( | ) | [virtual] |
Simply calls inherited::build() then build_().
Reimplemented from PLearn::VMatrix.
Definition at line 190 of file MixtureVMatrix.cc.
References PLearn::VMatrix::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::MixtureVMatrix::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::VMatrix.
Definition at line 106 of file MixtureVMatrix.cc.
References buildPeriod(), PLearn::TVec< T >::count(), PLearn::VMatrix::extrasize_, i, PLearn::VMatrix::inputsize_, PLearn::TVec< T >::length(), PLearn::VMatrix::length_, n_sources, occurrences, period, period_length, PLCHECK_MSG, PLearn::TVec< T >::resize(), PLearn::TVec< T >::size(), sources, PLearn::sum(), PLearn::VMatrix::targetsize_, PLearn::VMatrix::updateMtime(), weights, PLearn::VMatrix::weightsize_, PLearn::VMatrix::width(), and PLearn::VMatrix::width_.
Referenced by build().
{ n_sources = sources.size(); if (n_sources == 0) return; PLCHECK_MSG(sources.size() == weights.size(), "You should provide as many weights as sources"); PLCHECK_MSG(length_ >= 0, "You should provide a length greater than 0"); width_ = sources[0]->width(); for (int i=1; i<n_sources; i++) PLCHECK_MSG(sources[i]->width() == width_, "All sources should have the same width"); if (inputsize_<0 || targetsize_<0 || weightsize_<0 || extrasize_<0 || inputsize_ + targetsize_ + weightsize_ + extrasize_ != width_) { inputsize_ = sources[0]->inputsize(); targetsize_ = sources[0]->targetsize(); weightsize_ = sources[0]->weightsize(); extrasize_ = sources[0]->extrasize(); } period_length = sum(weights); period.resize(period_length); occurrences.resize(period_length); bool incorrect_period = false; for (int i=0; i<n_sources; i++) if (period.count(i) != weights[i]) { incorrect_period = true; break; } if (incorrect_period) buildPeriod(); for(int i=0;i<sources.length();i++) updateMtime(sources[i]); }
void PLearn::MixtureVMatrix::buildPeriod | ( | ) | [private] |
build period and occurrences
Definition at line 150 of file MixtureVMatrix.cc.
References PLearn::argmax(), PLearn::TVec< T >::count(), i, j, PLearn::max(), n_sources, occurrences, period, period_length, PLASSERT, PLearn::TVec< T >::subVec(), and weights.
Referenced by build_().
{ TVec<int> ideal_count(n_sources); TVec<int> actual_count(n_sources); TVec<int> sources_count(n_sources); for (int i=0; i<period_length; i++) { // Find the source that is the most underrepresented ideal_count += weights; int max = 0; int argmax = -1; for (int j=0; j<n_sources; j++) { if (ideal_count[j] - actual_count[j] > max) { argmax = j; max = ideal_count[j] - actual_count[j]; } } PLASSERT(argmax >= 0); period[i] = argmax; actual_count[argmax] += period_length; occurrences[i] = sources_count[argmax]; sources_count[argmax]++; } #ifdef BOUNDCHECK for (int i=0; i<n_sources; i++) { PLASSERT(period.count(i) == weights[i]); PLASSERT( (i==0 && occurrences[0]==0) || period.subVec(0,i-1).count(period[i]) == occurrences[i]); } #endif }
string PLearn::MixtureVMatrix::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 50 of file MixtureVMatrix.cc.
void PLearn::MixtureVMatrix::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares the class options.
Reimplemented from PLearn::VMatrix.
Definition at line 70 of file MixtureVMatrix.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::VMatrix::declareOptions(), PLearn::OptionBase::learntoption, n_sources, period, period_length, sources, and weights.
{ // declareOption(ol, "myoption", &MixtureVMatrix::myoption, // OptionBase::buildoption, // "Help text describing this option"); declareOption(ol, "sources", &MixtureVMatrix::sources, OptionBase::buildoption, "The VMat to mix"); declareOption(ol, "weights", &MixtureVMatrix::weights, OptionBase::buildoption, "Weights of the different sources.\n" "If weights[0]==2 and weights[1]==2, then there will be\n" "twice as many exambles coming from sources[0] than from\n" "sources[1], regardless of the sources' length." ); declareOption(ol, "n_sources", &MixtureVMatrix::n_sources, OptionBase::learntoption, "Number of sources"); declareOption(ol, "period_length", &MixtureVMatrix::period_length, OptionBase::learntoption, "sum(weights)"); declareOption(ol, "period", &MixtureVMatrix::period, OptionBase::learntoption, "Sequence of sources to select, ensuring the proportion of\n" "sources and their homogeneity ." ); // Now call the parent class' declareOptions inherited::declareOptions(ol); }
static const PPath& PLearn::MixtureVMatrix::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::RowBufferedVMatrix.
Definition at line 78 of file MixtureVMatrix.h.
:
//##### Protected Options ###############################################
MixtureVMatrix * PLearn::MixtureVMatrix::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::RowBufferedVMatrix.
Definition at line 50 of file MixtureVMatrix.cc.
Fill the vector 'v' with the content of the i-th row.
'v' is assumed to be the right size.
Implements PLearn::RowBufferedVMatrix.
Definition at line 58 of file MixtureVMatrix.cc.
References PLearn::VMatrix::length(), occurrences, period, period_length, sources, and weights.
{ // The source it comes from int source = period[i % period_length]; // The number of previous samples of the same source in the same period int occurrence = occurrences[i % period_length]; // The index in this source int index = (i/period_length)*weights[source] + occurrence; sources[source]->getRow(index % sources[source].length(), v); }
OptionList & PLearn::MixtureVMatrix::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 50 of file MixtureVMatrix.cc.
OptionMap & PLearn::MixtureVMatrix::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 50 of file MixtureVMatrix.cc.
RemoteMethodMap & PLearn::MixtureVMatrix::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 50 of file MixtureVMatrix.cc.
void PLearn::MixtureVMatrix::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::RowBufferedVMatrix.
Definition at line 196 of file MixtureVMatrix.cc.
References PLearn::deepCopyField(), PLearn::RowBufferedVMatrix::makeDeepCopyFromShallowCopy(), occurrences, period, sources, and weights.
{ inherited::makeDeepCopyFromShallowCopy(copies); deepCopyField(sources, copies); deepCopyField(weights, copies); deepCopyField(period, copies); deepCopyField(occurrences, copies); }
Reimplemented from PLearn::RowBufferedVMatrix.
Definition at line 78 of file MixtureVMatrix.h.
int PLearn::MixtureVMatrix::n_sources [protected] |
sources.size()
Definition at line 91 of file MixtureVMatrix.h.
Referenced by build_(), buildPeriod(), and declareOptions().
TVec<int> PLearn::MixtureVMatrix::occurrences [protected] |
occurrences[i] is the count of element period[i] in period[0..i-1]
Definition at line 101 of file MixtureVMatrix.h.
Referenced by build_(), buildPeriod(), getNewRow(), and makeDeepCopyFromShallowCopy().
TVec<int> PLearn::MixtureVMatrix::period [protected] |
Sequence of sources to select, ensuring the proportion of sources and their homogeneity.
Definition at line 98 of file MixtureVMatrix.h.
Referenced by build_(), buildPeriod(), declareOptions(), getNewRow(), and makeDeepCopyFromShallowCopy().
int PLearn::MixtureVMatrix::period_length [protected] |
sum(weights)
Definition at line 94 of file MixtureVMatrix.h.
Referenced by build_(), buildPeriod(), declareOptions(), and getNewRow().
The sources to mix (with repetitions if needed)
Definition at line 60 of file MixtureVMatrix.h.
Referenced by build_(), declareOptions(), getNewRow(), and makeDeepCopyFromShallowCopy().
Weights of the different sources.
If weights[0]==2 and weights[1]==2, then there will be twice as many exambles coming from sources[0] than from sources[1], regardless of the sources' length.
Definition at line 65 of file MixtureVMatrix.h.
Referenced by build_(), buildPeriod(), declareOptions(), getNewRow(), and makeDeepCopyFromShallowCopy().