panobbgo.lib.classic.Rosenbrock#

class panobbgo.lib.classic.Rosenbrock(dims: int | None = None, par1: float = 100, optimum: Any = None, box: Sequence[Tuple[float, float]] | None = None, **kwargs: Any)[source]#

Rosenbrock function with parameter par1 and configurable optimum location.

\[f(x) = \sum_i (\mathit{par}_1 (y_{i+1} - y_i^2)^2 + (1-y_i)^2)\]

where \(y = x - \mathit{optimum} + \mathbf{1}\) shifts the optimum from the standard location \(\mathbf{1} = (1, 1, \ldots, 1)\) to the specified optimum location.

Parameters:
  • dims (int, optional) – Number of dimensions. Can be omitted if optimum is a vector.

  • par1 (float, optional) – Coefficient for the quadratic term (default: 100). Higher values create a steeper, narrower valley.

  • optimum (float or array-like, optional) – Location of the optimum. Can be: - A scalar: applied to all dimensions (default: 1.0) - A vector: specifies each coordinate of the optimum If a vector is provided and dims is omitted, dims is inferred.

  • box (list of tuples, optional) – Custom bounding box. If not provided, defaults to [(-2, 2)] * dims with the first dimension adjusted to (0, 2).

Examples

Standard 2D Rosenbrock with optimum at [1, 1]:

>>> from panobbgo.lib.classic import Rosenbrock
>>> problem = Rosenbrock(dims=2)

2D Rosenbrock with optimum at [5, 3]:

>>> problem = Rosenbrock(dims=2, optimum=[5, 3], box=[(-10, 10), (-10, 10)])

Infer dims from optimum vector:

>>> problem = Rosenbrock(optimum=[24, -12], box=[(-100, 100), (-100, 100)])
Parameters:
  • box (list) – list of tuples for the bounding box with length n, e.g.: \(\left[ (-1,1), (-100, 0), (0, 0.01) \right]\).

  • dx (list) – translation of the whole problem, an n-dimensional vector (default: None). The search box becomes box + dx and the objective is evaluated at x - dx, i.e. the problem seen by the optimiser is \(g(x) = f(x - dx)\) and a minimiser \(x^*\) of \(f\) moves to \(x^* + dx\). Every point the objective sees lies in the original box.

__init__(dims: int | None = None, par1: float = 100, optimum: Any = None, box: Sequence[Tuple[float, float]] | None = None, **kwargs: Any)[source]#
Parameters:
  • box (list) – list of tuples for the bounding box with length n, e.g.: \(\left[ (-1,1), (-100, 0), (0, 0.01) \right]\).

  • dx (list) – translation of the whole problem, an n-dimensional vector (default: None). The search box becomes box + dx and the objective is evaluated at x - dx, i.e. the problem seen by the optimiser is \(g(x) = f(x - dx)\) and a minimiser \(x^*\) of \(f\) moves to \(x^* + dx\). Every point the objective sees lies in the original box.

Methods

__init__([dims, par1, optimum, box])

eval(x)

This is called to evaluate the given black-box function.

eval_constraints(x)

This method is optionally overwritten by the problem to calculate the constraint violations.

project(point)

projects given point into the search box.

random_point([distribution, rng])

Generates a random point inside the given search box.

Attributes

box

The bounding box for this problem, a \((\mathit{dim},2)\)-array.

center

center of the box

dim

The number of dimensions.

ranges

The ranges along each dimension, a numpy.ndarray.