@CodeReview(reviewer="Kevin R. Dixon", date="2008-07-23", changesNeeded=false, comments={"Minor change to class javadoc.","Looks fine."}) @PublicationReference(author="Wikipedia", title="Numerical differentiation", type=WebPage, year=2009, url="http://en.wikipedia.org/wiki/Numerical_differentiation") public class GradientDescendableApproximator extends AbstractCloneableSerializable implements GradientDescendable
radientDescendable
from a
VectorizableVectorFunction
by estimating the parameter gradient
using a forward-difference approximation of the parameter Jacobian.
Requires N+1 VectorFunction evaluations to approximate the Jacobian, where N
is the number of parameters in the VectorizableVectorFunction
.
To compute the approximated derivative of the output with respect to the
input, use NumericalDifferentiator.NumericalDifferentiator
,
Serialized FormModifier and Type | Field and Description |
---|---|
static double |
DEFAULT_DELTA_SIZE
Default deltaSize, 1.0E-5
|
Constructor and Description |
---|
GradientDescendableApproximator()
Default constructor.
|
GradientDescendableApproximator(VectorizableVectorFunction function)
Creates a new instance of GradientDescendableApproximator
|
GradientDescendableApproximator(VectorizableVectorFunction function,
double deltaSize)
Creates a new instance of GradientDescendableApproximator
|
Modifier and Type | Method and Description |
---|---|
GradientDescendableApproximator |
clone()
This makes public the clone method on the
Object class and
removes the exception that it throws. |
Matrix |
computeParameterGradient(Vector input)
Computes a forward-differences approximation to the parameter Jacobian
|
static Matrix |
computeParameterGradient(VectorizableVectorFunction function,
Vector input,
double deltaSize)
Computes a forward-differences approximation to the parameter Jacobian
|
void |
convertFromVector(Vector parameters)
Converts the object from a Vector of parameters.
|
Vector |
convertToVector()
Converts the object to a vector.
|
Vector |
evaluate(Vector input)
Evaluates the function on the given input and returns the output.
|
double |
getDeltaSize()
Getter for deltaSize
|
VectorizableVectorFunction |
getFunction()
Getter for function
|
void |
setDeltaSize(double deltaSize)
Setter for deltaSize
|
void |
setFunction(VectorizableVectorFunction function)
Setter for function
|
public static final double DEFAULT_DELTA_SIZE
public GradientDescendableApproximator()
public GradientDescendableApproximator(VectorizableVectorFunction function)
function
- Internal VectorizableVectorFunction to considerpublic GradientDescendableApproximator(VectorizableVectorFunction function, double deltaSize)
function
- Internal VectorizableVectorFunction to considerdeltaSize
- Size of the finite-difference unit vectors, typically ~1e-5public GradientDescendableApproximator clone()
AbstractCloneableSerializable
Object
class and
removes the exception that it throws. Its default behavior is to
automatically create a clone of the exact type of object that the
clone is called on and to copy all primitives but to keep all references,
which means it is a shallow copy.
Extensions of this class may want to override this method (but call
super.clone()
to implement a "smart copy". That is, to target
the most common use case for creating a copy of the object. Because of
the default behavior being a shallow copy, extending classes only need
to handle fields that need to have a deeper copy (or those that need to
be reset). Some of the methods in ObjectUtil
may be helpful in
implementing a custom clone method.
Note: The contract of this method is that you must use
super.clone()
as the basis for your implementation.clone
in interface GradientDescendable
clone
in interface Vectorizable
clone
in interface VectorizableVectorFunction
clone
in interface CloneableSerializable
clone
in class AbstractCloneableSerializable
public VectorizableVectorFunction getFunction()
public void setFunction(VectorizableVectorFunction function)
function
- Internal VectorizableVectorFunction to considerpublic Vector convertToVector()
Vectorizable
convertToVector
in interface Vectorizable
public void convertFromVector(Vector parameters)
Vectorizable
convertFromVector
in interface Vectorizable
parameters
- The parameters to incorporate.public Vector evaluate(Vector input)
Evaluator
public static Matrix computeParameterGradient(VectorizableVectorFunction function, Vector input, double deltaSize)
function
- Internal VectorizableVectorFunction to considerinput
- Input about which to estimate the JacobiandeltaSize
- Size of the finite-difference unit vectors, typically ~1e-5public Matrix computeParameterGradient(Vector input)
computeParameterGradient
in interface GradientDescendable
computeParameterGradient
in interface ParameterGradientEvaluator<Vector,Vector,Matrix>
input
- Input about which to estimate the Jacobianpublic double getDeltaSize()
public void setDeltaSize(double deltaSize)
deltaSize
- Size of the finite-difference unit vectors, typically ~1e-5