Processing constraints

Process the user provided pc for use during the optimization.

The main purpose of this module is to convert the user provided pc into inputs for fast reparametrization functions. In the process, the pc are checked and consolidated. Consolidation means that redundant pc are dropped and other pc are collected in meaningful bundles.

To improve readability, the actual code for checking and consolidation are in separate modules.

The calls to the check functions are not in one place but scattered over the module. This is because we want to do each check as soon as it becomes possible, which allows to write error messages that are closely tied to the pc as written by the users and not some transformed version thereof. However, some checks can only be done after the consolidation.

The challenge in making this module readable is that after each function is applied the list of pc and the params dataframe will be slightly different, but it is not possible to reflect all of the changes in meaningful names because thy would get way too long. We chose the following conventions:

As soon as a list of pc or a params DataFrame is different from what the user provided they are called pc (for pc) and pp (for processed params) respectively. If all pc of a certain type, say linear, are collected in a this collection is called pc_linear.

If only few columns of processed params are used in a function, it is better to pass them as Series, to make the flow of information more explicit.

estimagic.optimization.process_constraints.process_constraints(constraints, params)[source]

Process, consolidate and check constraints.

Parameters
Returns

A processed version of those constraints

that entail actual transformations and not just fixing parameters.

pp (pd.DataFrame): Processed params. A copy of params with additional columns:
  • _internal_lower: Lower bounds for the internal parameter vector. Those are derived from the original lower bounds and additional bounds implied by other constraints.

  • _internal_upper: As _internal_lower but for upper bounds.

  • _internal_free: Boolean column that is true for those parameters over which the optimizer will actually optimize.

  • _pre_replacements: The j_th element indicates the position of the internal parameter that has to be copied into the j_th position of the external parameter vector when reparametrizing from_internal, before any transformations are applied. Negative if no element has to be copied.

  • _post_replacements: As pre_replacements, but applied after the transformations are done.

  • _internal_fixed_value: Contains transformed versions of the fixed values that will become equal to the external fixed values after the kernel transformations are applied.

  • _is_fixed_to_value: True for parameters that are fixed to a value

  • _is_fixed_to_other: True for parameters that are fixed to another parameter

Return type

pc (list)

estimagic.optimization.process_constraints.process_bounds(params)[source]

Fill missing bounds with -np.inf and np.inf.