cbx.dynamics.CBS#

class cbx.dynamics.CBS(f, mode='sampling', noise='covariance', scheme='EM', M=1, track_args=None, **kwargs)[source]#

Bases: CBO

Consensus-Based Sampling (CBS) class.

Implements CBS as described in [1]. Two discretisation schemes are available:

  • scheme='EM' — Euler-Maruyama (inherited CBO step):

    \[X^{k+1} = X^k - dt\,(X^k - c_\alpha) + \text{noise}\]
  • scheme='exponential' — exponential integrator (exact linear solve):

    \[X^{k+1} = c_\alpha + e^{-dt}(X^k - c_\alpha) + \text{noise}\]

In both cases the noise uses the covariance noise model with the matching factor (\(\sqrt{2\,dt/\lambda}\) for EM and \(\sqrt{(1-e^{-2dt})/\lambda}\) for the exponential integrator), with \(\lambda = 1 + \alpha\).

Parameters:
  • f (callable) – The objective function.

  • mode (str, optional) – Passed to covariance_noise. Default: 'sampling'.

  • noise (str, optional) – Noise model. Default: 'covariance'.

  • scheme (str, optional) – Discretisation scheme: 'EM' or 'exponential'. Default: 'EM'.

References

inner_step()[source]#

This function is used in meth:step to perform the inner step. This function implements the actual update of the dynamic and is therfore the most important function in the dynamics class. This function should be overwritten by subclasses to perform any inner steps.

Parameters:

None

Returns:

None

optimize(sched='default')[source]#

Optimize the function using the dynmaic. This function perfoms the iterations as specified by step method and the update in inner_step().

Parameters:
  • print_int – int, optional The interval at which to print the current state of the optimization. If not provided, the default value is used. Defaults to None.

  • sched – str The scheduler to use for the optimization. If set to ‘default’, the default scheduler is used. If set to None, a scheduler is created based on the current optimization parameters. Defaults to ‘default’.

Returns:

The best particle found during the optimization process.

Return type:

best_particle

default_sched()[source]#

A function that returns a default scheduler.

Parameters:

None

Returns:

The scheduler object.

Return type:

scheduler