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(use_guesses: bool = True, check_fval: bool = False, check_grad: bool = False)[source]

Bases: pypesto.startpoint.base.StartpointMethod, abc.ABC

Startpoints checked for function value and/or gradient finiteness.

__call__(n_starts: int, problem: pypesto.problem.Problem)numpy.ndarray[source]

Generate checked startpoints.

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

Initialize.

Parameters
  • use_guesses – Whether to use guesses provided in the problem.

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

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

check_and_resample(xs: numpy.ndarray, lb: numpy.ndarray, ub: numpy.ndarray, objective: pypesto.objective.base.ObjectiveBase)numpy.ndarray[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.) –

Returns

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

Return type

xs

abstract sample(n_starts: int, lb: numpy.ndarray, ub: numpy.ndarray)numpy.ndarray[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.) –

Returns

xs

Return type

Startpoints, shape (n_starts, n_par)

class pypesto.startpoint.FunctionStartpoints(function: Callable, use_guesses: bool = True, check_fval: bool = False, check_grad: bool = False)[source]

Bases: pypesto.startpoint.base.CheckedStartpoints

Define startpoints via callable.

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

__init__(function: Callable, use_guesses: bool = True, check_fval: bool = False, check_grad: bool = 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: int, lb: numpy.ndarray, ub: numpy.ndarray)numpy.ndarray[source]

Call function.

class pypesto.startpoint.LatinHypercubeStartpoints(use_guesses: bool = True, check_fval: bool = False, check_grad: bool = False, smooth: bool = True)[source]

Bases: pypesto.startpoint.base.CheckedStartpoints

Generate latin hypercube-sampled startpoints.

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

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

Initialize.

Parameters
  • use_guesses – As in CheckedStartpoints.

  • check_fval – As in CheckedStartpoints.

  • check_grad – As in CheckedStartpoints.

  • smooth – 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: int, lb: numpy.ndarray, ub: numpy.ndarray)numpy.ndarray[source]

Call function.

class pypesto.startpoint.NoStartpoints[source]

Bases: pypesto.startpoint.base.StartpointMethod

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

__call__(n_starts: int, problem: pypesto.problem.Problem)numpy.ndarray[source]

Generate a (n_starts, dim) nan matrix.

class pypesto.startpoint.StartpointMethod[source]

Bases: abc.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: int, problem: pypesto.problem.Problem)numpy.ndarray[source]

Generate startpoints.

Parameters
  • n_starts (Number of starts.) –

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

Returns

xs

Return type

Startpoints, shape (n_starts, n_par)

class pypesto.startpoint.UniformStartpoints(use_guesses: bool = True, check_fval: bool = False, check_grad: bool = False)[source]

Bases: pypesto.startpoint.base.FunctionStartpoints

Generate uniformly sampled startpoints.

__init__(use_guesses: bool = True, check_fval: bool = False, check_grad: bool = 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: int, lb: numpy.ndarray, ub: numpy.ndarray, smooth: bool = True)numpy.ndarray[source]

Generate latin hypercube points.

Parameters
  • n_starts – Number of points.

  • lb – Lower bound.

  • ub – Upper bound.

  • smooth – 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).

Returns

Latin hypercube points, shape (n_starts, n_x).

Return type

xs

pypesto.startpoint.to_startpoint_method(maybe_startpoint_method: Union[pypesto.startpoint.base.StartpointMethod, Callable, bool])pypesto.startpoint.base.StartpointMethod[source]

Create StartpointMethod instance if possible, otherwise raise.

Parameters

maybe_startpoint_method – A StartpointMethod instance, or a Callable as expected by FunctionStartpoints.

Returns

A StartpointMethod instance.

Return type

startpoint_method

Raises

TypeError if arguments cannot be converted to a StartpointMethod.

pypesto.startpoint.uniform(n_starts: int, lb: numpy.ndarray, ub: numpy.ndarray)numpy.ndarray[source]

Generate uniform points.

Parameters
  • n_starts (Number of starts.) –

  • lb (Lower bound.) –

  • ub (Upper bound.) –

Returns

xs

Return type

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