PLearn 0.1
|
#include <IsomapTangentLearner.h>
Public Member Functions | |
IsomapTangentLearner () | |
Default constructor. | |
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 IsomapTangentLearner * | deepCopy (CopiesMap &copies) const |
virtual int | outputsize () const |
Returns the size of this learner's output, (which typically may depend on its inputsize(), targetsize() and set options). | |
virtual void | forget () |
(Re-)initializes the PLearner in its fresh state (that state may depend on the 'seed' option) And sets 'stage' back to 0 (this is the stage of a fresh learner!). | |
virtual void | train () |
The role of the train method is to bring the learner up to stage==nstages, updating the train_stats collector with training costs measured on-line in the process. | |
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 TVec< string > | getTestCostNames () const |
Returns the names of the costs computed by computeCostsFromOutpus (and thus the test method). | |
virtual TVec< string > | getTrainCostNames () const |
Returns the names of the objective costs that the train method computes and for which it updates the VecStatsCollector train_stats. | |
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 | n_comp |
int | knn |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declares this class' options. | |
Protected Attributes | |
Isomap | iso_learner |
Mat | k_xi_x_sorted |
Private Types | |
typedef PLearner | inherited |
Private Member Functions | |
void | build_ () |
This does the actual building. |
Definition at line 53 of file IsomapTangentLearner.h.
typedef PLearner PLearn::IsomapTangentLearner::inherited [private] |
Reimplemented from PLearn::PLearner.
Definition at line 58 of file IsomapTangentLearner.h.
PLearn::IsomapTangentLearner::IsomapTangentLearner | ( | ) |
Default constructor.
Definition at line 53 of file IsomapTangentLearner.cc.
string PLearn::IsomapTangentLearner::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::PLearner.
Definition at line 62 of file IsomapTangentLearner.cc.
OptionList & PLearn::IsomapTangentLearner::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::PLearner.
Definition at line 62 of file IsomapTangentLearner.cc.
RemoteMethodMap & PLearn::IsomapTangentLearner::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::PLearner.
Definition at line 62 of file IsomapTangentLearner.cc.
Reimplemented from PLearn::PLearner.
Definition at line 62 of file IsomapTangentLearner.cc.
Object * PLearn::IsomapTangentLearner::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 62 of file IsomapTangentLearner.cc.
StaticInitializer IsomapTangentLearner::_static_initializer_ & PLearn::IsomapTangentLearner::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::PLearner.
Definition at line 62 of file IsomapTangentLearner.cc.
void PLearn::IsomapTangentLearner::build | ( | ) | [virtual] |
Simply calls inherited::build() then build_().
Reimplemented from PLearn::PLearner.
Definition at line 111 of file IsomapTangentLearner.cc.
References PLearn::PLearner::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::IsomapTangentLearner::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::PLearner.
Definition at line 84 of file IsomapTangentLearner.cc.
References PLearn::Isomap::build(), iso_learner, knn, PLearn::Isomap::knn, n_comp, PLearn::KernelProjection::n_comp, PLearn::KernelProjection::setTrainingSet(), and PLearn::PLearner::train_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. iso_learner.knn = knn; iso_learner.n_comp = n_comp; if (train_set) iso_learner.setTrainingSet(train_set); iso_learner.build(); // peut etre qu'il faut un VectatsCollector // PP<VecStatsCollector> train_stats = new VecStatsCollector(); // learner->setTrainStatsCollector(train_stats); // learner->setTrainingSet(trainset); // learner->train(); }
string PLearn::IsomapTangentLearner::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 62 of file IsomapTangentLearner.cc.
void PLearn::IsomapTangentLearner::computeCostsFromOutputs | ( | const Vec & | input, |
const Vec & | output, | ||
const Vec & | target, | ||
Vec & | costs | ||
) | const [virtual] |
Computes the costs from already computed output.
Implements PLearn::PLearner.
Definition at line 271 of file IsomapTangentLearner.cc.
{ // Compute the costs from *already* computed output. // ... }
void PLearn::IsomapTangentLearner::computeOutput | ( | const Vec & | input, |
Vec & | output | ||
) | const [virtual] |
Computes the output from the input.
Reimplemented from PLearn::PLearner.
Definition at line 162 of file IsomapTangentLearner.cc.
References PLearn::KernelProjection::eigenvectors, i, PLearn::PLearner::inputsize(), iso_learner, j, k_xi_x_sorted, PLearn::KernelProjection::kernel, knn, PLearn::VMat::length(), PLearn::TMat< T >::length(), n_comp, PLearn::PLearner::n_examples, PLearn::norm(), PLearn::TMat< T >::subMatRows(), and PLearn::TMat< T >::toVec().
{ // Compute the output from the input. // int nout = outputsize(); // output.resize(nout); // ... // ici je recupere le GeodesicDistanceKernel PP<AdditiveNormalizationKernel> ank = dynamic_cast<AdditiveNormalizationKernel*>((Kernel*)iso_learner.kernel); PP<GeodesicDistanceKernel> gdk = dynamic_cast<GeodesicDistanceKernel*>((Kernel*)ank->source_kernel); // output.resize(outputsize()); Mat k_xi_x; //cout<<input<<endl; // on fait un knn+1 au cas ou on elve la premiere ligne un peu plus loin gdk->distance_kernel->computeNearestNeighbors(input, k_xi_x, knn+1); Mat k_xi_x_sorted; // we assume that the trainingset contains each exemple only one time // here we manage the case of computing tangent plane on a point of the training set if (k_xi_x(0,0) < 1e-9) k_xi_x_sorted = k_xi_x.subMatRows(1,k_xi_x.length() - 1); else k_xi_x_sorted = k_xi_x; //cout<<k_xi_x.subMatRows(1,knn); Mat result(n_comp,inputsize()); Vec dkdx(inputsize()); //dk/dx Vec temp(inputsize()); Vec term2(inputsize()); Vec term1(inputsize()); // Vec tangentVector(inputsize()); // = sum_i v_ik*dk(i)/dx int ngn; VMat trainset = ank->specify_dataset; int n_examples = trainset->length(); Mat diK_dx(n_examples,inputsize()); int i,j,nc; real D; term1<<0; // real seuil = 1e-9; for(j=0;j<n_examples;++j) { ngn = gdk->computeNearestGeodesicNeighbour(j, k_xi_x_sorted);// ngn minimise la distance geodesique entre input et j trainset->getRow(ngn,temp); temp << (input-temp); D = norm(temp) + gdk->geo_distances->get(j,ngn); // cout<<D<<endl; // probleme resolu: il faut appeler gdk->distance_kernel->compute... // cout<<" "<<D*D<<" "<<gdk->evaluate_i_x_from_distances(j,k_xi_x_sorted) <<endl; //if (norm(temp) > seuil) term1 += D*(temp)/norm(temp); } term1/=n_examples; for(i=0;i<n_examples;++i) { // get the nearest neighbor ngn = gdk->computeNearestGeodesicNeighbour(i, k_xi_x_sorted); // ngn minimise la distance geodesique entre input et i trainset->getRow(ngn,temp); //cout<<i<<"="<<ngn<<"-"<<int(k_xi_x_sorted(ngn,1))<<" "; temp << (input-temp); // temp = x-xN // cout<<gdk->evaluate_i_x(i,input,k_xi_x_sorted); // cout<<norm(temp)<<endl; term2<<0; D = norm(temp) + gdk->geo_distances->get(i,ngn); //if (norm(temp) > seuil) term2 = D*(temp)/norm(temp); // else // term2.fill(0); //cout<<term2<<endl; //cout<<sum; diK_dx(i) << (term1 - term2); // exactement la formule de NIPS //cout<<diK_dx(i); } for(nc=0;nc<n_comp;++nc) { // compute the corresponding vector with the Nystrom formula // d ek / dx = 1/n sum_i dK/dX // initialisation temp<<(0); for(i=0;i<n_examples;++i) { temp += (iso_learner.eigenvectors(nc,i) * diK_dx(i)); } // on ne normalise pas car c'est la direction vecteur qui nous interesse et pas sa norme // en plus on normalise tout a 1 dans matlab pour eviter les erreurs numériques. // result(nc)<<(temp/iso_learner.eigenvalues[nc]); result(nc)<<(temp); } //cout<<result; // toVec: a mettre dans l'aide output << result.toVec(); }
void PLearn::IsomapTangentLearner::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares this class' options.
Reimplemented from PLearn::PLearner.
Definition at line 64 of file IsomapTangentLearner.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::PLearner::declareOptions(), iso_learner, knn, PLearn::OptionBase::learntoption, and n_comp.
{ // ### 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", &IsomapTangentLearner::knn, OptionBase::buildoption, "Number of nearest neighbor taken into account"); declareOption(ol, "n_comp", &IsomapTangentLearner::n_comp, OptionBase::buildoption, "Number of Components"); declareOption(ol, "iso_learner", &IsomapTangentLearner::iso_learner, OptionBase::learntoption, "The Isomap Learner"); // Now call the parent class' declareOptions inherited::declareOptions(ol); }
static const PPath& PLearn::IsomapTangentLearner::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::PLearner.
Definition at line 124 of file IsomapTangentLearner.h.
IsomapTangentLearner * PLearn::IsomapTangentLearner::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::PLearner.
Definition at line 62 of file IsomapTangentLearner.cc.
void PLearn::IsomapTangentLearner::forget | ( | ) | [virtual] |
(Re-)initializes the PLearner in its fresh state (that state may depend on the 'seed' option) And sets 'stage' back to 0 (this is the stage of a fresh learner!).
(Re-)initialize the PLearner in its fresh state (that state may depend on the 'seed' option) And sets 'stage' back to 0 (this is the stage of a fresh learner!)
A typical forget() method should do the following:
Reimplemented from PLearn::PLearner.
Definition at line 140 of file IsomapTangentLearner.cc.
{ }
OptionList & PLearn::IsomapTangentLearner::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 62 of file IsomapTangentLearner.cc.
OptionMap & PLearn::IsomapTangentLearner::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 62 of file IsomapTangentLearner.cc.
RemoteMethodMap & PLearn::IsomapTangentLearner::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 62 of file IsomapTangentLearner.cc.
TVec< string > PLearn::IsomapTangentLearner::getTestCostNames | ( | ) | const [virtual] |
Returns the names of the costs computed by computeCostsFromOutpus (and thus the test method).
Implements PLearn::PLearner.
Definition at line 278 of file IsomapTangentLearner.cc.
{ // Return the names of the costs computed by computeCostsFromOutpus // (these may or may not be exactly the same as what's returned by getTrainCostNames). // ... return TVec<string>(); }
TVec< string > PLearn::IsomapTangentLearner::getTrainCostNames | ( | ) | const [virtual] |
Returns the names of the objective costs that the train method computes and for which it updates the VecStatsCollector train_stats.
Implements PLearn::PLearner.
Definition at line 286 of file IsomapTangentLearner.cc.
{ // Return the names of the objective costs that the train method computes and // for which it updates the VecStatsCollector train_stats // (these may or may not be exactly the same as what's returned by getTestCostNames). // ... return TVec<string>(); }
void PLearn::IsomapTangentLearner::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::PLearner.
Definition at line 118 of file IsomapTangentLearner.cc.
References PLearn::PLearner::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("IsomapTangentLearner::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!"); }
int PLearn::IsomapTangentLearner::outputsize | ( | ) | const [virtual] |
Returns the size of this learner's output, (which typically may depend on its inputsize(), targetsize() and set options).
Implements PLearn::PLearner.
Definition at line 133 of file IsomapTangentLearner.cc.
References PLearn::PLearner::inputsize(), and n_comp.
{ // Compute and return the size of this learner's output (which typically // may depend on its inputsize(), targetsize() and set options). return inputsize()*n_comp; }
void PLearn::IsomapTangentLearner::train | ( | ) | [virtual] |
The role of the train method is to bring the learner up to stage==nstages, updating the train_stats collector with training costs measured on-line in the process.
Implements PLearn::PLearner.
Definition at line 152 of file IsomapTangentLearner.cc.
References iso_learner, and PLearn::KernelProjection::train().
{ // The role of the train method is to bring the learner up to stage==nstages, // updating train_stats with training costs measured on-line in the process. iso_learner.train(); }
Reimplemented from PLearn::PLearner.
Definition at line 124 of file IsomapTangentLearner.h.
Isomap PLearn::IsomapTangentLearner::iso_learner [protected] |
Definition at line 68 of file IsomapTangentLearner.h.
Referenced by build_(), computeOutput(), declareOptions(), and train().
Mat PLearn::IsomapTangentLearner::k_xi_x_sorted [protected] |
Definition at line 69 of file IsomapTangentLearner.h.
Referenced by computeOutput().
Definition at line 74 of file IsomapTangentLearner.h.
Referenced by build_(), computeOutput(), and declareOptions().
Definition at line 73 of file IsomapTangentLearner.h.
Referenced by build_(), computeOutput(), declareOptions(), and outputsize().