pypesto.problem

Problem

A problem contains the objective as well as all information like prior describing the problem to be solved.

class pypesto.problem.Problem(objective: ObjectiveBase, lb: ndarray | List[float], ub: ndarray | List[float], dim_full: int | None = None, x_fixed_indices: Iterable[SupportsInt] | SupportsInt | None = None, x_fixed_vals: Iterable[SupportsFloat] | SupportsFloat | None = None, x_guesses: Iterable[float] | None = None, x_names: Iterable[str] | None = None, x_scales: Iterable[str] | None = None, x_priors_defs: NegLogParameterPriors | None = None, lb_init: ndarray | List[float] | None = None, ub_init: ndarray | List[float] | None = None, copy_objective: bool = True)[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 – The objective function for minimization. Note that a shallow copy is created.

  • lb – The lower and upper bounds for optimization. For unbounded directions set to +-inf.

  • ub – The lower and upper bounds for optimization. For unbounded directions set to +-inf.

  • lb_init – The lower and upper bounds for initialization, typically for defining search start points. If not set, set to lb, ub.

  • ub_init – The lower and upper bounds for initialization, typically for defining search start points. If not set, set to lb, ub.

  • dim_full – The full dimension of the problem, including fixed parameters.

  • x_fixed_indices – Vector containing the indices (zero-based) of parameter components that are not to be optimized.

  • x_fixed_vals – Vector of the same length as x_fixed_indices, containing the values of the fixed parameters.

  • x_guesses – 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 – 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 – 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 – Definitions of priors for parameters. Types of priors, and their required and optional parameters, are described in the Prior class.

  • copy_objective – Whethter to generate a deep copy of the objective function before potential modification the problem class performs on it.

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: ObjectiveBase, lb: ndarray | List[float], ub: ndarray | List[float], dim_full: int | None = None, x_fixed_indices: Iterable[SupportsInt] | SupportsInt | None = None, x_fixed_vals: Iterable[SupportsFloat] | SupportsFloat | None = None, x_guesses: Iterable[float] | None = None, x_names: Iterable[str] | None = None, x_scales: Iterable[str] | None = None, x_priors_defs: NegLogParameterPriors | None = None, lb_init: ndarray | List[float] | None = None, ub_init: ndarray | List[float] | None = None, copy_objective: bool = True)[source]
property dim: int

Return dimension only considering non fixed parameters.

fix_parameters(parameter_indices: Iterable[SupportsInt] | SupportsInt, parameter_vals: Iterable[SupportsFloat] | SupportsFloat) None[source]

Fix specified parameters to specified values.

full_index_to_free_index(full_index: int)[source]

Calculate index in reduced vector from index in full vector.

Parameters:

full_index (The index in the full vector.) –

Returns:

free_index

Return type:

The index in the free vector.

get_full_matrix(x: ndarray | None) ndarray | None[source]

Map matrix from dim to dim_full. Usually used for hessian.

Parameters:

x (array_like, shape=(dim, dim)) – The matrix in dimension dim.

get_full_vector(x: ndarray | None, x_fixed_vals: Iterable[float] | None = None) ndarray | None[source]

Map vector from dim to dim_full. Usually used for x, grad.

Parameters:
  • x (array_like, shape=(dim,)) – The vector in dimension dim.

  • x_fixed_vals (array_like, ndim=1, optional) – The values to be used for the fixed indices. If None, then nans are inserted. Usually, None will be used for grad and problem.x_fixed_vals for x.

get_reduced_matrix(x_full: ndarray | None) ndarray | None[source]

Map matrix from dim_full to dim, i.e. delete fixed indices.

Parameters:

x_full (array_like, ndim=2) – The matrix in dimension dim_full.

get_reduced_vector(x_full: ndarray | None, x_indices: List[int] | None = None) ndarray | None[source]

Keep only those elements, which indices are specified in x_indices.

If x_indices is not provided, delete fixed indices.

Parameters:
  • x_full (array_like, ndim=1) – The vector in dimension dim_full.

  • x_indices – indices of x_full that should remain

property lb: ndarray

Return lower bounds of free parameters.

property lb_init: ndarray

Return initial lower bounds of free parameters.

normalize() None[source]

Process vectors.

Reduce all vectors to dimension dim and have the objective accept vectors of dimension dim.

print_parameter_summary() None[source]

Print a summary of parameters.

Include what parameters are being optimized and parameter boundaries.

set_x_guesses(x_guesses: Iterable[float])[source]

Set the x_guesses of a problem.

Parameters:

x_guesses

property ub: ndarray

Return upper bounds of free parameters.

property ub_init: ndarray

Return initial upper bounds of free parameters.

unfix_parameters(parameter_indices: Iterable[SupportsInt] | SupportsInt) None[source]

Free specified parameters.

property x_free_indices: List[int]

Return non fixed parameters.

property x_guesses: ndarray

Return guesses of the free parameter values.