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(use_guesses: bool = True, check_fval: bool = False, check_grad: bool = False)[source]
Bases:
StartpointMethod
,ABC
Startpoints checked for function value and/or gradient finiteness.
- __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: ndarray, lb: ndarray, ub: ndarray, objective: ObjectiveBase) 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: ndarray, ub: ndarray) 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:
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.) –
- class pypesto.startpoint.LatinHypercubeStartpoints(use_guesses: bool = True, check_fval: bool = False, check_grad: bool = False, smooth: bool = True)[source]
Bases:
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).
- class pypesto.startpoint.NoStartpoints[source]
Bases:
StartpointMethod
Dummy class generating nan points. Useful if no startpoints needed.
- 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.
- class pypesto.startpoint.UniformStartpoints(use_guesses: bool = True, check_fval: bool = False, check_grad: bool = False)[source]
Bases:
FunctionStartpoints
Generate uniformly sampled startpoints.
- pypesto.startpoint.latin_hypercube(n_starts: int, lb: ndarray, ub: ndarray, smooth: bool = True) 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: StartpointMethod | Callable | bool) 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. –