|
PLearn 0.1
|
#include <BootstrapVMatrix.h>


Public Member Functions | |
| BootstrapVMatrix () | |
| Default constructor. | |
| BootstrapVMatrix (VMat m, real frac, bool shuffle=false, int32_t the_seed=1827, bool allow_rep=false) | |
| Construct a boostrap of another VMatrix. | |
| BootstrapVMatrix (VMat m, real frac, PP< PRandom > the_rgen, bool shuffle=false, bool allow_rep=false) | |
| Constructor which takes directly a PRandom object instead of a seed. | |
| virtual string | classname () const |
| virtual OptionList & | getOptionList () const |
| virtual OptionMap & | getOptionMap () const |
| virtual RemoteMethodMap & | getRemoteMethodMap () const |
| virtual BootstrapVMatrix * | 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_ () |
| BootstrapVMatrix. | |
| 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 | |
| PP< PRandom > | rgen |
| Public build options. | |
| real | frac |
| int | n_elems |
| bool | operate_on_bags |
| int32_t | own_seed |
| int32_t | seed |
| bool | shuffle |
| bool | allow_repetitions |
Static Public Attributes | |
| static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
| static void | declareOptions (OptionList &ol) |
| Declares this class' options. | |
Private Types | |
| typedef SelectRowsVMatrix | inherited |
Private Member Functions | |
| void | build_ () |
| This does the actual building. | |
Definition at line 51 of file BootstrapVMatrix.h.
typedef SelectRowsVMatrix PLearn::BootstrapVMatrix::inherited [private] |
Reimplemented from PLearn::SelectRowsVMatrix.
Definition at line 53 of file BootstrapVMatrix.h.
| PLearn::BootstrapVMatrix::BootstrapVMatrix | ( | ) |
Default constructor.
Definition at line 58 of file BootstrapVMatrix.cc.
:
rgen(new PRandom()),
frac(0.6667),
n_elems(-1),
operate_on_bags(false),
own_seed(-3), // Temporary hack value to detect use of deprecated option.
seed(1827), // Default fixed seed value (safer than time-dependent).
shuffle(false),
allow_repetitions(false)
{}
| PLearn::BootstrapVMatrix::BootstrapVMatrix | ( | VMat | m, |
| real | frac, | ||
| bool | shuffle = false, |
||
| int32_t | the_seed = 1827, |
||
| bool | allow_rep = false |
||
| ) |
Construct a boostrap of another VMatrix.
Definition at line 69 of file BootstrapVMatrix.cc.
References build(), m, and PLearn::SourceVMatrix::source.
:
rgen(new PRandom()),
frac(the_frac),
n_elems(-1),
operate_on_bags(false),
own_seed(-3),
seed(the_seed),
shuffle(the_shuffle),
allow_repetitions(allow_rep)
{
this->source = m;
build();
}

| PLearn::BootstrapVMatrix::BootstrapVMatrix | ( | VMat | m, |
| real | frac, | ||
| PP< PRandom > | the_rgen, | ||
| bool | shuffle = false, |
||
| bool | allow_rep = false |
||
| ) |
Constructor which takes directly a PRandom object instead of a seed.
Definition at line 84 of file BootstrapVMatrix.cc.
References build(), m, PLASSERT, seed, and PLearn::SourceVMatrix::source.
:
rgen(the_rgen),
frac(the_frac),
n_elems(-1),
operate_on_bags(false),
own_seed(-3),
shuffle(the_shuffle),
allow_repetitions(allow_rep)
{
PLASSERT( the_rgen );
// We obtain the seed value that was actually used to initialize the Boost
// random number generator, to ensure this VMat is always the same after
// consecutive builds.
seed = int32_t(the_rgen->get_the_seed());
this->source = m;
build();
}

| string PLearn::BootstrapVMatrix::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::SelectRowsVMatrix.
Definition at line 53 of file BootstrapVMatrix.cc.
| OptionList & PLearn::BootstrapVMatrix::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::SelectRowsVMatrix.
Definition at line 53 of file BootstrapVMatrix.cc.
| RemoteMethodMap & PLearn::BootstrapVMatrix::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::SelectRowsVMatrix.
Definition at line 53 of file BootstrapVMatrix.cc.
Reimplemented from PLearn::SelectRowsVMatrix.
Definition at line 53 of file BootstrapVMatrix.cc.
| Object * PLearn::BootstrapVMatrix::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::SelectRowsVMatrix.
Definition at line 53 of file BootstrapVMatrix.cc.
| StaticInitializer BootstrapVMatrix::_static_initializer_ & PLearn::BootstrapVMatrix::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::SelectRowsVMatrix.
Definition at line 53 of file BootstrapVMatrix.cc.
| void PLearn::BootstrapVMatrix::build | ( | ) | [virtual] |
Simply calls inherited::build() then build_().
Reimplemented from PLearn::SelectRowsVMatrix.
Definition at line 148 of file BootstrapVMatrix.cc.
References PLearn::SelectRowsVMatrix::build(), and build_().
Referenced by BootstrapVMatrix(), and PLearn::Preprocessing::manageTrainTestUnknownSets().
{
inherited::build();
build_();
}


| void PLearn::BootstrapVMatrix::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::SelectRowsVMatrix.
Definition at line 157 of file BootstrapVMatrix.cc.
References allow_repetitions, PLearn::TVec< T >::append(), PLearn::SelectRowsVMatrix::build(), PLearn::TVec< T >::copy(), frac, PLearn::VMat::getExample(), i, PLearn::SelectRowsVMatrix::indices, PLearn::is_equal(), PLearn::TVec< T >::lastElement(), PLearn::TVec< T >::length(), PLearn::VMat::length(), PLearn::min(), n_elems, operate_on_bags, own_seed, PLASSERT, PLDEPRECATED, PLearn::TVec< T >::resize(), rgen, PLearn::SelectRowsVMatrix::rows_to_remove, seed, shuffle, PLearn::TVec< T >::size(), PLearn::sortElements(), PLearn::SourceVMatrix::source, PLearn::TVec< T >::subVec(), PLearn::VMatrix::updateMtime(), and PLearn::SelectRowsVMatrix::warn_if_all_rows_selected.
Referenced by build().
{
if (source)
{
updateMtime(source);
// Ensure we are not using the deprecated 'own_seed' option.
if (own_seed != -3) {
PLDEPRECATED("In BootstrapVMatrix::build_ - The 'own_seed' option "
"is deprecated: please use 'seed' instead");
PLASSERT( seed == 0 ); // Old default value for 'seed' was 0.
seed = own_seed;
own_seed = -3;
}
// Initialize RNG.
rgen->manual_seed(seed);
// Create bootstrap sample.
int l= source.length();
TVec< TVec<int> > bag_to_indices;
if (operate_on_bags) {
// Analyze bags in the source.
Vec input, target;
real weight;
for (int i = 0; i < l; i++) {
source->getExample(i, input, target, weight);
#ifndef NDEBUG
// Safety checks on bag information.
real bi = target.lastElement();
PLASSERT( is_equal(round(bi), bi) );
int bii = int(round(bi));
PLASSERT( bii >= 0 && bii <= 3 );
#endif
int bag_info = int(round(target.lastElement()));
if (bag_info % 2 == 1)
bag_to_indices.append(TVec<int>());
bag_to_indices.lastElement().append(i);
}
l = bag_to_indices.length();
}
int nsamp= (n_elems >= 0) ? n_elems : int(round(frac*l));
if(allow_repetitions)
{
indices.resize(nsamp);
for(int i= 0; i < nsamp; ++i)
indices[i]= rgen->uniform_multinomial_sample(l);
}
else
{
indices = TVec<int>(0, l-1, 1); // Range-vector
rgen->shuffleElements(indices);
indices = indices.subVec(0, min(indices.size(), nsamp));
}
if (!shuffle)
sortElements(indices);
if (operate_on_bags) {
// Convert bag indices back to sample indices.
TVec<int> bag_indices = indices.copy();
indices.resize(0);
for (int i = 0; i < bag_indices.length(); i++)
indices.append(bag_to_indices[bag_indices[i]]);
}
//if we only shuffle the rows, we remove a useless warning.
if(frac == 1 && allow_repetitions == 0 && rows_to_remove == 0 && shuffle == 1)
warn_if_all_rows_selected=false;
// Because we changed the indices, a rebuild may be needed.
inherited::build();
}
}


| string PLearn::BootstrapVMatrix::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::SelectRowsVMatrix.
Definition at line 53 of file BootstrapVMatrix.cc.
| void PLearn::BootstrapVMatrix::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares this class' options.
Reimplemented from PLearn::SelectRowsVMatrix.
Definition at line 108 of file BootstrapVMatrix.cc.
References PLearn::OptionBase::advanced_level, allow_repetitions, PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::SelectRowsVMatrix::declareOptions(), PLearn::OptionBase::deprecated_level, frac, PLearn::SelectRowsVMatrix::indices, PLearn::SelectRowsVMatrix::indices_vmat, PLearn::OptionBase::learntoption, n_elems, PLearn::OptionBase::nosave, operate_on_bags, own_seed, PLearn::redeclareOption(), seed, and shuffle.
{
declareOption(ol, "shuffle", &BootstrapVMatrix::shuffle, OptionBase::buildoption,
"If set to 1, the indices will be shuffled instead of being sorted.");
declareOption(ol, "frac", &BootstrapVMatrix::frac, OptionBase::buildoption,
"The fraction of elements we keep.");
declareOption(ol, "n_elems", &BootstrapVMatrix::n_elems, OptionBase::buildoption,
"The absolute number of elements we keep (will override 'frac' if provided).");
declareOption(ol, "seed", &BootstrapVMatrix::seed, OptionBase::buildoption,
"Random generator seed (-1 = from clock and 0 = no initialization).");
declareOption(ol, "allow_repetitions", &BootstrapVMatrix::allow_repetitions,
OptionBase::buildoption,
"Wether examples should be allowed to appear each more than once.",
OptionBase::advanced_level);
declareOption(ol, "operate_on_bags", &BootstrapVMatrix::operate_on_bags,
OptionBase::buildoption,
"Wether to operate on bags rather than individual samples (see help\n"
"of SumOverBagsVariable for details on bags).",
OptionBase::advanced_level);
declareOption(ol, "own_seed", &BootstrapVMatrix::own_seed,
(OptionBase::learntoption | OptionBase::nosave),
"DEPRECATED: old random generator seed",
OptionBase::deprecated_level);
inherited::declareOptions(ol);
// Hide the 'indices' option, because it will be overridden at build time.
redeclareOption(ol, "indices", &BootstrapVMatrix::indices, OptionBase::nosave,"");
redeclareOption(ol, "indices_vmat", &BootstrapVMatrix::indices_vmat, OptionBase::nosave,"");
}

| static const PPath& PLearn::BootstrapVMatrix::declaringFile | ( | ) | [inline, static] |
| BootstrapVMatrix * PLearn::BootstrapVMatrix::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::SelectRowsVMatrix.
Definition at line 53 of file BootstrapVMatrix.cc.
| OptionList & PLearn::BootstrapVMatrix::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::SelectRowsVMatrix.
Definition at line 53 of file BootstrapVMatrix.cc.
| OptionMap & PLearn::BootstrapVMatrix::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::SelectRowsVMatrix.
Definition at line 53 of file BootstrapVMatrix.cc.
| RemoteMethodMap & PLearn::BootstrapVMatrix::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::SelectRowsVMatrix.
Definition at line 53 of file BootstrapVMatrix.cc.
| void PLearn::BootstrapVMatrix::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::SelectRowsVMatrix.
Definition at line 235 of file BootstrapVMatrix.cc.
References PLearn::deepCopyField(), PLearn::SelectRowsVMatrix::makeDeepCopyFromShallowCopy(), and rgen.
{
inherited::makeDeepCopyFromShallowCopy(copies);
deepCopyField(rgen, copies);
}

Reimplemented from PLearn::SelectRowsVMatrix.
Definition at line 85 of file BootstrapVMatrix.h.
Definition at line 68 of file BootstrapVMatrix.h.
Referenced by build_(), and declareOptions().
Definition at line 62 of file BootstrapVMatrix.h.
Referenced by build_(), declareOptions(), and PLearn::Preprocessing::manageTrainTestUnknownSets().
Definition at line 63 of file BootstrapVMatrix.h.
Referenced by build_(), and declareOptions().
Definition at line 64 of file BootstrapVMatrix.h.
Referenced by build_(), and declareOptions().
Definition at line 65 of file BootstrapVMatrix.h.
Referenced by build_(), declareOptions(), and PLearn::Preprocessing::manageTrainTestUnknownSets().
Public build options.
Random number generator for shuffling the data.
Definition at line 60 of file BootstrapVMatrix.h.
Referenced by build_(), and makeDeepCopyFromShallowCopy().
| int32_t PLearn::BootstrapVMatrix::seed |
Definition at line 66 of file BootstrapVMatrix.h.
Referenced by BootstrapVMatrix(), build_(), and declareOptions().
Definition at line 67 of file BootstrapVMatrix.h.
Referenced by build_(), declareOptions(), and PLearn::Preprocessing::manageTrainTestUnknownSets().
1.7.4