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

Represents a vector of a given lenth, that has value 1 at the index given by another variable and 0 everywhere else. More...

#include <OneHotVariable.h>

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

List of all members.

Public Member Functions

 OneHotVariable ()
 Default constructor for persistence.
 OneHotVariable (int thelength, Variable *index, real the_coldvalue, real the_hotvalue)
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual OneHotVariabledeepCopy (CopiesMap &copies) const
virtual void build ()
 Post-constructor.
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 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_ ()
 OneHotVariable.
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 void declareOptions (OptionList &ol)
 Declare options (data fields) for the class.

Static Public Attributes

static StaticInitializer _static_initializer_

Protected Member Functions

void build_ ()
 Object-specific post-constructor.

Protected Attributes

real hotvalue
real coldvalue
int length_

Private Types

typedef UnaryVariable inherited

Detailed Description

Represents a vector of a given lenth, that has value 1 at the index given by another variable and 0 everywhere else.

Definition at line 55 of file OneHotVariable.h.


Member Typedef Documentation

Reimplemented from PLearn::UnaryVariable.

Definition at line 57 of file OneHotVariable.h.


Constructor & Destructor Documentation

PLearn::OneHotVariable::OneHotVariable ( ) [inline]

Default constructor for persistence.

Definition at line 66 of file OneHotVariable.h.

: hotvalue(), coldvalue() {}
PLearn::OneHotVariable::OneHotVariable ( int  thelength,
Variable index,
real  the_coldvalue,
real  the_hotvalue 
)

Definition at line 56 of file OneHotVariable.cc.

References build_().

    : inherited(hotindex,thelength,1), hotvalue(the_hotvalue), coldvalue(the_coldvalue), length_(thelength)
{
    build_();
}

Here is the call graph for this function:


Member Function Documentation

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

OneHotVariable.

Reimplemented from PLearn::UnaryVariable.

Definition at line 54 of file OneHotVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 54 of file OneHotVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 54 of file OneHotVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 54 of file OneHotVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 54 of file OneHotVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 54 of file OneHotVariable.cc.

void PLearn::OneHotVariable::bprop ( ) [virtual]

Nothing to do by default.

Reimplemented from PLearn::UnaryVariable.

Definition at line 104 of file OneHotVariable.cc.

{}
void PLearn::OneHotVariable::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::UnaryVariable.

Definition at line 63 of file OneHotVariable.cc.

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

Here is the call graph for this function:

void PLearn::OneHotVariable::build_ ( ) [protected]

Object-specific post-constructor.

This method should be redefined in subclasses and do the actual building of the object according to previously set option fields. Constructors can just set option fields, and then call build_. This method is NOT virtual, and will typically be called only from three places: a constructor, the public virtual build() method, and possibly the public virtual read method (which calls its parent's read). build_() can assume that its parent's build_() has already been called.

Reimplemented from PLearn::UnaryVariable.

Definition at line 70 of file OneHotVariable.cc.

References PLearn::UnaryVariable::input, and PLERROR.

Referenced by build(), and OneHotVariable().

{
    // input is hotindex from constructor
    if (input && !input->isScalar())
        PLERROR("InterValuesVariable OneHotVariable(int thelength, Variable* hotindex, real the_coldvalue, real the_hotvalue) hotindex must be scalar as it is supposed to be an integer index");
}

Here is the caller graph for this function:

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 54 of file OneHotVariable.cc.

void PLearn::OneHotVariable::declareOptions ( OptionList ol) [static]

Declare options (data fields) for the class.

Redefine this in subclasses: call declareOption(...) for each option, and then call inherited::declareOptions(options). Please call the inherited method AT THE END to get the options listed in a consistent order (from most recently defined to least recently defined).

  static void MyDerivedClass::declareOptions(OptionList& ol)
  {
      declareOption(ol, "inputsize", &MyObject::inputsize_,
                    OptionBase::buildoption,
                    "The size of the input; it must be provided");
      declareOption(ol, "weights", &MyObject::weights,
                    OptionBase::learntoption,
                    "The learned model weights");
      inherited::declareOptions(ol);
  }
Parameters:
olList of options that is progressively being constructed for the current class.

Reimplemented from PLearn::UnaryVariable.

Definition at line 78 of file OneHotVariable.cc.

References PLearn::OptionBase::buildoption, coldvalue, PLearn::declareOption(), PLearn::UnaryVariable::declareOptions(), hotvalue, and length_.

Here is the call graph for this function:

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 69 of file OneHotVariable.h.

:
    void build_();
OneHotVariable * PLearn::OneHotVariable::deepCopy ( CopiesMap copies) const [virtual]

Reimplemented from PLearn::UnaryVariable.

Definition at line 54 of file OneHotVariable.cc.

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

Nothing to do by default.

Reimplemented from PLearn::UnaryVariable.

Definition at line 90 of file OneHotVariable.cc.

References coldvalue, hotvalue, i, PLearn::UnaryVariable::input, PLearn::Variable::nelems(), PLearn::Variable::value, and PLearn::Variable::valuedata.

{
    int index = int(input->valuedata[0]);
    if (nelems()==1)
        value[0] = index==0 ? coldvalue : hotvalue;
    else
    {
        for(int i=0; i<nelems(); i++)
            valuedata[i] = coldvalue;
        value[index] = hotvalue;
    }
}

Here is the call graph for this function:

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 54 of file OneHotVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 54 of file OneHotVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 54 of file OneHotVariable.cc.

void PLearn::OneHotVariable::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 86 of file OneHotVariable.cc.

References length_.

{ l=length_; w=1; }
void PLearn::OneHotVariable::rfprop ( ) [virtual]

Reimplemented from PLearn::Variable.

Definition at line 110 of file OneHotVariable.cc.

References PLearn::TVec< T >::length(), PLearn::UnaryVariable::resizeRValue(), and PLearn::Variable::rValue.

                            {
    if (rValue.length()==0) resizeRValue();
}

Here is the call graph for this function:

void PLearn::OneHotVariable::symbolicBprop ( ) [virtual]

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

Reimplemented from PLearn::Variable.

Definition at line 107 of file OneHotVariable.cc.

{}

Member Data Documentation

Reimplemented from PLearn::UnaryVariable.

Definition at line 69 of file OneHotVariable.h.

Definition at line 61 of file OneHotVariable.h.

Referenced by declareOptions(), and fprop().

Definition at line 60 of file OneHotVariable.h.

Referenced by declareOptions(), and fprop().

Definition at line 62 of file OneHotVariable.h.

Referenced by declareOptions(), and recomputeSize().


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