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::RandomForcedValuesVariable Class Reference

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

#include <RandomForcedValuesVariable.h>

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

List of all members.

Public Member Functions

 RandomForcedValuesVariable ()
 Default constructor, usually does nothing.
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 string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual
RandomForcedValuesVariable
deepCopy (CopiesMap &copies) const
virtual void build ()
 Post-constructor.
virtual void makeDeepCopyFromShallowCopy (CopiesMap &copies)
 Transforms a shallow copy into a deep copy.

Static Public Member Functions

static string _classname_ ()
 RandomForcedValuesVariable.
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

PP< PRandomrandom_gen
 ### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //!
real forcing_prob
real forcing_value

Static Public Attributes

static StaticInitializer _static_initializer_

Static Protected Member Functions

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

Protected Attributes

TVec< boolforced

Private Types

typedef UnaryVariable inherited

Private Member Functions

void build_ ()
 This does the actual building.

Detailed Description

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

* RandomForcedValuesVariable * 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 61 of file RandomForcedValuesVariable.h.


Member Typedef Documentation

Reimplemented from PLearn::UnaryVariable.

Definition at line 63 of file RandomForcedValuesVariable.h.


Constructor & Destructor Documentation

PLearn::RandomForcedValuesVariable::RandomForcedValuesVariable ( )

Default constructor, usually does nothing.

Definition at line 53 of file RandomForcedValuesVariable.cc.

    :forcing_prob(0),
     forcing_value(0)

    /* ### Initialize all fields to their default value */
{
    // ### You may (or not) want to call build_() to finish building the object
    // ### (doing so assumes the parent classes' build_() have been called too
    // ### in the parent classes' constructors, something that you must ensure)
}

Member Function Documentation

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

RandomForcedValuesVariable.

Reimplemented from PLearn::UnaryVariable.

Definition at line 51 of file RandomForcedValuesVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 51 of file RandomForcedValuesVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 51 of file RandomForcedValuesVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 51 of file RandomForcedValuesVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 51 of file RandomForcedValuesVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 51 of file RandomForcedValuesVariable.cc.

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

Nothing to do by default.

Reimplemented from PLearn::UnaryVariable.

Definition at line 114 of file RandomForcedValuesVariable.cc.

References forced, PLearn::Variable::gradient, PLearn::Variable::gradientdata, i, PLearn::UnaryVariable::input, PLearn::TVec< T >::length(), and n.

{
    int n = gradient.length();
    for(int i=0; i<n; i++)
    {
        if(!forced[i])
            input->gradientdata[i] += gradientdata[i];
    }
}

Here is the call graph for this function:

void PLearn::RandomForcedValuesVariable::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 131 of file RandomForcedValuesVariable.cc.

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

Here is the call graph for this function:

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

This does the actual building.

Reimplemented from PLearn::UnaryVariable.

Definition at line 175 of file RandomForcedValuesVariable.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::RandomForcedValuesVariable::classname ( ) const [virtual]

Reimplemented from PLearn::UnaryVariable.

Definition at line 51 of file RandomForcedValuesVariable.cc.

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

Declares the class options.

Reimplemented from PLearn::UnaryVariable.

Definition at line 151 of file RandomForcedValuesVariable.cc.

References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::UnaryVariable::declareOptions(), forcing_prob, forcing_value, and random_gen.

{
    // ### 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)

    declareOption(ol, "forcing_prob", &RandomForcedValuesVariable::forcing_prob,
                  OptionBase::buildoption,
                  "The probability of forcing each input to forcing_value");
    declareOption(ol, "forcing_value", &RandomForcedValuesVariable::forcing_value,
                  OptionBase::buildoption,
                  "The value to which to set all inputs that have been elected to be forced.");
    declareOption(ol, "random_gen", &RandomForcedValuesVariable::random_gen,
                  OptionBase::buildoption,
                  "Random number generator. If null, the PRandom::common(false) generator will be used.");

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

Here is the call graph for this function:

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 102 of file RandomForcedValuesVariable.h.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 51 of file RandomForcedValuesVariable.cc.

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

Nothing to do by default.

Reimplemented from PLearn::UnaryVariable.

Definition at line 87 of file RandomForcedValuesVariable.cc.

References PLearn::UnaryVariable::checkContiguity(), PLearn::PRandom::common(), forced, forcing_prob, forcing_value, i, PLearn::UnaryVariable::input, PLearn::PP< T >::isNull(), PLearn::TVec< T >::length(), n, random_gen, PLearn::TVec< T >::resize(), PLearn::Variable::value, and PLearn::Variable::valuedata.

{
    checkContiguity();

    if(random_gen.isNull())
        random_gen = PRandom::common(false);


    int n = value.length();
    forced.resize(n);

    for(int i=0; i<n; i++)
    {
        if(random_gen->uniform_sample()<forcing_prob)
        {
            valuedata[i] = forcing_value;
            forced[i] = true;
        }
        else
        {
            valuedata[i] = input->valuedata[i];
            forced[i] = false;
        }
    }
}

Here is the call graph for this function:

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 51 of file RandomForcedValuesVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 51 of file RandomForcedValuesVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 51 of file RandomForcedValuesVariable.cc.

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

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::UnaryVariable.

Definition at line 137 of file RandomForcedValuesVariable.cc.

References PLearn::deepCopyField(), PLearn::UnaryVariable::makeDeepCopyFromShallowCopy(), and random_gen.

{
    inherited::makeDeepCopyFromShallowCopy(copies);

    // ### Call deepCopyField on all "pointer-like" fields
    // ### that you wish to be deepCopied rather than
    // ### shallow-copied.
    // ### ex:
    deepCopyField(random_gen, copies);

    // ### If you want to deepCopy a Var field:
    // varDeepCopyField(somevariable, copies);
}

Here is the call graph for this function:

void PLearn::RandomForcedValuesVariable::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 75 of file RandomForcedValuesVariable.cc.

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

{
    if (input) 
    {
        l = input.length();
        w = input.width(); // the computed width
    } 
    else
        l = w = 0;
}

Here is the call graph for this function:


Member Data Documentation

Reimplemented from PLearn::UnaryVariable.

Definition at line 102 of file RandomForcedValuesVariable.h.

Definition at line 118 of file RandomForcedValuesVariable.h.

Referenced by bprop(), and fprop().

Definition at line 71 of file RandomForcedValuesVariable.h.

Referenced by declareOptions(), and fprop().

Definition at line 72 of file RandomForcedValuesVariable.h.

Referenced by declareOptions(), and fprop().

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

Definition at line 70 of file RandomForcedValuesVariable.h.

Referenced by declareOptions(), fprop(), and makeDeepCopyFromShallowCopy().


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