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

#include <MatrixSoftmaxVariable.h>

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

List of all members.

Public Member Functions

 MatrixSoftmaxVariable ()
 Default constructor for persistence.
 MatrixSoftmaxVariable (Variable *input)
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual MatrixSoftmaxVariabledeepCopy (CopiesMap &copies) const
virtual void recomputeSize (int &l, int &w) const
 Recomputes the length l and width w that this variable should have, according to its parent variables.
virtual void fprop ()
 Nothing to do by default.
virtual void bprop ()
 Nothing to do by default.
virtual void bbprop ()
 compute an approximation to diag(d^2/dinput^2) given diag(d^2/doutput^2), with diag(d^2/dinput^2) ~=~ (doutput/dinput)' diag(d^2/doutput^2) (doutput/dinput) In particular: if 'C' depends on 'y' and 'y' depends on x ...
virtual void symbolicBprop ()
 compute a piece of new Var graph that represents the symbolic derivative of this Var
virtual void rfprop ()

Static Public Member Functions

static string _classname_ ()
 MatrixSoftmaxVariable.
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 Public Attributes

static StaticInitializer _static_initializer_

Private Types

typedef UnaryVariable inherited

Detailed Description

Definition at line 52 of file MatrixSoftmaxVariable.h.


Member Typedef Documentation

Reimplemented from PLearn::UnaryVariable.

Definition at line 54 of file MatrixSoftmaxVariable.h.


Constructor & Destructor Documentation

PLearn::MatrixSoftmaxVariable::MatrixSoftmaxVariable ( ) [inline]

Default constructor for persistence.

Definition at line 58 of file MatrixSoftmaxVariable.h.

{}
PLearn::MatrixSoftmaxVariable::MatrixSoftmaxVariable ( Variable input)

Definition at line 55 of file MatrixSoftmaxVariable.cc.

    : inherited(input, input->length(), input->width())
{}

Member Function Documentation

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

MatrixSoftmaxVariable.

Reimplemented from PLearn::UnaryVariable.

Definition at line 53 of file MatrixSoftmaxVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 53 of file MatrixSoftmaxVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 53 of file MatrixSoftmaxVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 53 of file MatrixSoftmaxVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 53 of file MatrixSoftmaxVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 53 of file MatrixSoftmaxVariable.cc.

void PLearn::MatrixSoftmaxVariable::bbprop ( ) [virtual]

compute an approximation to diag(d^2/dinput^2) given diag(d^2/doutput^2), with diag(d^2/dinput^2) ~=~ (doutput/dinput)' diag(d^2/doutput^2) (doutput/dinput) In particular: if 'C' depends on 'y' and 'y' depends on x ...

d^2C/dx^2 = d^2C/dy^2 * (dy/dx)^2 + dC/dy * d^2y/dx^2 (diaghessian) (gradient)

Reimplemented from PLearn::Variable.

Definition at line 105 of file MatrixSoftmaxVariable.cc.

References PLERROR.

{
    PLERROR("MatrixSofmaxVariable::bbprop() not implemented");
}
void PLearn::MatrixSoftmaxVariable::bprop ( ) [virtual]

Nothing to do by default.

Reimplemented from PLearn::UnaryVariable.

Definition at line 88 of file MatrixSoftmaxVariable.cc.

References i, PLearn::UnaryVariable::input, j, PLearn::Var::length(), PLearn::Variable::length(), PLearn::Variable::matGradient, PLearn::Variable::matValue, and PLearn::Var::width().

{
    for(int i=0; i<input->width(); i++)
        for(int j=0; j<input->length(); j++)
        {
            real vali = matValue[j][i];
            for(int k=0; k<length(); k++)
            {
                if(k!=j)
                    input->matGradient[j][i] -= matGradient[k][i]*vali*matValue[k][i];
                else
                    input->matGradient[j][i] += matGradient[j][i]*vali*(1.-vali);
            }
        }
}

Here is the call graph for this function:

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 53 of file MatrixSoftmaxVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 61 of file MatrixSoftmaxVariable.h.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 53 of file MatrixSoftmaxVariable.cc.

void PLearn::MatrixSoftmaxVariable::fprop ( ) [virtual]

Nothing to do by default.

Reimplemented from PLearn::UnaryVariable.

Definition at line 69 of file MatrixSoftmaxVariable.cc.

References PLearn::columnMax(), PLearn::fast_exact_is_equal(), i, PLearn::UnaryVariable::input, j, PLearn::Var::length(), PLearn::Variable::matValue, PLERROR, PLearn::safeexp(), PLearn::Var::width(), and PLearn::Variable::width().

{
    Vec column_max(width());
    columnMax(input->matValue, column_max);

    for(int j=0; j<input->width(); j++)
    {
        real s = 0;
        real curmax = column_max[j];
        for(int i=0; i<input->length(); i++)      
            s += (matValue[i][j] = safeexp(input->matValue[i][j]-curmax));
        if (fast_exact_is_equal(s, 0)) PLERROR("trying to divide by 0 in softmax");
        s = 1.0 / s;
        for(int i=0; i<input->length(); i++)
            matValue[i][j] *= s;
    }
}

Here is the call graph for this function:

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 53 of file MatrixSoftmaxVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 53 of file MatrixSoftmaxVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 53 of file MatrixSoftmaxVariable.cc.

void PLearn::MatrixSoftmaxVariable::recomputeSize ( int l,
int w 
) const [virtual]

Recomputes the length l and width w that this variable should have, according to its parent variables.

This is used for ex. by sizeprop() The default version stupidly returns the current dimensions, so make sure to overload it in subclasses if this is not appropriate.

Reimplemented from PLearn::Variable.

Definition at line 59 of file MatrixSoftmaxVariable.cc.

References PLearn::UnaryVariable::input, PLearn::Var::length(), and PLearn::Var::width().

{
    if (input) {
        l = input->length();
        w = input->width();
    } else
        l = w = 0;
}

Here is the call graph for this function:

void PLearn::MatrixSoftmaxVariable::rfprop ( ) [virtual]

Reimplemented from PLearn::Variable.

Definition at line 118 of file MatrixSoftmaxVariable.cc.

References PLERROR.

{
    PLERROR("SofmaxVariable::rfprop() not implemented");
}
void PLearn::MatrixSoftmaxVariable::symbolicBprop ( ) [virtual]

compute a piece of new Var graph that represents the symbolic derivative of this Var

Reimplemented from PLearn::Variable.

Definition at line 111 of file MatrixSoftmaxVariable.cc.

References PLERROR.

{
    PLERROR("MatrixSofmaxVariable::symbolicBprop() not implemented");
}

Member Data Documentation

Reimplemented from PLearn::UnaryVariable.

Definition at line 61 of file MatrixSoftmaxVariable.h.


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