src/estimagic/parameters/process_constraints.py
def process_constraints(constraints, params, scaling_factor=None, scaling_offset=None):
    """Process, consolidate and check constraints.

    Args:
        constraints (list): List of dictionaries where each dictionary is a constraint.
        params (pd.DataFrame): see :ref:`params`.
        scaling_factor (np.ndarray or None): If None, no scaling factor is used.
        scaling_offset (np.ndarray or None): If None, no scaling offset is used.

    Returns:

        pc (list): 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

    """
    params = add_default_bounds_to_params(params)
    with warnings.catch_warnings():
        warnings.filterwarnings(
            "ignore", message="indexing past lexsort depth may impact performance."
        )
        params = params.copy()
        check_types(constraints)
        # selectors have to be processed before anything else happens to the params
        pc = _process_selectors(constraints, params)

        pc = _replace_pairwise_equality_by_equality(pc)
        pc = _process_linear_weights(pc, params)
        check_constraints_are_satisfied(pc, params)
        pc = _replace_increasing_and_decreasing_by_linear(pc)
        pc = _process_linear_weights(pc, params)
        pc, pp = consolidate_constraints(pc, params)
        check_for_incompatible_overlaps(pp, pc)
        check_fixes_and_bounds(pp, pc)

        int_lower, int_upper = _create_unscaled_internal_bounds(
            pp.lower_bound, pp.upper_bound, pc
        )
        pp["_internal_lower"] = int_lower
        pp["_internal_upper"] = int_upper
        pp["_internal_free"] = _create_internal_free(
            pp._is_fixed_to_value, pp._is_fixed_to_other, pc
        )

        for col in ["_internal_lower", "_internal_upper"]:
            pp[col] = _scale_bound_to_internal(
                pp[col],
                pp._internal_free,
                scaling_factor=scaling_factor,
                scaling_offset=scaling_offset,
            )
        pp["_pre_replacements"] = _create_pre_replacements(pp._internal_free)
        pp["_internal_fixed_value"] = _create_internal_fixed_value(pp._fixed_value, pc)

        return pc, pp
Process, consolidate and check constraints.

    Args:
        constraints (list): List of dictionaries where each dictionary is a constraint.
        params (pd.DataFrame): see :ref:`params`.
        scaling_factor (np.ndarray or None): If None, no scaling factor is used.
        scaling_offset (np.ndarray or None): If None, no scaling offset is used.

    Returns:

        pc (list): 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

    
Process, consolidate and check constraints.
Process consolidate and check constraints .
def process_constraints(constraints, params, scaling_factor=None, scaling_offset=None):
    params = add_default_bounds_to_params(params)
    with warnings.catch_warnings():
        warnings.filterwarnings(
            "ignore", message="indexing past lexsort depth may impact performance."
        )
        params = params.copy()
        check_types(constraints)
        pc = _process_selectors(constraints, params)
        pc = _replace_pairwise_equality_by_equality(pc)
        pc = _process_linear_weights(pc, params)
        check_constraints_are_satisfied(pc, params)
        pc = _replace_increasing_and_decreasing_by_linear(pc)
        pc = _process_linear_weights(pc, params)
        pc, pp = consolidate_constraints(pc, params)
        check_for_incompatible_overlaps(pp, pc)
        check_fixes_and_bounds(pp, pc)
        int_lower, int_upper = _create_unscaled_internal_bounds(
            pp.lower_bound, pp.upper_bound, pc
        )
        pp["_internal_lower"] = int_lower
        pp["_internal_upper"] = int_upper
        pp["_internal_free"] = _create_internal_free(
            pp._is_fixed_to_value, pp._is_fixed_to_other, pc
        )
        for col in ["_internal_lower", "_internal_upper"]:
            pp[col] = _scale_bound_to_internal(
                pp[col],
                pp._internal_free,
                scaling_factor=scaling_factor,
                scaling_offset=scaling_offset,
            )
        pp["_pre_replacements"] = _create_pre_replacements(pp._internal_free)
        pp["_internal_fixed_value"] = _create_internal_fixed_value(pp._fixed_value, pc)
        return pc, pp
def process_constraints ( constraints , params , scaling_factor = None , scaling_offset = None ) : params = add_default_bounds_to_params ( params ) with warnings . catch_warnings ( ) : warnings . filterwarnings ( "ignore" , message = "indexing past lexsort depth may impact performance." ) params = params . copy ( ) check_types ( constraints ) pc = _process_selectors ( constraints , params ) pc = _replace_pairwise_equality_by_equality ( pc ) pc = _process_linear_weights ( pc , params ) check_constraints_are_satisfied ( pc , params ) pc = _replace_increasing_and_decreasing_by_linear ( pc ) pc = _process_linear_weights ( pc , params ) pc , pp = consolidate_constraints ( pc , params ) check_for_incompatible_overlaps ( pp , pc ) check_fixes_and_bounds ( pp , pc ) int_lower , int_upper = _create_unscaled_internal_bounds ( pp . lower_bound , pp . upper_bound , pc ) pp [ "_internal_lower" ] = int_lower pp [ "_internal_upper" ] = int_upper pp [ "_internal_free" ] = _create_internal_free ( pp . _is_fixed_to_value , pp . _is_fixed_to_other , pc ) for col in [ "_internal_lower" , "_internal_upper" ] : pp [ col ] = _scale_bound_to_internal ( pp [ col ] , pp . _internal_free , scaling_factor = scaling_factor , scaling_offset = scaling_offset , ) pp [ "_pre_replacements" ] = _create_pre_replacements ( pp . _internal_free ) pp [ "_internal_fixed_value" ] = _create_internal_fixed_value ( pp . _fixed_value , pc ) return pc , pp
Process, consolidate and check constraints.
Process consolidate and check constraints .
"""Process, consolidate and check constraints.

    Args:
        constraints (list): List of dictionaries where each dictionary is a constraint.
        params (pd.DataFrame): see :ref:`params`.
        scaling_factor (np.ndarray or None): If None, no scaling factor is used.
        scaling_offset (np.ndarray or None): If None, no scaling offset is used.

    Returns:

        pc (list): 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

    """ # selectors have to be processed before anything else happens to the params
pc (list): 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
pc ( list ) : 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
constraints
List of dictionaries where each dictionary is a constraint.
List of dictionaries where each dictionary is a constraint .
params
None
scaling_factor
If None, no scaling factor is used.
If None no scaling factor is used .
scaling_offset
If None, no scaling offset is used.
If None no scaling offset is used .