PLearn 0.1
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Static Protected Member Functions | Protected Attributes | Private Types | Private Member Functions
PLearn::KPCATangentLearner Class Reference

#include <KPCATangentLearner.h>

Inheritance diagram for PLearn::KPCATangentLearner:
Inheritance graph
[legend]
Collaboration diagram for PLearn::KPCATangentLearner:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 KPCATangentLearner ()
 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 OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual KPCATangentLearnerdeepCopy (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 PPathdeclaringFile ()

Public Attributes

int n_comp
real sigma

Static Public Attributes

static StaticInitializer _static_initializer_

Static Protected Member Functions

static void declareOptions (OptionList &ol)
 Declares this class' options.

Protected Attributes

KernelPCA KPCA

Private Types

typedef PLearner inherited

Private Member Functions

void build_ ()
 This does the actual building.

Detailed Description

Definition at line 53 of file KPCATangentLearner.h.


Member Typedef Documentation

Reimplemented from PLearn::PLearner.

Definition at line 58 of file KPCATangentLearner.h.


Constructor & Destructor Documentation

PLearn::KPCATangentLearner::KPCATangentLearner ( )

Default constructor.

Definition at line 54 of file KPCATangentLearner.cc.

                                       : n_comp(2),sigma(1)
/* ### Initialize all fields to their default value here */
{
    // ...

    // ### You may or may not want to call build_() to finish building the object
    // build_();
}

Member Function Documentation

string PLearn::KPCATangentLearner::_classname_ ( ) [static]

Reimplemented from PLearn::PLearner.

Definition at line 63 of file KPCATangentLearner.cc.

OptionList & PLearn::KPCATangentLearner::_getOptionList_ ( ) [static]

Reimplemented from PLearn::PLearner.

Definition at line 63 of file KPCATangentLearner.cc.

RemoteMethodMap & PLearn::KPCATangentLearner::_getRemoteMethodMap_ ( ) [static]

Reimplemented from PLearn::PLearner.

Definition at line 63 of file KPCATangentLearner.cc.

bool PLearn::KPCATangentLearner::_isa_ ( const Object o) [static]

Reimplemented from PLearn::PLearner.

Definition at line 63 of file KPCATangentLearner.cc.

Object * PLearn::KPCATangentLearner::_new_instance_for_typemap_ ( ) [static]

Reimplemented from PLearn::Object.

Definition at line 63 of file KPCATangentLearner.cc.

StaticInitializer KPCATangentLearner::_static_initializer_ & PLearn::KPCATangentLearner::_static_initialize_ ( ) [static]

Reimplemented from PLearn::PLearner.

Definition at line 63 of file KPCATangentLearner.cc.

void PLearn::KPCATangentLearner::build ( ) [virtual]

Simply calls inherited::build() then build_().

Reimplemented from PLearn::PLearner.

Definition at line 97 of file KPCATangentLearner.cc.

References PLearn::PLearner::build(), and build_().

Here is the call graph for this function:

void PLearn::KPCATangentLearner::build_ ( ) [private]

This does the actual building.

Reimplemented from PLearn::PLearner.

Definition at line 85 of file KPCATangentLearner.cc.

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.
}

Here is the caller graph for this function:

string PLearn::KPCATangentLearner::classname ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 63 of file KPCATangentLearner.cc.

void PLearn::KPCATangentLearner::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 212 of file KPCATangentLearner.cc.

{
// Compute the costs from *already* computed output. 
// ...
}                                
void PLearn::KPCATangentLearner::computeOutput ( const Vec input,
Vec output 
) const [virtual]

Computes the output from the input.

Reimplemented from PLearn::PLearner.

Definition at line 151 of file KPCATangentLearner.cc.

References PLearn::KernelProjection::eigenvectors, i, PLearn::PLearner::inputsize(), j, PLearn::KernelProjection::kernel, KPCA, PLearn::VMat::length(), n_comp, PLearn::PLearner::n_examples, sigma, PLearn::sum(), and PLearn::TMat< T >::toVec().

{
    PP<AdditiveNormalizationKernel> ank = dynamic_cast<AdditiveNormalizationKernel*>((Kernel*)KPCA.kernel);  
    PP<GaussianKernel> gk = dynamic_cast<GaussianKernel*>((Kernel*)ank->source_kernel);
  
    VMat trainset = ank->specify_dataset;
    int n_examples = trainset->length();
    Mat result(n_comp,inputsize());
  
    Vec dkdx(inputsize()); //dk/dx
    Vec temp(inputsize());
    Vec term2(inputsize());
    Vec sum(inputsize());
    Mat diK_dx(n_examples,inputsize());
  
    int i,j,nc;
  
    sum<<0;
    for(j=0;j<n_examples;++j) {
        trainset->getRow(j,temp);
        //real nt = norm(input-temp);
        // le noyau me renvoie ce que je veux mais les valeurs sont toutes petites: pb de sigma
        //cout<<gk->evaluate(temp,input)<<" "<<exp(-(nt*nt)/(sigma*sigma))<<endl;
        sum += gk->evaluate(temp,input)*(input-temp)/(sigma*sigma);
    }

  
    for(i=0;i<n_examples;++i)  {
        trainset->getRow(i,temp);
        term2 << gk->evaluate(temp,input)*(input-temp)/(sigma*sigma);      
        //cout<<term2<<endl;
        //cout<<sum;
        diK_dx(i) << (term2 - sum/n_examples); // on a le moins qui vient du moins de la dérivation de de exp(-)
        //diK_dx(i) << (sum/n_examples - 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 += (KPCA.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();
  
}

Here is the call graph for this function:

void PLearn::KPCATangentLearner::declareOptions ( OptionList ol) [static, protected]

Declares this class' options.

Reimplemented from PLearn::PLearner.

Definition at line 65 of file KPCATangentLearner.cc.

References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::PLearner::declareOptions(), KPCA, PLearn::OptionBase::learntoption, n_comp, and sigma.

{
    // ### 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, "sigma", &KPCATangentLearner::sigma, OptionBase::buildoption,
                  "Sigma");
    declareOption(ol, "n_comp", &KPCATangentLearner::n_comp, OptionBase::buildoption,
                  "Number of Components");
    declareOption(ol, "KPCA", &KPCATangentLearner::KPCA, OptionBase::learntoption,
                  "");
  
    // Now call the parent class' declareOptions
    inherited::declareOptions(ol);
}

Here is the call graph for this function:

static const PPath& PLearn::KPCATangentLearner::declaringFile ( ) [inline, static]

Reimplemented from PLearn::PLearner.

Definition at line 122 of file KPCATangentLearner.h.

KPCATangentLearner * PLearn::KPCATangentLearner::deepCopy ( CopiesMap copies) const [virtual]

Reimplemented from PLearn::PLearner.

Definition at line 63 of file KPCATangentLearner.cc.

void PLearn::KPCATangentLearner::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:

  • initialize a random number generator with the seed option
  • initialize the learner's parameters, using this random generator
  • stage = 0

Reimplemented from PLearn::PLearner.

Definition at line 126 of file KPCATangentLearner.cc.

{

}
OptionList & PLearn::KPCATangentLearner::getOptionList ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 63 of file KPCATangentLearner.cc.

OptionMap & PLearn::KPCATangentLearner::getOptionMap ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 63 of file KPCATangentLearner.cc.

RemoteMethodMap & PLearn::KPCATangentLearner::getRemoteMethodMap ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 63 of file KPCATangentLearner.cc.

TVec< string > PLearn::KPCATangentLearner::getTestCostNames ( ) const [virtual]

Returns the names of the costs computed by computeCostsFromOutpus (and thus the test method).

Implements PLearn::PLearner.

Definition at line 219 of file KPCATangentLearner.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::KPCATangentLearner::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 227 of file KPCATangentLearner.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::KPCATangentLearner::makeDeepCopyFromShallowCopy ( CopiesMap copies) [virtual]

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::PLearner.

Definition at line 104 of file KPCATangentLearner.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("KPCATangentLearner::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!");
}

Here is the call graph for this function:

int PLearn::KPCATangentLearner::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 119 of file KPCATangentLearner.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;
}

Here is the call graph for this function:

void PLearn::KPCATangentLearner::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 138 of file KPCATangentLearner.cc.

References PLearn::KernelPCA::build(), KPCA, PLearn::KernelPCA::kpca_kernel, n_comp, PLearn::KernelProjection::n_comp, PLearn::KernelProjection::setTrainingSet(), sigma, PLearn::KernelProjection::train(), and PLearn::PLearner::train_set.

{
    // 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.
    KPCA.n_comp = n_comp;
    KPCA.kpca_kernel = new GaussianKernel(sigma);
    if (train_set)
        KPCA.setTrainingSet(train_set);
    KPCA.build();
    KPCA.train();
}

Here is the call graph for this function:


Member Data Documentation

Reimplemented from PLearn::PLearner.

Definition at line 122 of file KPCATangentLearner.h.

Definition at line 68 of file KPCATangentLearner.h.

Referenced by computeOutput(), declareOptions(), and train().

Definition at line 71 of file KPCATangentLearner.h.

Referenced by computeOutput(), declareOptions(), outputsize(), and train().

Definition at line 72 of file KPCATangentLearner.h.

Referenced by computeOutput(), declareOptions(), and train().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines