Special Functions¶
Stochastic Function¶
- class disropt.functions.stochastic_function.StochasticFunction(fn_list, probabilities)[source]¶
Bases:
disropt.functions.abstract_function.AbstractFunction
Stochastic function
\[f(x)=\mathbb{E}[h(x)]\]with \(x: \mathbb{R}^{n}\).
The
random_batch
method extract a batch from the function andbatch_subgradient
,batch_jacobian
andbatch_hessian
methods return a subgradient, jacobian and hessian computed at on the last batch.- Parameters
- Raises
TypeError – fn_list input must be a list of functions
ValueError – All functions must have the same input/output shape
TypeError – probabilities argument must be a list of floats
ValueError – inputs must have the same lenght
ValueError – provided probabilities must sum to 1
NotImplementedError – only 1, 2 and inf norms are currently supported
- jacobian(x, **kwargs)¶
Evaluate the jacobian of the the function at a point x
- subgradient(x, **kwargs)¶
Evaluate the subgradient of the function at a point x
- Parameters
x (
ndarray
) – input point- Raises
ValueError – subgradient is defined only for functions with scalar output
- Return type
- batch_hessian(x)[source]¶
evaluate the hessian on the current batch
- Parameters
x (np.ndarray) – point
- Returns
hessian
- Return type
- batch_jacobian(x)[source]¶
evaluate the jacobian on the current batch
- Parameters
x (np.ndarray) – point
- Returns
jacobian
- Return type
- batch_subgradient(x)[source]¶
evaluate the subgradient on the current batch
- Parameters
x (np.ndarray) – point
- Raises
ValueError – Only functions with scalar output have a subgradient
- Returns
subgradient
- Return type
Function With Extended Variable¶
- class disropt.functions.extended_function.ExtendedFunction(fn, n_var=1, axis=- 1, pos=0)[source]¶
Bases:
disropt.functions.abstract_function.AbstractFunction
Function with extended variable
\[f(x, y) = x\]with \(x\in \mathbb{R}^{n}, y\in \mathbb{R}^{m}\)
- Parameters
fn (AbstractFunction) – input function
n_var (
int
) – number of additional variables. Defaults to 1axis (
int
) – axis along which the additional variables are appended. Defaults to -1 (the last valid one)pos (
int
) – position index of the old variable vector. Defaults to 0
- Raises