Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

PLearn::Function Class Reference

#include <Func.h>

Inheritance diagram for PLearn::Function:

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

Collaboration graph
[legend]
List of all members.

Public Types

typedef Object inherited

Public Member Functions

 Function ()
 Function *.

 Function (const VarArray &the_inputs, const VarArray &the_outputs)
 Function (const VarArray &the_inputs, const VarArray &parameters_to_optimize, const VarArray &the_outputs)
virtual void build ()
 simply calls inherited::build() then build_()

virtual void makeDeepCopyFromShallowCopy (map< const void *, void * > &copies)
 Transforms a shallow copy into a deep copy.

 PLEARN_DECLARE_OBJECT (Function)
void fprop (const Vec &in, const Vec &out) const
void fprop (const Array< Vec > &in, const Array< Vec > &out) const
void fbprop (const Vec &in, const Vec &out, const Vec &input_gradient, const Vec &output_gradient)
void fbprop (const Array< Vec > &in, const Array< Vec > &out, const Array< Vec > &input_gradient, const Array< Vec > &output_gradient)
void fbbprop (const Vec &in, const Vec &out, const Vec &gradient, const Mat &hessian)
 given input, compute output, gradient (=doutput/dinput) and hessian (=d^2output/dinput^2)

void fbbpropAcc (const Vec &in, const Vec &out, const Vec &gradient, const Mat &hessian)
 same thing but accumulate output, gradient and hessian

void rfprop (const Vec &in, const Vec &out, const Vec &input_rvalue, const Vec &output_rvalue, bool do_fprop=true)
void recomputeParents ()
 recomputes the value of all the vars that influence the output but do not depend on the declared inputs (shared parameters for instance...)

Func differentiate ()
Vec operator() (const Vec &input) const
real operator() (const Vec &input1, const Vec &input2) const
VarArray operator() (const VarArray &new_inputs) const
void verifyGradient (const Vec &in, real step=0.01)
 take the values given in the in Vec

void verifyHessian (const Vec &in, real step=0.01)
void verifyGradient (real minval, real maxval, real step=0.01)
 take the values randomly between minval and maxval

void verifyGradient (real step=0.01)
 take the current values of the inputs variables

void verifySymbolicGradient (const Vec &in)
void verifyrfprop (const Vec &in, real step=0.01)

Public Attributes

VarArray inputs
VarArray parameters
 nonInputSources

VarArray outputs
int inputsize
int outputsize
VarArray fproppath
VarArray bproppath
VarArray parentspath
 path on which to do a fprop to update the values of all the non-input direct parents on the fproppath (this will be called by method recomputeParents() )

Func df
 remembers the symbolic derivative


Static Protected Member Functions

void declareOptions (OptionList &ol)
 Declares this class' options.


Private Member Functions

void build_ ()
 This does the actual building.


Member Typedef Documentation

typedef Object PLearn::Function::inherited
 

Reimplemented from PLearn::Object.

Definition at line 135 of file Func.h.


Constructor & Destructor Documentation

PLearn::Function::Function  ) 
 

Function *.

Definition at line 103 of file Func.cc.

PLearn::Function::Function const VarArray the_inputs,
const VarArray the_outputs
 

Definition at line 108 of file Func.cc.

References build_().

PLearn::Function::Function const VarArray the_inputs,
const VarArray parameters_to_optimize,
const VarArray the_outputs
 

Definition at line 114 of file Func.cc.

References build_().


Member Function Documentation

void PLearn::Function::build  )  [virtual]
 

simply calls inherited::build() then build_()

Reimplemented from PLearn::Object.

Definition at line 181 of file Func.cc.

References build_().

void PLearn::Function::build_  )  [private]
 

This does the actual building.

Reimplemented from PLearn::Object.

Definition at line 141 of file Func.cc.

References bproppath, fproppath, inputs, inputsize, PLearn::TVec< Var >::isEmpty(), PLearn::TVec< Var >::length(), PLearn::VarArray::nelems(), PLearn::nonInputSources(), outputs, outputsize, parameters, parentspath, PLearn::propagationPath(), and PLearn::propagationPathToParentsOfPath().

Referenced by build(), and Function().

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

Declares this class' options.

Reimplemented from PLearn::Object.

Definition at line 128 of file Func.cc.

References PLearn::declareOption(), and PLearn::OptionList.

Func PLearn::Function::differentiate  ) 
 

Returns a Func that will compute the derivative of this function's output (expected to be a scalar) relative to the given input (of length inputsize) The computed derivative has (logically) also a length of inputsize. (This call uses symbolic gradient computation)

Definition at line 329 of file Func.cc.

References PLearn::VarArray::clearSymbolicGradient(), df, PLearn::endl(), fproppath, inputs, PLearn::TVec< Var >::isNull(), PLearn::VarArray::nelems(), outputs, PLearn::VarArray::parents(), PLERROR, PLearn::propagationPath(), PLearn::TVec< Var >::size(), PLearn::VarArray::symbolicBprop(), and PLearn::VarArray::symbolicGradient().

Referenced by fbbprop(), fbbpropAcc(), verifyrfprop(), and verifySymbolicGradient().

void PLearn::Function::fbbprop const Vec in,
const Vec out,
const Vec gradient,
const Mat hessian
 

given input, compute output, gradient (=doutput/dinput) and hessian (=d^2output/dinput^2)

Definition at line 259 of file Func.cc.

References df, differentiate(), PLearn::VarArray::fprop(), fproppath, inputs, PLearn::Mat, and outputs.

Referenced by verifyHessian(), and verifyrfprop().

void PLearn::Function::fbbpropAcc const Vec in,
const Vec out,
const Vec gradient,
const Mat hessian
 

same thing but accumulate output, gradient and hessian

Definition at line 288 of file Func.cc.

References PLearn::VarArray::accumulateTo(), df, differentiate(), PLearn::VarArray::fprop(), fproppath, inputs, and outputs.

void PLearn::Function::fbprop const Array< Vec > &  in,
const Array< Vec > &  out,
const Array< Vec > &  input_gradient,
const Array< Vec > &  output_gradient
 

Definition at line 243 of file Func.cc.

References PLearn::VarArray::clearGradient(), PLearn::VarArray::copyGradientFrom(), PLearn::VarArray::copyGradientTo(), PLearn::VarArray::fbprop(), fproppath, inputs, outputs, and PLERROR.

void PLearn::Function::fbprop const Vec in,
const Vec out,
const Vec input_gradient,
const Vec output_gradient
 

when put_gradient_on_first_element_only, a gradient of 1 is put in only the first element of the output gradient this is a hack that is useful for having a SumOfVariable computing several costs in parallel, but backpropagating only through the first

Definition at line 223 of file Func.cc.

References PLearn::VarArray::clearGradient(), PLearn::VarArray::copyGradientFrom(), PLearn::VarArray::copyGradientTo(), PLearn::displayVarGraph(), PLearn::VarArray::fbprop(), fproppath, inputs, outputs, and PLERROR.

Referenced by verifyGradient(), and verifySymbolicGradient().

void PLearn::Function::fprop const Array< Vec > &  in,
const Array< Vec > &  out
const
 

Definition at line 206 of file Func.cc.

References PLearn::VarArray::fprop(), fproppath, inputs, and outputs.

void PLearn::Function::fprop const Vec in,
const Vec out
const
 

Definition at line 199 of file Func.cc.

References PLearn::VarArray::fprop(), fproppath, inputs, outputs, and PLearn::Vec.

Referenced by operator()(), rfprop(), verifyGradient(), and verifyHessian().

void PLearn::Function::makeDeepCopyFromShallowCopy map< const void *, void * > &  copies  )  [virtual]
 

Transforms a shallow copy into a deep copy.

Definition at line 187 of file Func.cc.

References bproppath, PLearn::deepCopyField(), df, fproppath, inputs, outputs, parameters, and parentspath.

VarArray PLearn::Function::operator() const VarArray new_inputs  )  const
 

builds a whole new Var graph modeled after the current one but starting from new_inputs (instead of inputs) the resulting new_outputs var array is returned by the call All variables on the direct path from inputs to outputs are cloned but the parents of the cloned variables are the same as the originals (parents of the variables in the path are shared).

Definition at line 382 of file Func.cc.

References PLearn::CopiesMap, inputs, PLearn::TVec< Var >::length(), PLearn::VarArray::makeDeepCopyFromShallowCopy(), PLearn::nonInputParentsOfPath(), outputs, PLERROR, and PLearn::TVec< Var >::size().

real PLearn::Function::operator() const Vec input1,
const Vec input2
const
 

Definition at line 213 of file Func.cc.

References PLearn::VarArray::copyFrom(), PLearn::VarArray::fprop(), fproppath, inputs, outputs, outputsize, PLERROR, and PLearn::TVec< Var >::size().

Vec PLearn::Function::operator() const Vec input  )  const
 

Definition at line 373 of file Func.cc.

References fprop(), and outputsize.

PLearn::Function::PLEARN_DECLARE_OBJECT Function   ) 
 

void PLearn::Function::recomputeParents  ) 
 

recomputes the value of all the vars that influence the output but do not depend on the declared inputs (shared parameters for instance...)

Definition at line 326 of file Func.cc.

References PLearn::VarArray::fprop(), and parentspath.

void PLearn::Function::rfprop const Vec in,
const Vec out,
const Vec input_rvalue,
const Vec output_rvalue,
bool  do_fprop = true
 

Definition at line 317 of file Func.cc.

References PLearn::VarArray::copyRValueFrom(), PLearn::VarArray::copyRValueTo(), fprop(), fproppath, inputs, outputs, and PLearn::VarArray::rfprop().

void PLearn::Function::verifyGradient real  step = 0.01  ) 
 

take the current values of the inputs variables

Definition at line 576 of file Func.cc.

References inputs, inputsize, and verifyGradient().

void PLearn::Function::verifyGradient real  minval,
real  maxval,
real  step = 0.01
 

take the values randomly between minval and maxval

Definition at line 569 of file Func.cc.

References PLearn::fill_random_uniform(), inputsize, and verifyGradient().

void PLearn::Function::verifyGradient const Vec in,
real  step = 0.01
 

take the values given in the in Vec

Definition at line 519 of file Func.cc.

References PLearn::apply(), PLearn::TVec< T >::copy(), PLearn::dot(), PLearn::endl(), PLearn::FABS(), fbprop(), fprop(), inputsize, PLearn::max(), PLearn::norm(), outputsize, PLWARNING, and PLearn::tRealFunc.

Referenced by verifyGradient().

void PLearn::Function::verifyHessian const Vec in,
real  step = 0.01
 

Definition at line 439 of file Func.cc.

References PLearn::TMat< T >::copy(), PLearn::endl(), fbbprop(), fprop(), inputsize, PLearn::max(), outputsize, and PLERROR.

void PLearn::Function::verifyrfprop const Vec in,
real  step = 0.01
 

Definition at line 602 of file Func.cc.

References df, differentiate(), PLearn::endl(), fbbprop(), inputsize, PLearn::max(), outputsize, and PLearn::transposeProduct().

void PLearn::Function::verifySymbolicGradient const Vec in  ) 
 

Checks that the gradient computed by a bprop on the function and the gradient computed by a fprop on the symbolic derivative of the function give the same results

Definition at line 583 of file Func.cc.

References df, differentiate(), PLearn::displayFunction(), PLearn::endl(), fbprop(), inputsize, PLearn::TVec< T >::length(), outputsize, and PLERROR.


Member Data Documentation

VarArray PLearn::Function::bproppath
 

Definition at line 98 of file Func.h.

Referenced by build_(), and makeDeepCopyFromShallowCopy().

Func PLearn::Function::df
 

remembers the symbolic derivative

Definition at line 101 of file Func.h.

Referenced by differentiate(), fbbprop(), fbbpropAcc(), makeDeepCopyFromShallowCopy(), verifyrfprop(), and verifySymbolicGradient().

VarArray PLearn::Function::fproppath [mutable]
 

Definition at line 97 of file Func.h.

Referenced by build_(), differentiate(), fbbprop(), fbbpropAcc(), fbprop(), fprop(), makeDeepCopyFromShallowCopy(), operator()(), and rfprop().

VarArray PLearn::Function::inputs [mutable]
 

Definition at line 90 of file Func.h.

Referenced by build_(), differentiate(), fbbprop(), fbbpropAcc(), fbprop(), fprop(), makeDeepCopyFromShallowCopy(), operator()(), rfprop(), and verifyGradient().

int PLearn::Function::inputsize
 

Definition at line 95 of file Func.h.

Referenced by build_(), verifyGradient(), verifyHessian(), verifyrfprop(), and verifySymbolicGradient().

VarArray PLearn::Function::outputs [mutable]
 

Definition at line 92 of file Func.h.

Referenced by build_(), differentiate(), fbbprop(), fbbpropAcc(), fbprop(), fprop(), makeDeepCopyFromShallowCopy(), operator()(), and rfprop().

int PLearn::Function::outputsize
 

Definition at line 96 of file Func.h.

Referenced by build_(), operator()(), verifyGradient(), verifyHessian(), verifyrfprop(), and verifySymbolicGradient().

VarArray PLearn::Function::parameters [mutable]
 

nonInputSources

Definition at line 91 of file Func.h.

Referenced by build_(), and makeDeepCopyFromShallowCopy().

VarArray PLearn::Function::parentspath
 

path on which to do a fprop to update the values of all the non-input direct parents on the fproppath (this will be called by method recomputeParents() )

Definition at line 99 of file Func.h.

Referenced by build_(), makeDeepCopyFromShallowCopy(), and recomputeParents().


The documentation for this class was generated from the following files:
Generated on Tue Aug 17 16:24:56 2004 for PLearn by doxygen 1.3.7