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

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

#include <VerifyGradientCommand.h>

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

List of all members.

Public Member Functions

 VerifyGradientCommand ()
virtual void run (const std::vector< std::string > &args)
 The actual implementation of the 'VerifyGradientCommand' command.

Static Protected Attributes

static PLearnCommandRegistry reg_
 This allows to register the 'VerifyGradientCommand' command in the command registry.

Private Types

typedef PLearnCommand inherited

Detailed Description

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

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


Member Typedef Documentation

Definition at line 60 of file VerifyGradientCommand.h.


Constructor & Destructor Documentation

PLearn::VerifyGradientCommand::VerifyGradientCommand ( )

Definition at line 51 of file VerifyGradientCommand.cc.

    : PLearnCommand(
        "verify_gradient",
        "Verifies the gradient computation in a Variable through finite differences.",
        "verify_gradient 'MyVariable()' stepsize which_component input1_length input1_width input1_min input1_max input2_length input2_width input2_min input2_max \n"
        "The variable constructor can take option=value arguments if needed.\n"
        "stepsize is the size of the step taken for finite difference\n"
        "which_component specifies which element of MyVariable we feed gradients in (if MyVariable is not a scalar for ex.)\n"
        "if which_component is -1, then all elements will be fed gradient (same as considering gradient to the sum of all elements)\n"
        "input1_... and input2_... are required if the variable is a unary resp. binary variable.\n"
        "SourceVariables input1 and input2 of the specified size will be constructed \n"
        "and randomly initialized with a uniform between corresponding min and max.\n"
        )
{}

Member Function Documentation

void PLearn::VerifyGradientCommand::run ( const std::vector< std::string > &  args) [virtual]

The actual implementation of the 'VerifyGradientCommand' command.

Implements PLearn::PLearnCommand.

Definition at line 67 of file VerifyGradientCommand.cc.

References PLearn::TVec< T >::append(), PLearn::PRandom::common(), PLearn::endl(), PLearn::newObject(), PLearn::perr, PLERROR, PLearn::pout, PLearn::SourceVariable::randomInitialize(), PLearn::todouble(), PLearn::toint(), PLearn::var(), and w.

{
    if(args.size()<2)
        PLERROR("Not enough arguments provided");
    string varspec = args[0];
    Object* obj = newObject(varspec);
    Variable* varp = dynamic_cast<Variable*>(obj);
    if(!varp)
        PLERROR("The object you specified does not seem to be a known Variable (is it spelled correctly, did your executable link with it?)");
    Var var = varp;

    double stepsize = todouble(args[1]);
    int which_component = toint(args[2]);

    unsigned int nparents = (args.size()-3)/4;
    if(3+nparents*4 != args.size())
        PLERROR("You must specify 4 numbers (length, width, min, max) for each of the parents variable");

    VarArray parents;
    for(unsigned int k=0; k<nparents; k++)
    {
        int l = toint(args[3+k*4]);
        int w = toint(args[3+k*4+1]);
        double mi = todouble(args[3+k*4+2]);
        double ma = todouble(args[3+k*4+3]);
        perr << "Params: " << l << " " << w << " " << mi << " " << ma << endl;
        SourceVariable* sourcevar = new SourceVariable(l, w, "uniform", mi, ma);
        sourcevar->randomInitialize(PRandom::common());
        Var inputk = sourcevar;
        parents.append(inputk);
    }
    var->setParents(parents);
    var->build();

    pout << "parents:" << *parents[0] << endl;
    Func f(parents, var);
    pout << "func inputs:" << *(f->inputs[0]) << endl;

    f->verifyGradient(stepsize, which_component);
}

Here is the call graph for this function:


Member Data Documentation

This allows to register the 'VerifyGradientCommand' command in the command registry.

Definition at line 67 of file VerifyGradientCommand.h.


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