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

#include <MultiSampleVariable.h>

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

List of all members.

Public Member Functions

 MultiSampleVariable ()
 Default constructor, usually does nothing.
 MultiSampleVariable (Variable *input, int groupsize)
 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 string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual MultiSampleVariabledeepCopy (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_ ()
 MultiSampleVariable.
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 groupsize
 ### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //!
PP< PRandomrandom_gen

Static Public Attributes

static StaticInitializer _static_initializer_

Static Protected Member Functions

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

Private Types

typedef UnaryVariable inherited

Private Member Functions

void build_ ()
 This does the actual building.
void sample_range (Vec &x, Vec &y, int start, int length)

Detailed Description

* MultiSampleVariable *

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 58 of file MultiSampleVariable.h.


Member Typedef Documentation

Reimplemented from PLearn::UnaryVariable.

Definition at line 60 of file MultiSampleVariable.h.


Constructor & Destructor Documentation

PLearn::MultiSampleVariable::MultiSampleVariable ( ) [inline]

Default constructor, usually does nothing.

Definition at line 75 of file MultiSampleVariable.h.

                         :
         groupsize(-1)
    {}
PLearn::MultiSampleVariable::MultiSampleVariable ( Variable input,
int  groupsize 
)

Constructor.

Definition at line 58 of file MultiSampleVariable.cc.

References build_().

    : inherited(input, input->length(), input->width()),
      groupsize(groupsize),
      random_gen(NULL)
{
    build_();
}

Here is the call graph for this function:


Member Function Documentation

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

MultiSampleVariable.

Reimplemented from PLearn::UnaryVariable.

Definition at line 53 of file MultiSampleVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 53 of file MultiSampleVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 53 of file MultiSampleVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 53 of file MultiSampleVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 53 of file MultiSampleVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 53 of file MultiSampleVariable.cc.

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

Nothing to do by default.

Reimplemented from PLearn::UnaryVariable.

Definition at line 106 of file MultiSampleVariable.cc.

{}    
void PLearn::MultiSampleVariable::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 115 of file MultiSampleVariable.cc.

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

Here is the call graph for this function:

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

This does the actual building.

Reimplemented from PLearn::UnaryVariable.

Definition at line 161 of file MultiSampleVariable.cc.

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

Referenced by build(), and MultiSampleVariable().

{
    // ### 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.
    
    if (groupsize <= 0)
        PLERROR("Groupsize(s) not specified or invalid in MultiSampleVariable");    
    if (input->width() % groupsize != 0)
        PLERROR("Invalid groupsize in MultiSampleVariable (%i does not divide %i)", groupsize, input->width());
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 53 of file MultiSampleVariable.cc.

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

Declares the class options.

Reimplemented from PLearn::UnaryVariable.

Definition at line 134 of file MultiSampleVariable.cc.

References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::UnaryVariable::declareOptions(), groupsize, 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)

    // ### ex:
    //declareOption(ol, "groupsizes", &MultiSampleVariable::groupsizes,
    //              OptionBase::buildoption,
    //              "this tells how to \"divide\" our diffrents inputs\nex: groupsizes = [1,2,3] says we divide our output like this :\n[x1],[x2,x3],[x4,x5,x6] and apply a maximum algorithm on each group separately");

    declareOption(ol, "groupsize", &MultiSampleVariable::groupsize,
                  OptionBase::buildoption,
                  "shortcut if you want all groupsizes to be equals, for example if you set the value of this option to be 3, it will make groupsizes = [3,3,...,3]");   

    declareOption(ol, "random_gen", &MultiSampleVariable::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::MultiSampleVariable::declaringFile ( ) [inline, static]

Reimplemented from PLearn::UnaryVariable.

Definition at line 102 of file MultiSampleVariable.h.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 53 of file MultiSampleVariable.cc.

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

Nothing to do by default.

Reimplemented from PLearn::UnaryVariable.

Definition at line 76 of file MultiSampleVariable.cc.

References PLearn::PRandom::common(), groupsize, i, PLearn::UnaryVariable::input, PLearn::PP< T >::isNull(), PLearn::TVec< T >::length(), PLearn::TMat< T >::length(), PLearn::Variable::matValue, n, random_gen, sample_range(), and PLearn::Variable::width().

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

    int k;
    Mat inputValue = input->matValue;

    Vec inputValue_n;
    Vec value_n;

    for(int n=0; n<inputValue.length(); n++)
    {
        k=0;
        inputValue_n = inputValue(n);
        value_n = matValue(n);

        //we set all values to 0. before sampling "ones"
        for (int i=0; i<value_n.length(); i++)
            value_n[i]=0.;
        
        while ( k < this->width() )
        {            
            sample_range(inputValue_n, value_n, k, groupsize);         
            k+=groupsize;
        }
    }
}

Here is the call graph for this function:

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 53 of file MultiSampleVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 53 of file MultiSampleVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 53 of file MultiSampleVariable.cc.

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

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::UnaryVariable.

Definition at line 121 of file MultiSampleVariable.cc.

References PLearn::UnaryVariable::makeDeepCopyFromShallowCopy().

{
    inherited::makeDeepCopyFromShallowCopy(copies);

    // ### Call deepCopyField on all "pointer-like" fields
    // ### that you wish to be deepCopied rather than
    // ### shallow-copied.
    // ### ex:
    //deepCopyField(groupsizes, copies);
    // ### If you want to deepCopy a Var field:
    // varDeepCopyField(somevariable, copies);   
}

Here is the call graph for this function:

void PLearn::MultiSampleVariable::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 66 of file MultiSampleVariable.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::MultiSampleVariable::sample_range ( Vec x,
Vec y,
int  start,
int  length 
) [private]

Definition at line 185 of file MultiSampleVariable.cc.

References random_gen, and PLearn::TVec< T >::subVec().

Referenced by fprop().

{
    if(length != 1)
    {
        y[start+random_gen->multinomial_sample(x.subVec(start,length))] = 1;
    }
    else // if groupsize == 1
    {
        Vec temp(2);
        temp[0] = 1.-x[start];
        temp[1] = temp[0];
        y[start] = random_gen->multinomial_sample(temp);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Reimplemented from PLearn::UnaryVariable.

Definition at line 102 of file MultiSampleVariable.h.

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

Definition at line 67 of file MultiSampleVariable.h.

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

Definition at line 69 of file MultiSampleVariable.h.

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


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