PLearn 0.1
|
#include <NearestNeighborPredictionCost.h>
Public Member Functions | |
NearestNeighborPredictionCost () | |
Default constructor. | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual NearestNeighborPredictionCost * | deepCopy (CopiesMap &copies) const |
virtual void | build () |
Post-constructor. | |
void | run () |
Override this for runnable objects (default method issues a runtime error). | |
virtual void | makeDeepCopyFromShallowCopy (CopiesMap &copies) |
Transforms a shallow copy into a deep copy. | |
Static Public Member Functions | |
static string | _classname_ () |
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 | |
int | knn |
VMat | test_set |
string | learner_spec |
Vec | cost |
VMat | computed_outputs |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declares this class' options. | |
Protected Attributes | |
PP< PLearner > | learner |
Private Types | |
typedef Object | inherited |
Private Member Functions | |
void | build_ () |
This does the actual building. |
Definition at line 54 of file NearestNeighborPredictionCost.h.
typedef Object PLearn::NearestNeighborPredictionCost::inherited [private] |
Reimplemented from PLearn::Object.
Definition at line 59 of file NearestNeighborPredictionCost.h.
PLearn::NearestNeighborPredictionCost::NearestNeighborPredictionCost | ( | ) |
Default constructor.
Definition at line 57 of file NearestNeighborPredictionCost.cc.
: test_set(AutoVMatrix("/u/monperrm/data/amat/gauss2D_200_0p001_1.amat")) /* ### Initialize all fields to their default value */ { // ... // ### You may or may not want to call build_() to finish building the object // build_(); }
string PLearn::NearestNeighborPredictionCost::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 66 of file NearestNeighborPredictionCost.cc.
OptionList & PLearn::NearestNeighborPredictionCost::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 66 of file NearestNeighborPredictionCost.cc.
RemoteMethodMap & PLearn::NearestNeighborPredictionCost::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 66 of file NearestNeighborPredictionCost.cc.
Reimplemented from PLearn::Object.
Definition at line 66 of file NearestNeighborPredictionCost.cc.
Object * PLearn::NearestNeighborPredictionCost::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 66 of file NearestNeighborPredictionCost.cc.
StaticInitializer NearestNeighborPredictionCost::_static_initializer_ & PLearn::NearestNeighborPredictionCost::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 66 of file NearestNeighborPredictionCost.cc.
void PLearn::NearestNeighborPredictionCost::build | ( | ) | [virtual] |
Post-constructor.
The normal implementation should call simply inherited::build(), then this class's build_(). This method should be callable again at later times, after modifying some option fields to change the "architecture" of the object.
Reimplemented from PLearn::Object.
Definition at line 146 of file NearestNeighborPredictionCost.cc.
References PLearn::Object::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::NearestNeighborPredictionCost::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::Object.
Definition at line 92 of file NearestNeighborPredictionCost.cc.
References computed_outputs, cost, knn, learner, learner_spec, PLearn::VMat::length(), PLearn::Object::load(), PLearn::TVec< T >::resize(), and test_set.
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. PLearn::load(learner_spec,learner); learner->report_progress = false; cost.resize(knn); cost<<0; computed_outputs = new MemoryVMatrix(test_set->length(),learner->outputsize()); learner->use(test_set,computed_outputs); }
string PLearn::NearestNeighborPredictionCost::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 66 of file NearestNeighborPredictionCost.cc.
void PLearn::NearestNeighborPredictionCost::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares this class' options.
Reimplemented from PLearn::Object.
Definition at line 68 of file NearestNeighborPredictionCost.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::Object::declareOptions(), knn, learner_spec, and test_set.
{ // ### 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, "knn", &NearestNeighborPredictionCost::knn, OptionBase::buildoption, "Help text describing this option"); declareOption(ol, "test_set", &NearestNeighborPredictionCost::test_set, OptionBase::buildoption, "Help text describing this option"); declareOption(ol, "learner_spec", &NearestNeighborPredictionCost::learner_spec, OptionBase::buildoption, "Help text describing this option"); // ### ex: // declareOption(ol, "myoption", &NearestNeighborPredictionCost::myoption, OptionBase::buildoption, // "Help text describing this option"); // ... // Now call the parent class' declareOptions inherited::declareOptions(ol); }
static const PPath& PLearn::NearestNeighborPredictionCost::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::Object.
Definition at line 111 of file NearestNeighborPredictionCost.h.
NearestNeighborPredictionCost * PLearn::NearestNeighborPredictionCost::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 66 of file NearestNeighborPredictionCost.cc.
OptionList & PLearn::NearestNeighborPredictionCost::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 66 of file NearestNeighborPredictionCost.cc.
OptionMap & PLearn::NearestNeighborPredictionCost::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 66 of file NearestNeighborPredictionCost.cc.
RemoteMethodMap & PLearn::NearestNeighborPredictionCost::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 66 of file NearestNeighborPredictionCost.cc.
void PLearn::NearestNeighborPredictionCost::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::Object.
Definition at line 152 of file NearestNeighborPredictionCost.cc.
References PLearn::Object::makeDeepCopyFromShallowCopy(), and PLERROR.
{ inherited::makeDeepCopyFromShallowCopy(copies); // ### Call deepCopyField on all "pointer-like" fields // ### that you wish to be deepCopied rather than // ### shallow-copied. // ### ex: // deepCopyField(trainvec, copies); // ### Remove this line when you have fully implemented this method. PLERROR("NearestNeighborPredictionCost::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!"); }
void PLearn::NearestNeighborPredictionCost::run | ( | ) | [virtual] |
Override this for runnable objects (default method issues a runtime error).
Runnable objects are objects that can be used as *THE* object of a .plearn script. The run() method specifies what they should do when executed.
Reimplemented from PLearn::Object.
Definition at line 111 of file NearestNeighborPredictionCost.cc.
References computed_outputs, cost, PLearn::endl(), i, j, knn, learner, PLearn::VMat::length(), PLearn::local_neighbors_differences(), PLearn::min(), n, PLearn::projection_error(), test_set, and PLearn::VMat::width().
{ VMat targets_vmat; int l = test_set->length(); int n = test_set->width(); int n_dim = learner->outputsize() / test_set->width(); Var targets = Var(1,n); Var prediction = Var(n_dim,n); Var proj_err = projection_error(prediction, targets, 0, n); Func projection_error_f = Func(prediction & targets, proj_err); Vec temp(n_dim*n); Vec temp2(n); for (int j=0; j<knn; ++j) { targets_vmat = local_neighbors_differences(test_set, j+1, true); for (int i=0;i<l;++i) { computed_outputs->getRow(i,temp); targets_vmat->getRow(i,temp2); //cout<<temp2<<"/ "<<temp<<" "<<dot(temp,temp2)<<endl; //cout<<projection_error_f(temp,temp2)<<endl; cost[j]+=projection_error_f(temp,temp2); } } cost/=l; cout<<"Cost = "<<cost<<endl; cout<<min(cost)<<endl; // printf("%.12f",cost); }
Reimplemented from PLearn::Object.
Definition at line 111 of file NearestNeighborPredictionCost.h.
Definition at line 82 of file NearestNeighborPredictionCost.h.
Definition at line 81 of file NearestNeighborPredictionCost.h.
Definition at line 76 of file NearestNeighborPredictionCost.h.
Referenced by build_(), declareOptions(), and run().
PP<PLearner> PLearn::NearestNeighborPredictionCost::learner [protected] |
Definition at line 68 of file NearestNeighborPredictionCost.h.
Definition at line 78 of file NearestNeighborPredictionCost.h.
Referenced by build_(), and declareOptions().
Definition at line 77 of file NearestNeighborPredictionCost.h.
Referenced by build_(), declareOptions(), and run().