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 and batch_subgradient, batch_jacobian and batch_hessian methods return a subgradient, jacobian and hessian computed at on the last batch.

Parameters
  • fn_list (list) – list of AbstractFunction objects

  • probabilities (list, optional) – list with the probabilities of drawing each function. Default is None which leads to uniform probabilities

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

eval(x)[source]

Evaluate the function at a point x

Parameters

x (ndarray) – input point

Return type

ndarray

jacobian(x, **kwargs)

Evaluate the jacobian of the the function at a point x

Parameters

x (ndarray) – input point

Return type

ndarray

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

ndarray

batch_hessian(x)[source]

evaluate the hessian on the current batch

Parameters

x (np.ndarray) – point

Returns

hessian

Return type

numpy.ndarray

batch_jacobian(x)[source]

evaluate the jacobian on the current batch

Parameters

x (np.ndarray) – point

Returns

jacobian

Return type

numpy.ndarray

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

numpy.ndarray

random_batch(batch_size=1)[source]

generate a random batch from the function.

Parameters

batch_size (int, optional) – batch size. Defaults to 1.

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 1

  • axis (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