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 | Private Attributes
PLearn::NatGradEstimator Class Reference

Class used for converting a sequence of n-dimensional gradients g_t into covariance-corrected update directions v_t, approximating v_t = inv(C_t) g_t, with C_t = gamma C_{t-1} + g_t g_t'. More...

#include <NatGradItEstimator.h>

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

List of all members.

Public Member Functions

 NatGradEstimator ()
 Default constructor.
void init ()
 initialize the object to start collecting covariance statistics from fresh
void operator() (int t, const Vec &g, Vec v)
 main method of this class: reads from the gradient "g" field and writes into the "v" field an estimator of inv(cov) g.
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual NatGradEstimatordeepCopy (CopiesMap &copies) const
virtual void build ()
 Post-constructor.
virtual void makeDeepCopyFromShallowCopy (CopiesMap &copies)
 Transforms a shallow copy into a deep copy.
 NatGradEstimator ()
 Default constructor.
virtual void build ()
 Post-constructor.
virtual void init ()
 initialize the object to start collecting covariance statistics from fresh
virtual void operator() (int t, const Vec &g, Vec v)
 main method of this class: reads from the gradient "g" field and writes into the "v" field an estimator of inv(cov) g.
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual NatGradEstimatordeepCopy (CopiesMap &copies) const
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 ()
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 cov_minibatch_size
 ### declare public option fields (such as build options) here
real lambda
 regularization coefficient of covariance matrix (initial values on diagonal)
int n_eigen
 number of eigenvectors-eigenvalues that is preserved of the covariance matrix
real alpha
 learning rate of the inversion iterations
real gamma
 forgetting factor in moving average estimator of covariance
int inversion_n_iterations
 number of iterations for approaching the solution of inv(C) v_t = g_t
int n_dim
 number of input dimensions (size of g_t or v_t)
bool use_double_init
 wether to use the u0 and its correction for initialization the inversion iteration
int verbosity
 verbosity level, track improvement, spectrum, etgc.
bool amari_version
 use the formula Ginv <-- (1+eps) Ginv - eps Ginv g g' Ginv to estimate the inverse of the covariance matrix
real init_lambda
 regularization coefficient of covariance matrix (initial values on diagonal)
real min_lambda
 Minimal value allowed for lambda in its update from an.
bool renormalize
bool update_lambda_from_eigen
 Following an eigendecomposition, set lambda to the (n_eigen+1)th eigenvalue.

Static Public Attributes

static StaticInitializer _static_initializer_

Static Protected Member Functions

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

Protected Attributes

Mat Ut
 k principal eigenvectors of the estimated covariance matrix
Vec D
 k principal eigenvalues of the estimated covariance matrix
Vec E
 eigenvalues of the Gram matrix
real sigma
 eigenvalue attributed to the non-principal eigenvectors
Mat Gt
 gradient vectors collected during the minibatch, in each row of Gt
int previous_t
 previous value of t
Mat initial_v
 initial v's for the gradients in this minibatch
Vec vg
 vg[i] = initial_v[i] . Gt[i]
Mat Xt
 contains in its rows the scaled eigenvectors and g's seen since the beginning of the minibatch
Mat G
 Gram matrix = X' X = Xt Xt'.
int first_t

Private Types

typedef Object inherited
typedef GradientCorrector inherited

Private Member Functions

void build_ ()
 This does the actual building.

Private Attributes

Vec tmp_v
 temporary buffer
Mat M
 Gram matrix, of dimension (k + minibatch_size, k + minibatch_size) and its sub-matrices.
Mat M11
Mat M12
Mat M21
Mat M22
Mat Vt
 k+1 eigenvectors of the Gram matrix (in the rows)
Mat Vkt
Mat Vbt
 sub-matrix of Vt with first n_eigen elements of each eigen-vector
Mat newUt
 sub-matrix of Vt with last cov_minibatch_size elements of each eigen-vector
Vec r
Mat A
 sub-matrix of Vt with first n_eigen eigen-vectors
TVec< intpivots

Detailed Description

Class used for converting a sequence of n-dimensional gradients g_t into covariance-corrected update directions v_t, approximating v_t = inv(C_t) g_t, with C_t = gamma C_{t-1} + g_t g_t'.

GradientCorrector subclass used for converting a sequence of n-dimensional gradients g_t into covariance-corrected update directions v_t, approximating v_t = inv(C_t) g_t, with C_t = gamma C_{t-1} + g_t g_t'.

There is a main method, the operator(), which takes a g_t and fills v_t. The process can be initialized by init().

Definition at line 57 of file NatGradItEstimator.h.


Member Typedef Documentation

Reimplemented from PLearn::Object.

Definition at line 59 of file NatGradItEstimator.h.

Reimplemented from PLearn::Object.

Definition at line 58 of file NatGradEstimator.h.


Constructor & Destructor Documentation

PLearn::NatGradEstimator::NatGradEstimator ( )

Default constructor.

Definition at line 101 of file NatGradItEstimator.cc.

References build().

    : cov_minibatch_size(10),
      lambda(1),
      n_eigen(10),
      alpha(0.1),
      gamma(0.9),
      inversion_n_iterations(5),
      n_dim(-1),
      use_double_init(true),
      verbosity(0),
      sigma(0),
      previous_t(-1)
{
    build();
}

Here is the call graph for this function:

PLearn::NatGradEstimator::NatGradEstimator ( )

Default constructor.


Member Function Documentation

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

Reimplemented from PLearn::Object.

Definition at line 99 of file NatGradItEstimator.cc.

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

Reimplemented from PLearn::Object.

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

Reimplemented from PLearn::Object.

Definition at line 99 of file NatGradItEstimator.cc.

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

Reimplemented from PLearn::Object.

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

Reimplemented from PLearn::Object.

Definition at line 99 of file NatGradItEstimator.cc.

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

Reimplemented from PLearn::Object.

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

Reimplemented from PLearn::Object.

Definition at line 99 of file NatGradItEstimator.cc.

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

Reimplemented from PLearn::Object.

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

Reimplemented from PLearn::Object.

Definition at line 99 of file NatGradItEstimator.cc.

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

Reimplemented from PLearn::Object.

static void PLearn::NatGradEstimator::_static_initialize_ ( ) [static]

Reimplemented from PLearn::Object.

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

Reimplemented from PLearn::Object.

Definition at line 99 of file NatGradItEstimator.cc.

virtual void PLearn::NatGradEstimator::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.

void PLearn::NatGradEstimator::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 119 of file NatGradItEstimator.cc.

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

Referenced by NatGradEstimator().

Here is the call graph for this function:

Here is the caller graph for this function:

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

This does the actual building.

Reimplemented from PLearn::Object.

Definition at line 224 of file NatGradItEstimator.cc.

References init().

Referenced by build().

{
    init();
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 99 of file NatGradItEstimator.cc.

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

Reimplemented from PLearn::Object.

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

Declares the class options.

Reimplemented from PLearn::Object.

Definition at line 151 of file NatGradItEstimator.cc.

References alpha, amari_version, PLearn::OptionBase::buildoption, cov_minibatch_size, PLearn::declareOption(), PLearn::Object::declareOptions(), E, gamma, Gt, initial_v, inversion_n_iterations, lambda, PLearn::OptionBase::learntoption, n_dim, n_eigen, previous_t, sigma, use_double_init, Ut, and verbosity.

{
    // ### 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, "cov_minibatch_size", &NatGradEstimator::cov_minibatch_size,
                  OptionBase::buildoption,
                  "Covariance estimator minibatch size, i.e. number of calls\n"
                  "to operator() before re-estimating the principal\n"
                  "eigenvectors/values. Note that each such re-computation will\n"
                  "cost O(n_eigen * n)");
    declareOption(ol, "lambda", &NatGradEstimator::lambda,
                  OptionBase::buildoption,
                  "Initial variance. The first covariance is assumed to be\n"
                  "lambda times the identity. Default = 1.\n");
    declareOption(ol, "n_eigen", &NatGradEstimator::n_eigen,
                  OptionBase::buildoption,
                  "Number of principal eigenvectors of the covariance matrix\n"
                  "that are kept in its approximation.\n");
    declareOption(ol, "alpha", &NatGradEstimator::alpha,
                  OptionBase::buildoption,
                  "Learning rate of the inversion iterations.\n");
    declareOption(ol, "inversion_n_iterations", &NatGradEstimator::inversion_n_iterations,
                  OptionBase::buildoption,
                  "Number of iterations of numerical approximation algorithm for\n"
                  "solving the system inverse(cov) v = g\n");
    declareOption(ol, "use_double_init", &NatGradEstimator::use_double_init,
                  OptionBase::buildoption,
                  "wether to use the u0 and its correction for initialization the inversion iteration\n");
    declareOption(ol, "gamma", &NatGradEstimator::gamma,
                  OptionBase::buildoption,
                  "Forgetting factor in moving average estimator of covariance. 0<gamma<1.\n");
    declareOption(ol, "amari_version", &NatGradEstimator::amari_version,
                  OptionBase::buildoption,
                  "Instead of our tricks, use the formula Ginv <-- (1+eps) Ginv - eps Ginv g g' Ginv\n"
                  "to estimate the inverse of the covariance matrix, and multiply it with g at each step.\n");
    declareOption(ol, "verbosity", &NatGradEstimator::verbosity,
                  OptionBase::buildoption,
                  "Verbosity level\n");

    declareOption(ol, "n_dim", &NatGradEstimator::n_dim,
                  OptionBase::learntoption,
                  "Number of dimensions of the gradient vectors\n");
    declareOption(ol, "Ut", &NatGradEstimator::Ut,
                  OptionBase::learntoption,
                  "Estimated principal eigenvectors of the gradients covariance matrix\n"
                  "(stored in the rows of Ut)\n");
    declareOption(ol, "E", &NatGradEstimator::E,
                  OptionBase::learntoption,
                  "Estimated principal eigenvalues of the gradients covariance matrix\n");
    declareOption(ol, "sigma", &NatGradEstimator::sigma,
                  OptionBase::learntoption,
                  "Estimated value for the minor eigenvalues of the gradients covariance matrix\n");
    declareOption(ol, "Gt", &NatGradEstimator::Gt,
                  OptionBase::learntoption,
                  "Collected gradients during a minibatch\n");
    declareOption(ol, "previous_t", &NatGradEstimator::previous_t,
                  OptionBase::learntoption,
                  "Value of t at previous call of operator()\n");
    declareOption(ol, "initial_v", &NatGradEstimator::initial_v,
                  OptionBase::learntoption,
                  "Initial v for the g's of the current minibatch\n");

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

Here is the call graph for this function:

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

Declares the class options.

Reimplemented from PLearn::Object.

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

Reimplemented from PLearn::Object.

Definition at line 117 of file NatGradEstimator.h.

:
    //#####  Protected Options  ###############################################
static const PPath& PLearn::NatGradEstimator::declaringFile ( ) [inline, static]

Reimplemented from PLearn::Object.

Definition at line 122 of file NatGradItEstimator.h.

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

Reimplemented from PLearn::Object.

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

Reimplemented from PLearn::Object.

Definition at line 99 of file NatGradItEstimator.cc.

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

Reimplemented from PLearn::Object.

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

Reimplemented from PLearn::Object.

Definition at line 99 of file NatGradItEstimator.cc.

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

Reimplemented from PLearn::Object.

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

Reimplemented from PLearn::Object.

Definition at line 99 of file NatGradItEstimator.cc.

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

Reimplemented from PLearn::Object.

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

Reimplemented from PLearn::Object.

Definition at line 99 of file NatGradItEstimator.cc.

void PLearn::NatGradEstimator::init ( ) [virtual]

initialize the object to start collecting covariance statistics from fresh

Implements PLearn::GradientCorrector.

Definition at line 229 of file NatGradItEstimator.cc.

References cov_minibatch_size, D, E, Gt, initial_v, M, M11, M12, M21, M22, n_dim, n_eigen, newUt, PLASSERT_MSG, PLearn::TVec< T >::resize(), PLearn::TMat< T >::resize(), PLearn::TMat< T >::subMat(), PLearn::TVec< T >::subVec(), tmp_v, Ut, Vbt, vg, Vkt, and Vt.

Referenced by build_(), and operator()().

{
    if (n_dim>=0)
    {
        PLASSERT_MSG(n_dim>0, "NatGradEstimator::init(), n_dim should be > 0");
        PLASSERT_MSG(gamma<1 && gamma>0, "NatGradEstimator::init(), gamma should be < 1 and >0");
        Ut.resize(n_eigen,n_dim);
        Vt.resize(n_eigen+1,n_eigen+cov_minibatch_size);
        Vkt = Vt.subMat(0,0,n_eigen,n_eigen);
        Vbt = Vt.subMat(0,n_eigen,n_eigen,cov_minibatch_size);
        E.resize(n_eigen+1);
        D = E.subVec(0,n_eigen);
        M.resize(n_eigen + cov_minibatch_size, n_eigen + cov_minibatch_size);
        M11=M.subMat(0,0,n_eigen,n_eigen);
        M12=M.subMat(0,n_eigen,n_eigen,cov_minibatch_size);
        M21=M.subMat(n_eigen,0,cov_minibatch_size,n_eigen);
        M22=M.subMat(n_eigen,n_eigen,cov_minibatch_size,cov_minibatch_size);
        Gt.resize(cov_minibatch_size, n_dim);
        initial_v.resize(cov_minibatch_size, n_dim);
        tmp_v.resize(n_dim);
        newUt.resize(n_eigen,n_dim);
        vg.resize(cov_minibatch_size);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void PLearn::NatGradEstimator::init ( ) [virtual]

initialize the object to start collecting covariance statistics from fresh

Implements PLearn::GradientCorrector.

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

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::Object.

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

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::Object.

Definition at line 125 of file NatGradItEstimator.cc.

References D, PLearn::deepCopyField(), E, Gt, initial_v, M, M11, M12, M21, M22, PLearn::Object::makeDeepCopyFromShallowCopy(), newUt, tmp_v, Ut, Vbt, vg, Vkt, and Vt.

{
    inherited::makeDeepCopyFromShallowCopy(copies);

    // ### Call deepCopyField on all "pointer-like" fields
    // ### that you wish to be deepCopied rather than
    // ### shallow-copied.
    // ### ex:
    deepCopyField(Ut, copies);
    deepCopyField(E, copies);
    deepCopyField(D, copies);
    deepCopyField(Gt, copies);
    deepCopyField(initial_v, copies);
    deepCopyField(tmp_v, copies);
    deepCopyField(M, copies);
    deepCopyField(M11, copies);
    deepCopyField(M12, copies);
    deepCopyField(M21, copies);
    deepCopyField(M22, copies);
    deepCopyField(Vt, copies);
    deepCopyField(Vkt, copies);
    deepCopyField(Vbt, copies);
    deepCopyField(newUt, copies);
    deepCopyField(vg, copies);
}

Here is the call graph for this function:

void PLearn::NatGradEstimator::operator() ( int  t,
const Vec g,
Vec  v 
) [virtual]

main method of this class: reads from the gradient "g" field and writes into the "v" field an estimator of inv(cov) g.

The argument is an index over examples, which is used to know when cycling through a minibatch. The statistics on the covariance are updated.

Implements PLearn::GradientCorrector.

Definition at line 254 of file NatGradItEstimator.cc.

References alpha, PLearn::TMat< T >::clear(), PLearn::compute_sqrt(), cov_minibatch_size, D, PLearn::diagonalizedFactorsProduct(), PLearn::dot(), E, PLearn::eigenVecOfSymmMat(), PLearn::endl(), g, gamma, Gt, i, init(), initial_v, inversion_n_iterations, j, PLearn::L2distance(), lambda, PLearn::TVec< T >::length(), M, M11, M12, M21, M22, PLearn::multiply(), PLearn::multiplyAcc(), n_dim, n_eigen, newUt, PLASSERT_MSG, PLearn::pow(), PLearn::pownorm(), previous_t, PLearn::product(), PLearn::productTranspose(), r, PLearn::TVec< T >::resize(), sigma, PLearn::sqrt(), PLearn::TVec< T >::subVec(), tmp_v, PLearn::transpose(), use_double_init, Ut, Vbt, verbosity, vg, Vkt, and Vt.

{
    if (t!=0)
        PLASSERT_MSG(t==previous_t+1, "NatGradEstimator() should be called sequentially!");
    if  (n_dim<0) 
    {
        PLASSERT_MSG(t==0, "The first call to NatGradEstimator() should be with t=0\n");
        n_dim = g.length();
        v.resize(n_dim);
        init();
    }
    int i = t % cov_minibatch_size;
    Vec v0 = initial_v(i);
    Gt(i) << g;

    // initialize v0
    v0 << g;
    if (t<cov_minibatch_size)
    {
        v0 *= 1.0/(lambda + pownorm(g));
        v << v0;
    }
    else
    {
        real oos = gamma/sigma;
        real ooip1 = 1.0/(i+1.0);
        v0 *= oos;
        // v0 = g*gamma/sigma + sum_j (1/D_j - gamma/sigma Uj Uj' g
        for (int j=0;j<n_eigen;j++)
        {
            Vec Uj = Ut(j);
            multiplyAcc(v0, Uj, (1/D[j] - oos) * dot(Uj,g));
        }
        if (use_double_init)
        {
            vg[i] = dot(v0,g);
            multiply(v0,1.0/(gamma + vg[i]*ooip1),tmp_v); // tmp_v == u0_i here
            v << tmp_v;
            for (int j=0;j<i;j++)
                multiplyAcc(v, initial_v(j), -ooip1*dot(Gt(j),tmp_v)/(gamma + vg[j]*ooip1));
        }
        else
            v << v0;
    }

    // iterate on v to solve linear system
    if (verbosity>0)
        cout << "start inversion iterations" << endl;
    for (int j=0;j<inversion_n_iterations;j++)
    {
        multiply(v, (1 - gamma*alpha),tmp_v);
        multiplyAcc(tmp_v, v0, alpha);
        for (int r=0;r<=i;r++)
            multiplyAcc(tmp_v, initial_v(r), -alpha/(i+1)*dot(Gt(r),v));
        v << tmp_v;
        // verify that we get an improvement
        if (verbosity>0)
        {
            // compute (B + (1/i)sum_{k=1}^i g_k g_k') v_i            
            //        =(U (gamma D -sigma I) U' + sigma I + (1/i)sum_{k=1}^i g_k g_k') v_i            
            multiply(v,sigma,tmp_v);
            for (int j=0;j<n_eigen;j++)
            {
                Vec Uj = Ut(j);
                multiplyAcc(tmp_v,Uj,(gamma*D[j]-sigma)*dot(Uj,v));
            }
            for (int j=0;j<=i;j++)
            {
                Vec Gj = Gt(j);
                multiplyAcc(tmp_v,Gj,dot(Gj,v)/(i+1));
            }
            // result is in tmp_v. Compare with g_i
            real gnorm = dot(g,g);
            real enorm = dot(tmp_v,tmp_v);
            real angle = acos(dot(tmp_v,g)/sqrt(gnorm*enorm))*360/(2*3.14159);
            real err = L2distance(g,tmp_v);
            cout << "linear system distance=" << err << ", angle="<<angle<<", norm ratio="<<enorm/gnorm<<endl;
        }
    }
    
    // normalize back v, to take into account scaling up of C due to gamma iteration
    v *= (1 - pow(gamma,real(t/cov_minibatch_size)))/(1 - gamma);
    // recompute the eigen-decomposition
    if (i+1==cov_minibatch_size)
    {
        // build Gram matrix M, by blocks [M11 M12; M21 M22]
        M11.clear();
        for (int j=0;j<n_eigen;j++)
            M11(j,j) = gamma*D[j];
        productTranspose(M12,Ut,Gt);
        real gob=gamma/cov_minibatch_size;
        for (int j=0;j<n_eigen;j++)
            M12(j) *= sqrt(D[j]*gob);
        transpose(M12,M21);
        productTranspose(M22,Gt,Gt);
        M22 *= 1.0/cov_minibatch_size;

        // get eigen-decomposition, with one more eigen-x than necessary to set sigma
        eigenVecOfSymmMat(M,n_eigen+1,E,Vt);
        
        // convert eigenvectors Vt of M into eigenvectors U of C
        product(newUt,Vbt,Gt);
        Vec sqrtD = tmp_v.subVec(0,n_eigen);
        compute_sqrt(D,sqrtD);
        diagonalizedFactorsProduct(newUt,Vkt,sqrtD,Ut,true);
        Ut << newUt;
    }
    previous_t = t;
}

Here is the call graph for this function:

virtual void PLearn::NatGradEstimator::operator() ( int  t,
const Vec g,
Vec  v 
) [virtual]

main method of this class: reads from the gradient "g" field and writes into the "v" field an estimator of inv(cov) g.

The argument is an index over examples, which is used to know when cycling through a minibatch. The statistics on the covariance are updated.

Implements PLearn::GradientCorrector.


Member Data Documentation

Reimplemented from PLearn::Object.

Definition at line 122 of file NatGradItEstimator.h.

sub-matrix of Vt with first n_eigen eigen-vectors

Definition at line 162 of file NatGradEstimator.h.

learning rate of the inversion iterations

Definition at line 76 of file NatGradItEstimator.h.

Referenced by declareOptions(), and operator()().

use the formula Ginv <-- (1+eps) Ginv - eps Ginv g g' Ginv to estimate the inverse of the covariance matrix

Definition at line 95 of file NatGradItEstimator.h.

Referenced by declareOptions().

### declare public option fields (such as build options) here

mini-batch size for covariance eigen-decomposition

Definition at line 67 of file NatGradItEstimator.h.

Referenced by declareOptions(), init(), and operator()().

k principal eigenvalues of the estimated covariance matrix

Definition at line 140 of file NatGradItEstimator.h.

Referenced by init(), makeDeepCopyFromShallowCopy(), and operator()().

eigenvalues of the Gram matrix

Definition at line 143 of file NatGradItEstimator.h.

Referenced by declareOptions(), init(), makeDeepCopyFromShallowCopy(), and operator()().

Definition at line 142 of file NatGradEstimator.h.

Gram matrix = X' X = Xt Xt'.

Definition at line 138 of file NatGradEstimator.h.

forgetting factor in moving average estimator of covariance

Definition at line 79 of file NatGradItEstimator.h.

Referenced by declareOptions(), and operator()().

gradient vectors collected during the minibatch, in each row of Gt

Definition at line 149 of file NatGradItEstimator.h.

Referenced by declareOptions(), init(), makeDeepCopyFromShallowCopy(), and operator()().

regularization coefficient of covariance matrix (initial values on diagonal)

Definition at line 69 of file NatGradEstimator.h.

initial v's for the gradients in this minibatch

Definition at line 155 of file NatGradItEstimator.h.

Referenced by declareOptions(), init(), makeDeepCopyFromShallowCopy(), and operator()().

number of iterations for approaching the solution of inv(C) v_t = g_t

Definition at line 82 of file NatGradItEstimator.h.

Referenced by declareOptions(), and operator()().

regularization coefficient of covariance matrix (initial values on diagonal)

Definition at line 70 of file NatGradItEstimator.h.

Referenced by declareOptions(), and operator()().

Gram matrix, of dimension (k + minibatch_size, k + minibatch_size) and its sub-matrices.

Definition at line 182 of file NatGradItEstimator.h.

Referenced by init(), makeDeepCopyFromShallowCopy(), and operator()().

Definition at line 182 of file NatGradItEstimator.h.

Referenced by init(), makeDeepCopyFromShallowCopy(), and operator()().

Definition at line 182 of file NatGradItEstimator.h.

Referenced by init(), makeDeepCopyFromShallowCopy(), and operator()().

Definition at line 182 of file NatGradItEstimator.h.

Referenced by init(), makeDeepCopyFromShallowCopy(), and operator()().

Definition at line 182 of file NatGradItEstimator.h.

Referenced by init(), makeDeepCopyFromShallowCopy(), and operator()().

Minimal value allowed for lambda in its update from an.

Definition at line 72 of file NatGradEstimator.h.

number of input dimensions (size of g_t or v_t)

Reimplemented from PLearn::GradientCorrector.

Definition at line 85 of file NatGradItEstimator.h.

Referenced by declareOptions(), init(), and operator()().

number of eigenvectors-eigenvalues that is preserved of the covariance matrix

Definition at line 73 of file NatGradItEstimator.h.

Referenced by declareOptions(), init(), and operator()().

sub-matrix of Vt with last cov_minibatch_size elements of each eigen-vector

temp for new value of Ut

Definition at line 188 of file NatGradItEstimator.h.

Referenced by init(), makeDeepCopyFromShallowCopy(), and operator()().

Definition at line 163 of file NatGradEstimator.h.

previous value of t

Definition at line 152 of file NatGradItEstimator.h.

Referenced by declareOptions(), and operator()().

Definition at line 159 of file NatGradEstimator.h.

Referenced by operator()().

Definition at line 80 of file NatGradEstimator.h.

eigenvalue attributed to the non-principal eigenvectors

Definition at line 146 of file NatGradItEstimator.h.

Referenced by declareOptions(), and operator()().

temporary buffer

Definition at line 179 of file NatGradItEstimator.h.

Referenced by init(), makeDeepCopyFromShallowCopy(), and operator()().

Following an eigendecomposition, set lambda to the (n_eigen+1)th eigenvalue.

Definition at line 88 of file NatGradEstimator.h.

wether to use the u0 and its correction for initialization the inversion iteration

Definition at line 88 of file NatGradItEstimator.h.

Referenced by declareOptions(), and operator()().

k principal eigenvectors of the estimated covariance matrix

Definition at line 137 of file NatGradItEstimator.h.

Referenced by declareOptions(), init(), makeDeepCopyFromShallowCopy(), and operator()().

sub-matrix of Vt with first n_eigen elements of each eigen-vector

Definition at line 186 of file NatGradItEstimator.h.

Referenced by init(), makeDeepCopyFromShallowCopy(), and operator()().

verbosity level, track improvement, spectrum, etgc.

Reimplemented from PLearn::GradientCorrector.

Definition at line 91 of file NatGradItEstimator.h.

Referenced by declareOptions(), and operator()().

vg[i] = initial_v[i] . Gt[i]

Definition at line 157 of file NatGradItEstimator.h.

Referenced by init(), makeDeepCopyFromShallowCopy(), and operator()().

Definition at line 185 of file NatGradItEstimator.h.

Referenced by init(), makeDeepCopyFromShallowCopy(), and operator()().

k+1 eigenvectors of the Gram matrix (in the rows)

rhs of linear system (G + gamma^{-i} lambda I) a = r

Definition at line 184 of file NatGradItEstimator.h.

Referenced by init(), makeDeepCopyFromShallowCopy(), and operator()().

contains in its rows the scaled eigenvectors and g's seen since the beginning of the minibatch

Definition at line 135 of file NatGradEstimator.h.


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