CenteredFiniteDifferenceGradient

class CenteredFiniteDifferenceGradient(*args)

First order centered finite-difference scheme.

Available constructors:

CenteredFiniteDifferenceGradient(epsilon, evalImpl)

CenteredFiniteDifferenceGradient(step, evalImpl)

Parameters:

evalImpl : NumericalMathEvaluationImplementation

Implementation of the evaluation of a function.

epsilon : float, sequence of float

Finite difference steps for each dimension.

step : FiniteDifferenceStep

Defines how finite difference steps values are computed.

Notes

CenteredFiniteDifferenceGradient provides a first order centered finite- difference scheme:

\frac{\partial f_j}{\partial x_i} \approx \frac{f_j(x + \epsilon_i) - f_j(x - \epsilon_i)}
                                               {2 \epsilon_i}

Examples

>>> import openturns as ot
>>> formulas = ['x1 * sin(x2)', 'cos(x1 + x2)', '(x2 + 1) * exp(x1 - 2 * x2)']
>>> myFunc = ot.SymbolicFunction(['x1', 'x2'], formulas)
>>> epsilon = [0.01]*2
>>> myGradient = ot.CenteredFiniteDifferenceGradient(epsilon, myFunc.getEvaluation())
>>> inPoint = [1.]*2
>>> print(myGradient.gradient(inPoint))
[[  0.841471 -0.909282  0.735771 ]
 [  0.540293 -0.909282 -1.10366  ]]

Methods

getCallsNumber() Accessor to the number of times the gradient has been called.
getClassName() Accessor to the object’s name.
getEpsilon() Get the finite difference steps.
getEvaluation() Get the implementation of the evaluation of the function.
getFiniteDifferenceStep() Get the finite difference step.
getId() Accessor to the object’s id.
getInputDimension() Get the input dimension.
getMarginal(*args) Accessor to the gradient implementation of a specific output.
getName() Accessor to the object’s name.
getOutputDimension() Get the output dimension.
getParameter() Accessor to the parameter values.
getShadowedId() Accessor to the object’s shadowed id.
getVisibility() Accessor to the object’s visibility state.
gradient(inP) Get the gradient at some point.
hasName() Test if the object is named.
hasVisibleName() Test if the object has a distinguishable name.
isActualImplementation() Accessor to the validity flag.
setFiniteDifferenceStep(finiteDifferenceStep) Set the finite difference step.
setName(name) Accessor to the object’s name.
setParameter(parameter) Accessor to the parameter values.
setShadowedId(id) Accessor to the object’s shadowed id.
setVisibility(visible) Accessor to the object’s visibility state.
__init__(*args)
getCallsNumber()

Accessor to the number of times the gradient has been called.

Returns:

calls_number : int

Integer that counts the number of times the gradient has been called since its creation.

getClassName()

Accessor to the object’s name.

Returns:

class_name : str

The object class name (object.__class__.__name__).

getEpsilon()

Get the finite difference steps.

Returns:

epsilon : NumericalPoint

Finite difference steps for each dimension.

getEvaluation()

Get the implementation of the evaluation of the function.

Returns:

evalImpl : NumericalMathFunctionEvaluationImplementation

Implementation of the evaluation of a function.

getFiniteDifferenceStep()

Get the finite difference step.

Returns:

step : FiniteDifferenceStep

Defines how finite difference steps values are computed.

getId()

Accessor to the object’s id.

Returns:

id : int

Internal unique identifier.

getInputDimension()

Get the input dimension.

Returns:

dimension : int

Input dimension.

getMarginal(*args)

Accessor to the gradient implementation of a specific output.

Parameters:

i : integer

Integer corresponding to the output (Care: it starts at 0).

indices : sequence of integer

The set of indices for which the outputs are extracted.

Returns:

gradientImplementation : NumericalMathGradientImplementation

A gradient implementation restricted to its compenents functions which indices are i or indices.

getName()

Accessor to the object’s name.

Returns:

name : str

The name of the object.

getOutputDimension()

Get the output dimension.

Returns:

dimension : int

Output dimension.

getParameter()

Accessor to the parameter values.

Returns:

parameter : NumericalPoint

The parameter values.

getShadowedId()

Accessor to the object’s shadowed id.

Returns:

id : int

Internal unique identifier.

getVisibility()

Accessor to the object’s visibility state.

Returns:

visible : bool

Visibility flag.

gradient(inP)

Get the gradient at some point.

Parameters:

point : sequence of float

Point where the gradient is computed.

Returns:

gradient : Matrix

Transposed Jacobian matrix evaluated at point.

hasName()

Test if the object is named.

Returns:

hasName : bool

True if the name is not empty.

hasVisibleName()

Test if the object has a distinguishable name.

Returns:

hasVisibleName : bool

True if the name is not empty and not the default one.

isActualImplementation()

Accessor to the validity flag.

Returns:

is_impl : bool

Whether the implementation is valid.

setFiniteDifferenceStep(finiteDifferenceStep)

Set the finite difference step.

Parameters:

step : FiniteDifferenceStep

Defines how finite difference steps values are computed.

setName(name)

Accessor to the object’s name.

Parameters:

name : str

The name of the object.

setParameter(parameter)

Accessor to the parameter values.

Parameters:

parameter : sequence of float

The parameter values.

setShadowedId(id)

Accessor to the object’s shadowed id.

Parameters:

id : int

Internal unique identifier.

setVisibility(visible)

Accessor to the object’s visibility state.

Parameters:

visible : bool

Visibility flag.