pypesto.startpoint

Startpoint

Methods for selecting points that can be used as startpoints for multi-start optimization. Startpoint methods can be implemented by deriving from pypesto.startpoint.StartpointMethod.

class pypesto.startpoint.CheckedStartpoints[source]

Bases: StartpointMethod, ABC

Startpoints checked for function value and/or gradient finiteness.

__call__(n_starts, problem)[source]

Generate checked startpoints.

Return type:

ndarray

Parameters:
__init__(use_guesses=True, check_fval=False, check_grad=False)[source]

Initialize.

Parameters:
  • use_guesses (bool) – Whether to use guesses provided in the problem.

  • check_fval (bool) – Whether to check function values at the startpoint, and resample if not finite.

  • check_grad (bool) – Whether to check gradients at the startpoint, and resample if not finite.

check_and_resample(xs, lb, ub, objective)[source]

Check sampled points for fval, grad, and potentially resample ones.

Parameters:
  • xs (Startpoints candidates, shape (n_starts, n_par).) –

  • lb (Lower parameter bound.) –

  • ub (Upper parameter bound.) –

  • objective (Objective function, for evaluation.) –

Return type:

ndarray

Returns:

xs – Checked and potentially partially resampled startpoints, shape (n_starts, n_par).

abstract sample(n_starts, lb, ub)[source]

Actually sample startpoints.

While in this implementation, __call__ handles the checking of guesses and resampling, this method defines the actual sampling.

Parameters:
  • n_starts (Number of startpoints to generate.) –

  • lb (Lower parameter bound.) –

  • ub (Upper parameter bound.) –

Return type:

ndarray

Returns:

xs (Startpoints, shape (n_starts, n_par).)

class pypesto.startpoint.FunctionStartpoints[source]

Bases: CheckedStartpoints

Define startpoints via callable.

The callable should take the same arguments as the __call__ method.

__init__(function, use_guesses=True, check_fval=False, check_grad=False)[source]

Initialize.

Parameters:
  • function (The callable sampling startpoints.) –

  • use_guesses (As in CheckedStartpoints.) –

  • check_fval (As in CheckedStartpoints.) –

  • check_grad (As in CheckedStartpoints.) –

sample(n_starts, lb, ub)[source]

Call function.

Return type:

ndarray

Parameters:
class pypesto.startpoint.LatinHypercubeStartpoints[source]

Bases: CheckedStartpoints

Generate latin hypercube-sampled startpoints.

See e.g. https://en.wikipedia.org/wiki/Latin_hypercube_sampling.

__init__(use_guesses=True, check_fval=False, check_grad=False, smooth=True)[source]

Initialize.

Parameters:
  • use_guesses (bool) – As in CheckedStartpoints.

  • check_fval (bool) – As in CheckedStartpoints.

  • check_grad (bool) – As in CheckedStartpoints.

  • smooth (bool) – Whether a (uniformly chosen) random starting point within the hypercube [i/n_starts, (i+1)/n_starts] should be chosen (True) or the midpoint of the interval (False).

sample(n_starts, lb, ub)[source]

Call function.

Return type:

ndarray

Parameters:
class pypesto.startpoint.NoStartpoints[source]

Bases: StartpointMethod

Dummy class generating nan points. Useful if no startpoints needed.

__call__(n_starts, problem)[source]

Generate a (n_starts, dim) nan matrix.

Return type:

ndarray

Parameters:
class pypesto.startpoint.StartpointMethod[source]

Bases: ABC

Startpoint generation, in particular for multi-start optimization.

Abstract base class, specific sampling method needs to be defined in sub-classes.

abstract __call__(n_starts, problem)[source]

Generate startpoints.

Parameters:
  • n_starts (Number of starts.) –

  • problem (Problem specifying e.g. dimensions, bounds, and guesses.) –

Return type:

ndarray

Returns:

xs (Startpoints, shape (n_starts, n_par).)

class pypesto.startpoint.UniformStartpoints[source]

Bases: FunctionStartpoints

Generate uniformly sampled startpoints.

__init__(use_guesses=True, check_fval=False, check_grad=False)[source]

Initialize.

Parameters:
  • function (The callable sampling startpoints.) –

  • use_guesses (As in CheckedStartpoints.) –

  • check_fval (As in CheckedStartpoints.) –

  • check_grad (As in CheckedStartpoints.) –

pypesto.startpoint.latin_hypercube(n_starts, lb, ub, smooth=True)[source]

Generate latin hypercube points.

Parameters:
  • n_starts (int) – Number of points.

  • lb (ndarray) – Lower bound.

  • ub (ndarray) – Upper bound.

  • smooth (bool) – Whether a (uniformly chosen) random starting point within the hypercube [i/n_starts, (i+1)/n_starts] should be chosen (True) or the midpoint of the interval (False).

Return type:

ndarray

Returns:

xs – Latin hypercube points, shape (n_starts, n_x).

pypesto.startpoint.to_startpoint_method(maybe_startpoint_method)[source]

Create StartpointMethod instance if possible, otherwise raise.

Parameters:

maybe_startpoint_method (Union[StartpointMethod, Callable, bool]) – A StartpointMethod instance, or a Callable as expected by FunctionStartpoints.

Return type:

StartpointMethod

Returns:

startpoint_method – A StartpointMethod instance.

Raises:

TypeError if arguments cannot be converted to a StartpointMethod.

pypesto.startpoint.uniform(n_starts, lb, ub)[source]

Generate uniform points.

Parameters:
  • n_starts (Number of starts.) –

  • lb (Lower bound.) –

  • ub (Upper bound.) –

Return type:

ndarray

Returns:

xs (Uniformly sampled points in [lb, ub], shape (n_starts, n_x).)