PLearn 0.1
|
#include <SelectInputSubsetLearner.h>
Public Member Functions | |
SelectInputSubsetLearner () | |
virtual void | build () |
Simply calls inherited::build() then build_(). | |
virtual void | makeDeepCopyFromShallowCopy (CopiesMap &copies) |
Transforms a shallow copy into a deep copy. | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual SelectInputSubsetLearner * | deepCopy (CopiesMap &copies) const |
virtual int | inputsize () const |
Forwarded to inner learner. | |
virtual void | computeOutput (const Vec &input, Vec &output) const |
Computes the output from the input. | |
virtual void | computeCostsFromOutputs (const Vec &input, const Vec &output, const Vec &target, Vec &costs) const |
Computes the costs from already computed output. | |
virtual void | computeOutputAndCosts (const Vec &input, const Vec &target, Vec &output, Vec &costs) const |
Forwarded to inner learner. | |
virtual void | setTrainingSet (VMat training_set, bool call_forget=true) |
Forwarded to inner learner. | |
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< int > | selected_inputs |
real | random_fraction |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declares this class' options. | |
Protected Attributes | |
Vec | learner_inputs |
TVec< int > | all_indices |
Private Types | |
typedef EmbeddedLearner | inherited |
Private Member Functions | |
void | build_ () |
This does the actual building. |
Definition at line 52 of file SelectInputSubsetLearner.h.
typedef EmbeddedLearner PLearn::SelectInputSubsetLearner::inherited [private] |
Reimplemented from PLearn::EmbeddedLearner.
Definition at line 57 of file SelectInputSubsetLearner.h.
PLearn::SelectInputSubsetLearner::SelectInputSubsetLearner | ( | ) |
Definition at line 50 of file SelectInputSubsetLearner.cc.
: random_fraction(0) /* ### Initialize all fields to their default value here */ { }
string PLearn::SelectInputSubsetLearner::_classname_ | ( | ) | [static] |
Declares name and deepCopy methods.
Reimplemented from PLearn::EmbeddedLearner.
Definition at line 58 of file SelectInputSubsetLearner.cc.
OptionList & PLearn::SelectInputSubsetLearner::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::EmbeddedLearner.
Definition at line 58 of file SelectInputSubsetLearner.cc.
RemoteMethodMap & PLearn::SelectInputSubsetLearner::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::EmbeddedLearner.
Definition at line 58 of file SelectInputSubsetLearner.cc.
Reimplemented from PLearn::EmbeddedLearner.
Definition at line 58 of file SelectInputSubsetLearner.cc.
Object * PLearn::SelectInputSubsetLearner::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::EmbeddedLearner.
Definition at line 58 of file SelectInputSubsetLearner.cc.
StaticInitializer SelectInputSubsetLearner::_static_initializer_ & PLearn::SelectInputSubsetLearner::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::EmbeddedLearner.
Definition at line 58 of file SelectInputSubsetLearner.cc.
void PLearn::SelectInputSubsetLearner::build | ( | ) | [virtual] |
Simply calls inherited::build() then build_().
Reimplemented from PLearn::EmbeddedLearner.
Definition at line 95 of file SelectInputSubsetLearner.cc.
References PLearn::EmbeddedLearner::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::SelectInputSubsetLearner::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::EmbeddedLearner.
Definition at line 80 of file SelectInputSubsetLearner.cc.
References i, PLearn::PLearner::inputsize_, PLearn::EmbeddedLearner::learner_, learner_inputs, PLearn::TVec< T >::length(), random_fraction, PLearn::TVec< T >::resize(), selected_inputs, and PLearn::shuffleElements().
Referenced by build().
{ if (random_fraction>0 && learner_ && inputsize_>0 && selected_inputs.length()==0) { int n_selected = int(rint(random_fraction*inputsize_)); selected_inputs.resize(inputsize_); for (int i=0;i<n_selected;i++) selected_inputs[i]=i; shuffleElements(selected_inputs); selected_inputs.resize(n_selected); } learner_inputs.resize(selected_inputs.length()); }
string PLearn::SelectInputSubsetLearner::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::EmbeddedLearner.
Definition at line 58 of file SelectInputSubsetLearner.cc.
void PLearn::SelectInputSubsetLearner::computeCostsFromOutputs | ( | const Vec & | input, |
const Vec & | output, | ||
const Vec & | target, | ||
Vec & | costs | ||
) | const [virtual] |
Computes the costs from already computed output.
Reimplemented from PLearn::EmbeddedLearner.
Definition at line 126 of file SelectInputSubsetLearner.cc.
References i, PLearn::EmbeddedLearner::learner_, learner_inputs, PLearn::TVec< T >::length(), and selected_inputs.
{ // Compute the costs from *already* computed output. for (int i=0;i<learner_inputs.length();i++) learner_inputs[i] = input[selected_inputs[i]]; learner_->computeCostsFromOutputs(learner_inputs,output,target,costs); }
void PLearn::SelectInputSubsetLearner::computeOutput | ( | const Vec & | input, |
Vec & | output | ||
) | const [virtual] |
Computes the output from the input.
Reimplemented from PLearn::EmbeddedLearner.
Definition at line 119 of file SelectInputSubsetLearner.cc.
References i, PLearn::EmbeddedLearner::learner_, learner_inputs, PLearn::TVec< T >::length(), and selected_inputs.
{ for (int i=0;i<learner_inputs.length();i++) learner_inputs[i] = input[selected_inputs[i]]; learner_->computeOutput(learner_inputs,output); }
void PLearn::SelectInputSubsetLearner::computeOutputAndCosts | ( | const Vec & | input, |
const Vec & | target, | ||
Vec & | output, | ||
Vec & | costs | ||
) | const [virtual] |
Forwarded to inner learner.
Reimplemented from PLearn::EmbeddedLearner.
Definition at line 135 of file SelectInputSubsetLearner.cc.
References i, PLearn::EmbeddedLearner::learner_, learner_inputs, PLearn::TVec< T >::length(), and selected_inputs.
{ for (int i=0;i<learner_inputs.length();i++) learner_inputs[i] = input[selected_inputs[i]]; learner_->computeOutputAndCosts(learner_inputs, target, output, costs); }
void PLearn::SelectInputSubsetLearner::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares this class' options.
Reimplemented from PLearn::EmbeddedLearner.
Definition at line 60 of file SelectInputSubsetLearner.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::EmbeddedLearner::declareOptions(), random_fraction, and selected_inputs.
{ // ### 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, "selected_inputs", &SelectInputSubsetLearner::selected_inputs, OptionBase::buildoption, "List of selected inputs. If this option is set then random_fraction should not be set (or set to 0).\n"); declareOption(ol, "random_fraction", &SelectInputSubsetLearner::random_fraction, OptionBase::buildoption, "Fraction of the original inputs that is randomly selected.\n" "If 0 then the selected_inputs option should be set.\n" "If selected_inputs is provided (length>0) then this option is ignored.\n"); // Now call the parent class' declareOptions inherited::declareOptions(ol); }
static const PPath& PLearn::SelectInputSubsetLearner::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::EmbeddedLearner.
Definition at line 124 of file SelectInputSubsetLearner.h.
SelectInputSubsetLearner * PLearn::SelectInputSubsetLearner::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::EmbeddedLearner.
Definition at line 58 of file SelectInputSubsetLearner.cc.
OptionList & PLearn::SelectInputSubsetLearner::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::EmbeddedLearner.
Definition at line 58 of file SelectInputSubsetLearner.cc.
OptionMap & PLearn::SelectInputSubsetLearner::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::EmbeddedLearner.
Definition at line 58 of file SelectInputSubsetLearner.cc.
RemoteMethodMap & PLearn::SelectInputSubsetLearner::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::EmbeddedLearner.
Definition at line 58 of file SelectInputSubsetLearner.cc.
int PLearn::SelectInputSubsetLearner::inputsize | ( | ) | const [virtual] |
Forwarded to inner learner.
Reimplemented from PLearn::EmbeddedLearner.
Definition at line 115 of file SelectInputSubsetLearner.cc.
References PLearn::PLearner::inputsize_.
Referenced by setTrainingSet().
{ return inputsize_; }
void PLearn::SelectInputSubsetLearner::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::EmbeddedLearner.
Definition at line 102 of file SelectInputSubsetLearner.cc.
References all_indices, PLearn::deepCopyField(), learner_inputs, PLearn::EmbeddedLearner::makeDeepCopyFromShallowCopy(), and selected_inputs.
{ inherited::makeDeepCopyFromShallowCopy(copies); // ### Call deepCopyField on all "pointer-like" fields // ### that you wish to be deepCopied rather than // ### shallow-copied. // ### ex: deepCopyField(selected_inputs, copies); deepCopyField(all_indices, copies); deepCopyField(learner_inputs, copies); }
void PLearn::SelectInputSubsetLearner::setTrainingSet | ( | VMat | training_set, |
bool | call_forget = true |
||
) | [virtual] |
Forwarded to inner learner.
Reimplemented from PLearn::EmbeddedLearner.
Definition at line 143 of file SelectInputSubsetLearner.cc.
References all_indices, i, inputsize(), j, PLearn::EmbeddedLearner::learner_, PLearn::TVec< T >::length(), PLearn::TVec< T >::resize(), selected_inputs, PLearn::EmbeddedLearner::setTrainingSet(), and PLearn::VMat::width().
{ inherited::setTrainingSet(training_set,call_forget); int n_other_columns = training_set->width()-inputsize(); all_indices.resize(selected_inputs.length()+n_other_columns); for (int i=0;i<selected_inputs.length();i++) all_indices[i]=selected_inputs[i]; for (int j=0;j<n_other_columns;j++) all_indices[selected_inputs.length()+j]=inputsize()+j; VMat vm = new SelectColumnsVMatrix(training_set,all_indices); vm->defineSizes(selected_inputs.length(),training_set->targetsize(),training_set->weightsize()); learner_->setTrainingSet(vm,call_forget); }
Reimplemented from PLearn::EmbeddedLearner.
Definition at line 124 of file SelectInputSubsetLearner.h.
TVec<int> PLearn::SelectInputSubsetLearner::all_indices [protected] |
Definition at line 65 of file SelectInputSubsetLearner.h.
Referenced by makeDeepCopyFromShallowCopy(), and setTrainingSet().
Vec PLearn::SelectInputSubsetLearner::learner_inputs [protected] |
Definition at line 64 of file SelectInputSubsetLearner.h.
Referenced by build_(), computeCostsFromOutputs(), computeOutput(), computeOutputAndCosts(), and makeDeepCopyFromShallowCopy().
Definition at line 82 of file SelectInputSubsetLearner.h.
Referenced by build_(), and declareOptions().
Definition at line 78 of file SelectInputSubsetLearner.h.
Referenced by build_(), computeCostsFromOutputs(), computeOutput(), computeOutputAndCosts(), declareOptions(), makeDeepCopyFromShallowCopy(), and setTrainingSet().