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

The first sentence should be a BRIEF DESCRIPTION of what the class does. More...

#include <DiverseComponentAnalysis.h>

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

List of all members.

Public Member Functions

 DiverseComponentAnalysis ()
 Default constructor.
Mat getVarValue (string varname) const
 Returns the value of the var with the specified name (searched in VarArray allvars)
Mat getVarGradient (string varname) const
 Returns the gradient of the var with the specified name (searched in VarArray allvars)
TVec< string > listVarNames () const
 Returns the names of all vars (in VarArray allvars)
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< std::string > getTestCostNames () const
 Returns the names of the costs computed by computeCostsFromOutpus (and thus the test method).
virtual TVec< std::string > getTrainCostNames () const
 Returns the names of the objective costs that the train method computes and for which it updates the VecStatsCollector train_stats.
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual DiverseComponentAnalysisdeepCopy (CopiesMap &copies) const
virtual void build ()
 Finish building the object; just call inherited::build followed by build_()
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 PPathdeclaringFile ()

Public Attributes

int ncomponents
 ### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //!
string nonlinearity
string cov_transformation_type
double diag_add
double diag_premul
double offdiag_premul
string diag_nonlinearity
string offdiag_nonlinearity
double diag_weight
double offdiag_weight
bool force_zero_mean
real epsilon
real nu
real constrain_norm_type
bool normalize
PP< Optimizeroptimizer
Vec mu
 The (weighted) mean of the samples.
Var Cx
 The (weighted) covariance matrix of the samples.
Var W
 A ncomponents x inputsize matrix containing the projection directions.
Var Cy
 The covariance of transformed data Cy = cov(W x) = W Cx W^T.
Var Cyt
 The "transformed" covariance according to cov_transformation_type.
Var L
 The loss variable: sum(asCy)
Vec inv_stddev_of_projections
Var inputdata
Var bias
Var trdata
Var ctrdata

Static Public Attributes

static StaticInitializer _static_initializer_

Static Protected Member Functions

static void declareOptions (OptionList &ol)
 Declares the class options.
static void declareMethods (RemoteMethodMap &rmm)
 Declare the methods that are remote-callable.
static Var nonlinear_transform (Var in, string nonlinearity)

Private Types

typedef PLearner inherited

Private Member Functions

void build_ ()
 This does the actual building.

Private Attributes

VarArray allvars

Detailed Description

The first sentence should be a BRIEF DESCRIPTION of what the class does.

Place the rest of the class programmer documentation here. Doxygen supports Javadoc-style comments. See http://www.doxygen.org/manual.html

Todo:
Write class to-do's here if there are any.
Deprecated:
Write deprecated stuff here if there is any. Indicate what else should be used instead.

Definition at line 59 of file DiverseComponentAnalysis.h.


Member Typedef Documentation

Reimplemented from PLearn::PLearner.

Definition at line 61 of file DiverseComponentAnalysis.h.


Constructor & Destructor Documentation

PLearn::DiverseComponentAnalysis::DiverseComponentAnalysis ( )

Default constructor.

Definition at line 76 of file DiverseComponentAnalysis.cc.

References PLearn::PLearner::random_gen.

    :ncomponents(2),
     nonlinearity("none"),
     cov_transformation_type("cov"),
     diag_add(0.),
     diag_premul(1.0),
     offdiag_premul(1.0),
     diag_nonlinearity("square"),
     offdiag_nonlinearity("square"),
     diag_weight(-1.0),
     offdiag_weight(1.0),
     force_zero_mean(false),
     epsilon(1e-8),
     nu(0),
     constrain_norm_type(-2),
     normalize(false)
/* ### Initialize all fields to their default value here */
{
    // ### If this learner needs to generate random numbers, uncomment the
    // ### line below to enable the use of the inherited PRandom object.
    random_gen = new PRandom();
}

Member Function Documentation

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

Reimplemented from PLearn::PLearner.

Definition at line 74 of file DiverseComponentAnalysis.cc.

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

Reimplemented from PLearn::PLearner.

Definition at line 74 of file DiverseComponentAnalysis.cc.

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

Reimplemented from PLearn::PLearner.

Definition at line 74 of file DiverseComponentAnalysis.cc.

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

Reimplemented from PLearn::PLearner.

Definition at line 74 of file DiverseComponentAnalysis.cc.

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

Reimplemented from PLearn::Object.

Definition at line 74 of file DiverseComponentAnalysis.cc.

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

Reimplemented from PLearn::PLearner.

Definition at line 74 of file DiverseComponentAnalysis.cc.

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

Finish building the object; just call inherited::build followed by build_()

Reimplemented from PLearn::PLearner.

Definition at line 425 of file DiverseComponentAnalysis.cc.

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

Here is the call graph for this function:

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

This does the actual building.

Reimplemented from PLearn::PLearner.

Definition at line 272 of file DiverseComponentAnalysis.cc.

References allvars, bias, PLearn::columnSum(), constrain_norm_type, PLearn::cov2corr(), cov_transformation_type, ctrdata, Cx, Cy, Cyt, PLearn::diag(), diag_add, diag_nonlinearity, diag_premul, diag_weight, PLearn::endl(), PLearn::exp(), force_zero_mean, inputdata, PLearn::PLearner::inputsize_, PLearn::PP< T >::isNull(), L, PLearn::Var::length(), PLearn::VMat::length(), ncomponents, PLearn::nondiag(), nonlinear_transform(), nonlinearity, offdiag_nonlinearity, offdiag_premul, offdiag_weight, optimizer, PLearn::perr, PLERROR, PLearn::product(), PLearn::productTranspose(), PLearn::rowSumSquare(), PLearn::square(), PLearn::squareroot(), PLearn::sum(), PLearn::sumsquare(), PLearn::PLearner::train_set, PLearn::transpose(), PLearn::transposeProduct(), trdata, W, and PLearn::Var::width().

Referenced by build().

{
    perr << "Entering DiverseComponentAnalysis::build_()" << endl;
    bool rebuild_all = inputsize_>0 && (W.isNull() || (W->matValue.width()!=inputsize_));
    bool rebuild_some = inputsize_>0 && Cyt.isNull();
    bool linear = (nonlinearity=="none" || nonlinearity=="linear");
    if(rebuild_some || rebuild_all)
    {
        perr << "Building with inputsize_ = " << inputsize_ << endl;

        Var nW;
        
        if(constrain_norm_type==-1) // use constrainted source to constrain L1 norms to 1
        {
            perr << "using constrainted source to constrain L1 norms to 1" << endl;
            if(rebuild_all)
                W = new ConstrainedSourceVariable(ncomponents,inputsize_,1);
            nW = W;
        }
        else if(constrain_norm_type==-2) // use constrainted source to constrain L2 norms to 1
        {
            perr << "using constrainted source to constrain L2 norms to 1" << endl;
            if(rebuild_all)
                W = new ConstrainedSourceVariable(ncomponents,inputsize_,2);
            nW = W;
        }
        else if(constrain_norm_type==-3) // compute L2 normalization explicitly
        {
            perr << "Normalizing explicitly" << endl;
            if(rebuild_all)
                W = Var(ncomponents,inputsize_);
            nW = W/squareroot(rowSumSquare(W));
        }
        else  // using ordinary weight decay: nW is not hard-constrained to be normalized
        {
            perr << "Using ordinary weight decay " << constrain_norm_type << endl;
            if(rebuild_all)
                W = Var(ncomponents,inputsize_);
            nW = W;
        }

        if(linear) 
        {
            if(rebuild_all)
                Cx = Var(inputsize_,inputsize_);
            Cx->setName("Cx");
            Cy = product(nW, productTranspose(Cx, nW));
        }
        else // nonlinear trasform
        {
            int l = train_set->length();
            perr << "Building with nonlinear transform and l="<<l <<" examples of inputsize=" << inputsize_ << endl;

            inputdata = Var(l,inputsize_);
            if(rebuild_all)
                bias = Var(1, ncomponents);
            trdata = productTranspose(inputdata,nW)+bias;
            perr << "USING MAIN REPRESENTATION NONLINEARITY: " << nonlinearity << endl;
            trdata = nonlinear_transform(trdata,nonlinearity);
            if(force_zero_mean)
                ctrdata = trdata;
            else
                ctrdata = trdata-(1.0/l)*columnSum(trdata);
            ctrdata->setName("ctrdata");            
            trdata->setName("trdata");            
            Cy = (1.0/l)*transposeProduct(ctrdata,ctrdata);
        }
        perr << "Built Cy of size " << Cy->length() << "x" << Cy->width() << endl;

        if(cov_transformation_type=="cov")
            Cyt = Cy;
        else if(cov_transformation_type=="corr")
            Cyt = cov2corr(Cy,2);
        else if(cov_transformation_type=="squaredist")
        {
            Var dCy = diag(Cy);
            Cyt = Cy*(-2.0)+dCy+transpose(dCy);
        }
        else if(cov_transformation_type=="sincov")
        {
            Var dCy = diag(Cy);
            Cyt = squareroot(((1+1e-6)-square(cov2corr(Cy)))*dCy*transpose(dCy));            
            // Cyt = ((1.0-square(cov2corr(Cy)))*dCy*transpose(dCy));            
        }
        else 
            PLERROR("Invalid cov_transformation_type");

        if(diag_weight!=0)
        {
            Var diagelems = diag(Cyt);
            if(diag_add!=0)
                diagelems = diagelems+diag_add;
            L += diag_weight*sum(nonlinear_transform(diagelems*diag_premul,diag_nonlinearity));
        }
        if(offdiag_weight!=0)
            L += offdiag_weight*sum(nonlinear_transform(nondiag(Cyt)*offdiag_premul,offdiag_nonlinearity));
            
        if(constrain_norm_type>0)
            L += L+constrain_norm_type*exp(sumsquare(W));

        if(!optimizer)
            PLERROR("You must specify the optimizer field (ex: GradientOptimizer)");
        if(linear)
            optimizer->setToOptimize(W, L);
        else
            optimizer->setToOptimize(W&bias, L);
        
        perr << "Built optimizer" << endl;
        nW->setName("W");
        Cy->setName("Cy");
        Cyt->setName("Cyt");
        L->setName("L");

        allvars = Cx & trdata& ctrdata& nW & Cy & Cyt & L;
    }
    perr << "Exiting DiverseComponentAnalysis::build_()" << endl;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 74 of file DiverseComponentAnalysis.cc.

void PLearn::DiverseComponentAnalysis::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 576 of file DiverseComponentAnalysis.cc.

References PLearn::TVec< T >::resize().

{
    costs.resize(0);
}

Here is the call graph for this function:

void PLearn::DiverseComponentAnalysis::computeOutput ( const Vec input,
Vec output 
) const [virtual]

Computes the output from the input.

Reimplemented from PLearn::PLearner.

Definition at line 562 of file DiverseComponentAnalysis.cc.

References inv_stddev_of_projections, PLearn::TVec< T >::length(), mu, ncomponents, normalize, PLearn::product(), PLearn::TVec< T >::resize(), W, and x.

{
    static Vec x;
    x.resize(input.length());
    x << input;

    // Center and project on directions
    x -= mu;
    output.resize(ncomponents);
    product(output, W->matValue, x);
    if(normalize)
        output *= inv_stddev_of_projections;
}

Here is the call graph for this function:

void PLearn::DiverseComponentAnalysis::declareMethods ( RemoteMethodMap rmm) [static, protected]

Declare the methods that are remote-callable.

Reimplemented from PLearn::PLearner.

Definition at line 222 of file DiverseComponentAnalysis.cc.

References PLearn::PLearner::_getRemoteMethodMap_(), PLearn::declareMethod(), getVarGradient(), getVarValue(), PLearn::RemoteMethodMap::inherited(), and listVarNames().

{
    rmm.inherited(inherited::_getRemoteMethodMap_());

    declareMethod(rmm,
                  "getVarValue",
                  &DiverseComponentAnalysis::getVarValue,
                  (BodyDoc("Returns the matValue of the variable with the given name"),
                   ArgDoc("varname", "name of the variable searched for"),
                   RetDoc("Returns the value of the var as a Mat")));

    declareMethod(rmm,
                  "getVarGradient",
                  &DiverseComponentAnalysis::getVarGradient,
                  (BodyDoc("Returns the matGradient of the variable with the given name"),
                   ArgDoc("varname", "name of the variable searched for"),
                   RetDoc("Returns the gradient of the var as a Mat")));

    declareMethod(rmm,
                  "listVarNames",
                  &DiverseComponentAnalysis::listVarNames,
                  (BodyDoc("Returns a list of the names of all vars"),
                   RetDoc("Returns a list of the names of all vars")));

}

Here is the call graph for this function:

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

Declares the class options.

Reimplemented from PLearn::PLearner.

Definition at line 99 of file DiverseComponentAnalysis.cc.

References bias, PLearn::OptionBase::buildoption, constrain_norm_type, cov_transformation_type, Cx, PLearn::declareOption(), PLearn::PLearner::declareOptions(), diag_add, diag_nonlinearity, diag_premul, diag_weight, epsilon, force_zero_mean, inv_stddev_of_projections, PLearn::OptionBase::learntoption, mu, ncomponents, nonlinearity, normalize, nu, offdiag_nonlinearity, offdiag_premul, offdiag_weight, optimizer, and W.

{
    // ### 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. If you don't provide one of these three,
    // ### this option will be ignored when loading values from a script.
    // ### You can also combine flags, for example with OptionBase::nosave:
    // ### (OptionBase::buildoption | OptionBase::nosave)

    // ### ex:
    // declareOption(ol, "myoption", &DiverseComponentAnalysis::myoption,
    //               OptionBase::buildoption,
    //               "Help text describing this option");
    // ...

    declareOption(
        ol, "nonlinearity", &DiverseComponentAnalysis::nonlinearity, OptionBase::buildoption,
        "The nonlinearity to apply after linear transformation of the inputs to obtain the representation.");

    declareOption(
        ol, "force_zero_mean", &DiverseComponentAnalysis::force_zero_mean, OptionBase::buildoption,
        "If true then input mean won't be computes but forced to 0 (and a corresponding different covariance matrix will be computed)");

    declareOption(
        ol, "epsilon", &DiverseComponentAnalysis::epsilon, OptionBase::buildoption,
        "regularization value to add to diagonal of computed input covariance matrix.");

    declareOption(
        ol, "nu", &DiverseComponentAnalysis::nu, OptionBase::buildoption,
        "regularization parameter simulating destruction noise: \n"
        "off-diagonal elements of covariance matrix Cx will be multiplied by 1-nu.");

    declareOption(
        ol, "constrain_norm_type", &DiverseComponentAnalysis::constrain_norm_type, OptionBase::buildoption,
        "How to constrain the norms of rows of W: \n"
        "  -1: L1 norm constrained source \n"
        "  -2: L2 norm constrained source \n"
        "  -3:explicit L2 normalization \n"
        "  >0:add specified value times exp(sumsquare(W)) to the cost\n");

    declareOption(
        ol, "ncomponents", &DiverseComponentAnalysis::ncomponents, OptionBase::buildoption,
        "The number components to keep (that's also the outputsize).");

    declareOption(
        ol, "cov_transformation_type", &DiverseComponentAnalysis::cov_transformation_type, OptionBase::buildoption,
        "Controls the kind of transformation to apply to covariance matrix\n"
        "cov: no transformation (keep covariance)\n"
        "corr: transform into correlations, but keeping variances on the diagonal.\n"
        "squaredist: do a 'squared distance kernel' Dij <- Cii+Cjj-2Cij kind of transformation\n"
        "sincov: instead of ||u|| ||v|| cos(angle(u,v)) we transform it to ||u|| ||v|| |sin(angle(u,v))|\n"
        "        this is computed as sqrt((1-<u.v>^2) * <u,u>^2 * <v,v>^2) where <u,v> is given by the covariance matrix\n");

    declareOption(
        ol, "diag_add", &DiverseComponentAnalysis::diag_add, OptionBase::buildoption,
        "This value will be added to the diagonal (before premultiplying and applying non-linearity)");

    declareOption(
        ol, "diag_premul", &DiverseComponentAnalysis::diag_premul, OptionBase::buildoption,
        "diagonal elements of Cy will be pre-multiplied by diag_premul (before applying non-linearity)");

    declareOption(
        ol, "offdiag_premul", &DiverseComponentAnalysis::offdiag_premul, OptionBase::buildoption,
        "Non-diagonal elements of Cy will be pre-multiplied by diag_premul (before applying non-linearity)");

    declareOption(
        ol, "diag_nonlinearity", &DiverseComponentAnalysis::diag_nonlinearity, OptionBase::buildoption,
        "The kind of nonlinearity to apply to the diagonal elements of Cy\n"
        "after it's been through cov_transformation_type\n"
        "Currently supported: none square abs sqrt sqrtabs exp tanh sigmoid");

    declareOption(
        ol, "offdiag_nonlinearity", &DiverseComponentAnalysis::offdiag_nonlinearity, OptionBase::buildoption,
        "The kind of nonlinearity to apply to the non-diagonal elements of Cy \n"
        "after it's been through cov_transformation_type\n"
        "Currently supported: none square abs sqrt sqrtabs exp tanh sigmoid");

    declareOption(
        ol, "diag_weight", &DiverseComponentAnalysis::diag_weight, OptionBase::buildoption,
        "what weight to give to the sum of transformed diagonal elements in the cost");

    declareOption(
        ol, "offdiag_weight", &DiverseComponentAnalysis::offdiag_weight, OptionBase::buildoption,
        "what weight to give to the sum of transformed non-diagonal elements in the cost");

    declareOption(
        ol, "optimizer", &DiverseComponentAnalysis::optimizer, OptionBase::buildoption,
        "The gradient-based optimizer to use");

    declareOption(
        ol, "normalize", &DiverseComponentAnalysis::normalize, OptionBase::buildoption,
        "If true computed outputs will be scaled so they have unit variance.\n"
        "(see explanation about inv_stddev_of_projections)");


    // learnt options
    declareOption(
        ol, "mu", &DiverseComponentAnalysis::mu, OptionBase::learntoption,
        "The (weighted) mean of the samples");

    declareOption(
        ol, "Cx", &DiverseComponentAnalysis::Cx, OptionBase::learntoption,
        "The (weighted) covariance of the samples");

    declareOption(
        ol, "W", &DiverseComponentAnalysis::W, OptionBase::learntoption,
        "A ncomponents x inputsize matrix containing the learnt projection directions");

    declareOption(
        ol, "bias", &DiverseComponentAnalysis::bias, OptionBase::learntoption,
        "A 1 x ncomponents matrix containing the learnt bias (for the nonlinear case only)");

    declareOption(
        ol, "inv_stddev_of_projections", &DiverseComponentAnalysis::inv_stddev_of_projections, OptionBase::learntoption,
        "As its name implies, this is one over the standard deviation of projected data.\n"
        "when normalize=true computeOutput will multiply the projection by this,\n"
        " elementwise, so that the output should have unit variance" );

    // Now call the parent class' declareOptions
    inherited::declareOptions(ol);
}

Here is the call graph for this function:

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

Reimplemented from PLearn::PLearner.

Definition at line 201 of file DiverseComponentAnalysis.h.

:
    //#####  Protected Options  ###############################################
DiverseComponentAnalysis * PLearn::DiverseComponentAnalysis::deepCopy ( CopiesMap copies) const [virtual]

Reimplemented from PLearn::PLearner.

Definition at line 74 of file DiverseComponentAnalysis.cc.

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

  • call inherited::forget() to initialize its 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 446 of file DiverseComponentAnalysis.cc.

References constrain_norm_type, PLearn::endl(), PLearn::PLearner::forget(), i, PLearn::PLearner::inputsize_, ncomponents, PLearn::normalize(), PLearn::perr, PLearn::pownorm(), PLearn::PLearner::random_gen, and W.

{

    // this will reset stage=0 and reset the random_gen to the initial seed_
    inherited::forget();

    perr << "Called DCS::forget() with inputsize_ = " << inputsize_ << endl;
    if(inputsize_>0)
    {
        random_gen->fill_random_normal(W->value, 0., 1.);
        perr << "Squared norm of first row of W after fill_random_normal: " << pownorm(W->matValue(0)) << endl;
        int normval = (constrain_norm_type==-1 ?1 :2);
        for(int i=0; i<ncomponents; i++)
            PLearn::normalize(W->matValue(i), normval);
        perr << "Squared norm of first row of W after L" << normval << " normalization: " << pownorm(W->matValue(0)) << endl;
    }
}

Here is the call graph for this function:

OptionList & PLearn::DiverseComponentAnalysis::getOptionList ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 74 of file DiverseComponentAnalysis.cc.

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

Reimplemented from PLearn::Object.

Definition at line 74 of file DiverseComponentAnalysis.cc.

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

Reimplemented from PLearn::Object.

Definition at line 74 of file DiverseComponentAnalysis.cc.

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

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

Implements PLearn::PLearner.

Definition at line 582 of file DiverseComponentAnalysis.cc.

{
    return TVec<string>();
}
TVec< string > PLearn::DiverseComponentAnalysis::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 587 of file DiverseComponentAnalysis.cc.

{
    return TVec<string>(1,"L");
}
Mat PLearn::DiverseComponentAnalysis::getVarGradient ( string  varname) const

Returns the gradient of the var with the specified name (searched in VarArray allvars)

Definition at line 413 of file DiverseComponentAnalysis.cc.

References allvars, i, PLearn::PP< T >::isNotNull(), PLearn::TVec< T >::length(), and PLERROR.

Referenced by declareMethods().

{
    for(int i=0; i<allvars.length(); i++)
    {
        Var v = allvars[i];
        if(v.isNotNull() && v->getName()==varname)
            return v->matGradient;
    }
    PLERROR("No Var with name %s", varname.c_str());
    return Mat();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Mat PLearn::DiverseComponentAnalysis::getVarValue ( string  varname) const

Returns the value of the var with the specified name (searched in VarArray allvars)

Definition at line 401 of file DiverseComponentAnalysis.cc.

References allvars, i, PLearn::PP< T >::isNotNull(), PLearn::TVec< T >::length(), and PLERROR.

Referenced by declareMethods().

{
    for(int i=0; i<allvars.length(); i++)
    {
        Var v = allvars[i];        
        if(v.isNotNull() && v->getName()==varname)
            return v->matValue;
    }
    PLERROR("No Var with name %s", varname.c_str());
    return Mat();
}

Here is the call graph for this function:

Here is the caller graph for this function:

TVec< string > PLearn::DiverseComponentAnalysis::listVarNames ( ) const

Returns the names of all vars (in VarArray allvars)

Definition at line 391 of file DiverseComponentAnalysis.cc.

References allvars, PLearn::TVec< T >::append(), i, PLearn::TVec< T >::length(), and n.

Referenced by declareMethods().

{
    int n = allvars.length();
    TVec<string> names;
    for(int i=0; i<n; i++)
        if(allvars[i].isNotNull())
            names.append(allvars[i]->getName());
    return names;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void PLearn::DiverseComponentAnalysis::makeDeepCopyFromShallowCopy ( CopiesMap copies) [virtual]

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::PLearner.

Definition at line 432 of file DiverseComponentAnalysis.cc.

References Cx, PLearn::deepCopyField(), PLearn::PLearner::makeDeepCopyFromShallowCopy(), mu, and W.

Here is the call graph for this function:

Var PLearn::DiverseComponentAnalysis::nonlinear_transform ( Var  in,
string  nonlinearity 
) [static, protected]

Definition at line 248 of file DiverseComponentAnalysis.cc.

References PLearn::abs(), PLearn::exp(), in, PLERROR, PLearn::sigmoid(), PLearn::square(), PLearn::squareroot(), and PLearn::tanh().

Referenced by build_().

{
    Var res; // result
    if(nonlinearity=="none" || nonlinearity=="linear")
        res = in;
    else if(nonlinearity=="square")
        res = square(in);
    else if(nonlinearity=="abs")
        res = abs(in);
    else if(nonlinearity=="sqrt")
        res = squareroot(in);
    else if(nonlinearity=="sqrtabs")
        res = squareroot(abs(in));
    else if(nonlinearity=="exp")
        res = exp(in);
    else if(nonlinearity=="tanh")
        res = tanh(in);
    else if(nonlinearity=="sigmoid")
        res = sigmoid(in);
    else
        PLERROR("Unknown nonlinearity %s",nonlinearity.c_str());
    return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int PLearn::DiverseComponentAnalysis::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 441 of file DiverseComponentAnalysis.cc.

References ncomponents.

{
    return ncomponents;
}
void PLearn::DiverseComponentAnalysis::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 474 of file DiverseComponentAnalysis.cc.

References PLearn::columnMean(), PLearn::computeInputCovar(), PLearn::computeInputMeanAndCovar(), Cx, Cy, PLearn::endl(), epsilon, PLearn::TVec< T >::fill(), force_zero_mean, PLearn::VMat::getExample(), i, PLearn::PLearner::initTrain(), inputdata, PLearn::PLearner::inputsize(), PLearn::PLearner::inputsize_, inv_stddev_of_projections, j, PLearn::TMat< T >::length(), PLearn::VMat::length(), mu, nonlinearity, PLearn::PLearner::nstages, nu, optimizer, PLearn::perr, PLearn::TVec< T >::resize(), PLearn::sqrt(), PLearn::PLearner::stage, PLearn::PLearner::train_set, and PLearn::PLearner::train_stats.

{
    // 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.

    /* TYPICAL CODE:

    static Vec input;  // static so we don't reallocate memory each time...
    static Vec target; // (but be careful that static means shared!)
    input.resize(inputsize());    // the train_set's inputsize()
    target.resize(targetsize());  // the train_set's targetsize()
    real weight;

    // This generic PLearner method does a number of standard stuff useful for
    // (almost) any learner, and return 'false' if no training should take
    // place. See PLearner.h for more details.
    */

    if (!initTrain())
        return;

    while(stage<nstages)
    {
        // clear statistics of previous epoch
        train_stats->forget();

        if(stage==0) // do stage 1
        {
            bool linear = (nonlinearity=="none" || nonlinearity=="linear");
            if(!linear)
            {
                perr << "Nonlinear training to stage 1" << endl;
                Mat X = inputdata->matValue;
                int l = train_set->length();
                Vec target;
                real weight;
                for(int i=0; i<l; i++)
                {
                    Vec Xi = X(i);
                    train_set->getExample(i,Xi,target,weight);
                }
                mu.resize(inputsize_);
                columnMean(X, mu);
                perr << "Nonlinear training to stage 1. DONE." << endl;
            }
            else // linear case
            {
                if(force_zero_mean)
                {
                    mu.resize(inputsize());
                    mu.fill(0);
                    computeInputCovar(train_set, mu, Cx->matValue, epsilon);
                }
                else
                    computeInputMeanAndCovar(train_set, mu, Cx->matValue, epsilon);

                if(nu!=0)
                {
                    Mat C = Cx->matValue;
                    int l = C.length();
                    for(int i=0; i<l; i++)
                        for(int j=0; j<l; j++)
                            if(i!=j)
                                C(i,j) *= (1-nu);
                }
            }
        }
        else
        {
            optimizer->optimizeN(*train_stats);
            Mat C = Cy->matValue;
            int l = C.length();            
            inv_stddev_of_projections.resize(l);
            for(int i=0; i<l; i++)
                inv_stddev_of_projections.fill(1.0/sqrt(C(i,i)));
        }

        //... train for 1 stage, and update train_stats,
        // using train_set->getExample(input, target, weight)
        // and train_stats->update(train_costs)

        ++stage;
        train_stats->finalize(); // finalize statistics for this epoch
    }
}

Here is the call graph for this function:


Member Data Documentation

Reimplemented from PLearn::PLearner.

Definition at line 201 of file DiverseComponentAnalysis.h.

Definition at line 234 of file DiverseComponentAnalysis.h.

Referenced by build_(), getVarGradient(), getVarValue(), and listVarNames().

Definition at line 120 of file DiverseComponentAnalysis.h.

Referenced by build_(), and declareOptions().

Definition at line 88 of file DiverseComponentAnalysis.h.

Referenced by build_(), declareOptions(), and forget().

Definition at line 73 of file DiverseComponentAnalysis.h.

Referenced by build_(), and declareOptions().

Definition at line 122 of file DiverseComponentAnalysis.h.

Referenced by build_().

The (weighted) covariance matrix of the samples.

Definition at line 102 of file DiverseComponentAnalysis.h.

Referenced by build_(), declareOptions(), makeDeepCopyFromShallowCopy(), and train().

The covariance of transformed data Cy = cov(W x) = W Cx W^T.

Definition at line 108 of file DiverseComponentAnalysis.h.

Referenced by build_(), and train().

The "transformed" covariance according to cov_transformation_type.

Definition at line 111 of file DiverseComponentAnalysis.h.

Referenced by build_().

Definition at line 75 of file DiverseComponentAnalysis.h.

Referenced by build_(), and declareOptions().

Definition at line 79 of file DiverseComponentAnalysis.h.

Referenced by build_(), and declareOptions().

Definition at line 76 of file DiverseComponentAnalysis.h.

Referenced by build_(), and declareOptions().

Definition at line 82 of file DiverseComponentAnalysis.h.

Referenced by build_(), and declareOptions().

Definition at line 86 of file DiverseComponentAnalysis.h.

Referenced by declareOptions(), and train().

Definition at line 85 of file DiverseComponentAnalysis.h.

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

Definition at line 119 of file DiverseComponentAnalysis.h.

Referenced by build_(), and train().

Definition at line 116 of file DiverseComponentAnalysis.h.

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

The loss variable: sum(asCy)

Definition at line 114 of file DiverseComponentAnalysis.h.

Referenced by build_().

The (weighted) mean of the samples.

Definition at line 99 of file DiverseComponentAnalysis.h.

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

### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //!

The number of components to keep (that's also the outputsize)

Definition at line 70 of file DiverseComponentAnalysis.h.

Referenced by build_(), computeOutput(), declareOptions(), forget(), and outputsize().

Definition at line 71 of file DiverseComponentAnalysis.h.

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

Definition at line 90 of file DiverseComponentAnalysis.h.

Referenced by computeOutput(), and declareOptions().

Definition at line 87 of file DiverseComponentAnalysis.h.

Referenced by declareOptions(), and train().

Definition at line 80 of file DiverseComponentAnalysis.h.

Referenced by build_(), and declareOptions().

Definition at line 77 of file DiverseComponentAnalysis.h.

Referenced by build_(), and declareOptions().

Definition at line 83 of file DiverseComponentAnalysis.h.

Referenced by build_(), and declareOptions().

Definition at line 92 of file DiverseComponentAnalysis.h.

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

Definition at line 121 of file DiverseComponentAnalysis.h.

Referenced by build_().

A ncomponents x inputsize matrix containing the projection directions.

Definition at line 105 of file DiverseComponentAnalysis.h.

Referenced by build_(), computeOutput(), declareOptions(), forget(), and makeDeepCopyFromShallowCopy().


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