pypesto.problem
Problem
A problem contains the objective as well as all information like prior describing the problem to be solved.
- class pypesto.problem.HierarchicalProblem[source]
Bases:
Problem
The Hierarchical Problem.
A hierarchical problem is a problem with a nested structure: One or multiple inner problems are nested inside the outer problem. The inner problems are optimized for each evaluation of the outer problem. The objective’s calculator is used to collect the inner problems’ objective values.
- Parameters:
hierarchical – A flag indicating the problem is hierarchical.
inner_x_names (
Optional
[Iterable
[str
]]) – Names of the inner optimization parameters. Only relevant if hierarchical is True. Contains the names of easily interpretable inner parameters only, e.g. noise parameters, scaling factors, offsets.inner_lb (
Union
[ndarray
,list
[float
],None
]) – The lower and upper bounds for the inner optimization parameters. Only relevant if hierarchical is True. Contains the bounds of easily interpretable inner parameters only, e.g. noise parameters, scaling factors, offsets.inner_ub (
Union
[ndarray
,list
[float
],None
]) – The lower and upper bounds for the inner optimization parameters. Only relevant if hierarchical is True. Contains the bounds of easily interpretable inner parameters only, e.g. noise parameters, scaling factors, offsets.semiquant_observable_ids – The ids of semiquantitative observables. Only relevant if hierarchical is True. If not None, the optimization result’s spline_knots will be a list of lists of spline knots for each semiquantitative observable in the order of these ids.
- class pypesto.problem.Problem[source]
Bases:
object
The problem formulation.
A problem specifies the objective function, boundaries and constraints, parameter guesses as well as the parameters which are to be optimized.
- Parameters:
objective (
ObjectiveBase
) – The objective function for minimization. Note that a shallow copy is created.lb (
Union
[ndarray
,list
[float
]]) – The lower and upper bounds for optimization. For unbounded directions set to +-inf.ub (
Union
[ndarray
,list
[float
]]) – The lower and upper bounds for optimization. For unbounded directions set to +-inf.lb_init (
Union
[ndarray
,list
[float
],None
]) – The lower and upper bounds for initialization, typically for defining search start points. If not set, set to lb, ub.ub_init (
Union
[ndarray
,list
[float
],None
]) – The lower and upper bounds for initialization, typically for defining search start points. If not set, set to lb, ub.dim_full (
Optional
[int
]) – The full dimension of the problem, including fixed parameters.x_fixed_indices (
Union
[Iterable
[SupportsInt
],SupportsInt
,None
]) – Vector containing the indices (zero-based) of parameter components that are not to be optimized.x_fixed_vals (
Union
[Iterable
[SupportsFloat
],SupportsFloat
,None
]) – Vector of the same length as x_fixed_indices, containing the values of the fixed parameters.x_guesses (
Optional
[Iterable
[float
]]) – Guesses for the parameter values, shape (g, dim), where g denotes the number of guesses. These are used as start points in the optimization.x_names (
Optional
[Iterable
[str
]]) – Parameter names that can be optionally used e.g. in visualizations. If objective.get_x_names() is not None, those values are used, else the values specified here are used if not None, otherwise the variable names are set to [‘x0’, … ‘x{dim_full}’]. The list must always be of length dim_full.x_scales (
Optional
[Iterable
[str
]]) – Parameter scales can be optionally given and are used e.g. in visualisation and prior generation. Currently the scales ‘lin’, ‘log`and ‘log10’ are supported.x_priors_defs (
Optional
[NegLogParameterPriors
]) – Definitions of priors for parameters. Types of priors, and their required and optional parameters, are described in the Prior class.copy_objective (
bool
) – Whethter to generate a deep copy of the objective function before potential modification the problem class performs on it.startpoint_method (
Union
[StartpointMethod
,Callable
,bool
]) – Method for how to choose start points.False
means the optimizer does not require start points, e.g. for thePyswarmOptimizer
.
Notes
On the fixing of parameter values:
The number of parameters dim_full the objective takes as input must be known, so it must be either lb a vector of that size, or dim_full specified as a parameter.
All vectors are mapped to the reduced space of dimension dim in __init__, regardless of whether they were in dimension dim or dim_full before. If the full representation is needed, the methods get_full_vector() and get_full_matrix() can be used.
- __init__(objective, lb, ub, dim_full=None, x_fixed_indices=None, x_fixed_vals=None, x_guesses=None, x_names=None, x_scales=None, x_priors_defs=None, lb_init=None, ub_init=None, copy_objective=True, startpoint_method=None)[source]
- Parameters:
objective (ObjectiveBase) –
dim_full (int | None) –
x_fixed_indices (Iterable[SupportsInt] | SupportsInt | None) –
x_fixed_vals (Iterable[SupportsFloat] | SupportsFloat | None) –
x_priors_defs (NegLogParameterPriors | None) –
copy_objective (bool) –
startpoint_method (StartpointMethod | Callable | bool) –
- fix_parameters(parameter_indices, parameter_vals)[source]
Fix specified parameters to specified values.
- Return type:
- Parameters:
parameter_indices (Iterable[SupportsInt] | SupportsInt) –
parameter_vals (Iterable[SupportsFloat] | SupportsFloat) –
- full_index_to_free_index(full_index)[source]
Calculate index in reduced vector from index in full vector.
- Parameters:
full_index (The index in the full vector.) –
- Returns:
free_index (The index in the free vector.)
- get_full_vector(x, x_fixed_vals=None)[source]
Map vector from dim to dim_full. Usually used for x, grad.
- get_reduced_vector(x_full, x_indices=None)[source]
Keep only those elements, which indices are specified in x_indices.
If x_indices is not provided, delete fixed indices.
- normalize()[source]
Process vectors.
Reduce all vectors to dimension dim and have the objective accept vectors of dimension dim.
- Return type:
- print_parameter_summary()[source]
Print a summary of parameters.
Include what parameters are being optimized and parameter boundaries.
- Return type:
- unfix_parameters(parameter_indices)[source]
Free specified parameters.
- Return type:
- Parameters:
parameter_indices (Iterable[SupportsInt] | SupportsInt) –