josiann.vsa

josiann.vsa(fun, x0, args=None, bounds=None, moves=((0.8, [Move] RandomStep(0.05)), (0.2, [Move] RandomStep(0.5))), nb_walkers=1, max_iter=200, max_measures=20, final_acceptance_probability=1e-300, epsilon=0.01, T_0=5.0, tol=0.001, vectorized_on_evaluations=True, vectorized_skip_marker=None, backup=False, nb_slots=None, seed=None, verbose=True, suppress_warnings=False, detect_convergence=True, window_size=None, dtype=<class 'numpy.float64'>)[source]

Simulated Annealing using vectorized cost functions for computing multiple function evaluations at once.

Parameters:
  • fun (Callable[..., list[float]]) – a <d> dimensional (noisy) function to minimize.

  • x0 (ndarray[Any, dtype[Any]]) – a <d> dimensional vector of initial values.

  • args (Optional[tuple[Any, ...]] (default: None)) – an optional sequence of arguments to pass to the function to minimize.

  • bounds (Optional[Sequence[tuple[float, float]]] (default: None)) – an optional sequence of bounds (one for each <n> dimensions) with the following format: (lower_bound, upper_bound) or a single (lower_bound, upper_bound) tuple of bounds to set for all dimensions.

  • moves (Union[Move, Sequence[Move], Sequence[tuple[float, Move]]] (default: ((0.8, [Move] RandomStep(0.05)), (0.2, [Move] RandomStep(0.5))))) –

    • a single josiann.Move object

    • a sequence of josiann.Move objects (all Moves have the same probability of being selected at each step

      for proposing a new candidate vector x)

    • a sequence of tuples with the following format(selection probability, josiann.Move)

      In this case, the selection probability dictates the probability of each Move of being selected at each step.

  • nb_walkers (int (default: 1)) – the number of parallel walkers in the ensemble.

  • max_iter (int (default: 200)) – the maximum number of iterations before stopping the algorithm.

  • max_measures (int (default: 20)) – the maximum number of function evaluations to average per step.

  • final_acceptance_probability (float (default: 1e-300)) – the targeted final acceptance probability at iteration <max_iter>.

  • epsilon (float (default: 0.01)) – parameter in (0, 1) for controlling the rate of standard deviation decrease (bigger values yield steeper descent profiles)

  • T_0 (float (default: 5.0)) – initial temperature value.

  • tol (float (default: 0.001)) – the convergence tolerance.

  • vectorized_on_evaluations (bool (default: True)) –

    the vectorization can happen on walkers or on function evaluations.

    • On function evaluations, a loop on walkers calls <fun> with a vector of positions of the walker, repeated

      for the number of needed function evaluations. Ex: 2 walkers with position vectors p1 and p2 each need n1 and n2 function evaluations. <fun> is first called for walker 1 with a vector (p1, p1, …, p1) of size n1, then <fun> is called for walker 2 with a vector (p2, p2, …, p2) of size n2. This is the default option and is valid when <fun> is ok with receiving vectors of varying length and when <max_measures> is greater than <nb_walkers>.

    • On walkers, a loop on function evaluations calls <fun> with a vector of fixed size = <nb_walkers>.

      Ex: 2 walkers with position vectors p1 and p2 each need n1 and n2 function evaluations. <fun> is called with vector (p1, p2) for max(n1, n2) times. Often, n1 =/= n2 which would yield unnecessary function evaluations (e.g. when n1 < n2, some evaluations of p1 are not needed while p2 is still evaluated). To indicated that to <fun>, the <vectorized_skip_marker> is passed instead of unnecessary position vectors (e.g. when n1 < n2, the vector passed to <fun> will eventually be (<vectorized_skip_marker>, p2) instead of (p1, p2)). This is valid when <fun> needs to receive vectors of fixed length and when <nb_walkers> is greater than <max_measures>.

  • vectorized_skip_marker (Optional[Any] (default: None)) – when vectorizing on walkers, the object to pass to <fun> to indicate that an evaluation for a particular position vector can be skipped.

  • backup (bool (default: False)) – use Backup for storing previously computed function evaluations and reusing them when returning to the same position vector ? (Only available when using SetStep moves).

  • nb_slots (Optional[int] (default: None)) – When using a vectorized function, the total number of position vectors for which the cost can be computed at once. For example, when using 5 walkers and 22 slots, each walker will be attributed respectively 5, 5, 4, 4, and 4 slots. Multiple slots per walker are used for exploring multiple possible moves from the starting position vector of each walker, increasing convergence speed.

  • seed (Optional[int] (default: None)) – a seed for the random generator.

  • verbose (bool (default: True)) – print progress bar ?

  • suppress_warnings (bool (default: False)) – remove warnings ?

  • detect_convergence (bool (default: True)) – run convergence detection for an early stop of the algorithm ?

  • window_size (Optional[int] (default: None)) – number of past iterations to look at for detecting the convergence, getting the best position and computing the acceptance fraction.

  • dtype (Union[float64, int64] (default: <class 'numpy.float64'>)) – the data type for the values stored in the Trace.

Return type:

Result

Returns:

A Result object.