src/estimagic/optimization/pounders_auxiliary.py
def update_main_from_residual_model(
    residual_model, multiply_square_terms_with_residuals=True
):
    """Update linear and square terms of the main model via the residual model.

    Args:
        residual_model (dict): Dictionary containing the parameters of the
            residual model, i.e. "intercepts", "linear_terms", and "square terms".
        multiply_square_terms_with_residuals (bool): Indicator whether we
            multiply the main model's "square terms" with residuals, i.e.
            the intercepts of the residual model.

    Returns:
        main_model (dict): Dictionary containing the updated parameters of the
        main model, i.e. "linear_terms" and "square terms".
    """
    intercepts_residual_model = residual_model["intercepts"]
    linear_terms_residual_model = residual_model["linear_terms"]

    linear_terms_main_model = np.dot(
        linear_terms_residual_model, intercepts_residual_model
    )
    square_terms_main_model = np.dot(
        linear_terms_residual_model, linear_terms_residual_model.T
    )

    if multiply_square_terms_with_residuals is True:
        # Multiply 3d array *square_terms_residual_model* with
        # 1d array *intercepts_residual_model* along axis 0 of the former.
        square_terms_residual_model = residual_model["square_terms"]

        dim_array = np.ones((1, square_terms_residual_model.ndim), int).ravel()
        dim_array[0] = -1

        intercepts_reshaped = intercepts_residual_model.reshape(dim_array)

        square_terms_main_model = square_terms_main_model + np.sum(
            intercepts_reshaped * square_terms_residual_model, axis=0
        )

    main_model = {
        "linear_terms": linear_terms_main_model,
        "square_terms": square_terms_main_model,
    }

    return main_model
Update linear and square terms of the main model via the residual model.

    Args:
        residual_model (dict): Dictionary containing the parameters of the
            residual model, i.e. "intercepts", "linear_terms", and "square terms".
        multiply_square_terms_with_residuals (bool): Indicator whether we
            multiply the main model's "square terms" with residuals, i.e.
            the intercepts of the residual model.

    Returns:
        main_model (dict): Dictionary containing the updated parameters of the
        main model, i.e. "linear_terms" and "square terms".
    
Update linear and square terms of the main model via the residual model.
Update linear and square terms of the main model via the residual model .
def update_main_from_residual_model(
    residual_model, multiply_square_terms_with_residuals=True
):
    intercepts_residual_model = residual_model["intercepts"]
    linear_terms_residual_model = residual_model["linear_terms"]
    linear_terms_main_model = np.dot(
        linear_terms_residual_model, intercepts_residual_model
    )
    square_terms_main_model = np.dot(
        linear_terms_residual_model, linear_terms_residual_model.T
    )
    if multiply_square_terms_with_residuals is True:
        square_terms_residual_model = residual_model["square_terms"]
        dim_array = np.ones((1, square_terms_residual_model.ndim), int).ravel()
        dim_array[0] = -1
        intercepts_reshaped = intercepts_residual_model.reshape(dim_array)
        square_terms_main_model = square_terms_main_model + np.sum(
            intercepts_reshaped * square_terms_residual_model, axis=0
        )
    main_model = {
        "linear_terms": linear_terms_main_model,
        "square_terms": square_terms_main_model,
    }
    return main_model
def update_main_from_residual_model ( residual_model , multiply_square_terms_with_residuals = True ) : intercepts_residual_model = residual_model [ "intercepts" ] linear_terms_residual_model = residual_model [ "linear_terms" ] linear_terms_main_model = np . dot ( linear_terms_residual_model , intercepts_residual_model ) square_terms_main_model = np . dot ( linear_terms_residual_model , linear_terms_residual_model . T ) if multiply_square_terms_with_residuals is True : square_terms_residual_model = residual_model [ "square_terms" ] dim_array = np . ones ( ( 1 , square_terms_residual_model . ndim ) , int ) . ravel ( ) dim_array [ 0 ] = - 1 intercepts_reshaped = intercepts_residual_model . reshape ( dim_array ) square_terms_main_model = square_terms_main_model + np . sum ( intercepts_reshaped * square_terms_residual_model , axis = 0 ) main_model = { "linear_terms" : linear_terms_main_model , "square_terms" : square_terms_main_model , } return main_model
Update linear and square terms of the main model via the residual model.
Update linear and square terms of the main model via the residual model .
"""Update linear and square terms of the main model via the residual model.

    Args:
        residual_model (dict): Dictionary containing the parameters of the
            residual model, i.e. "intercepts", "linear_terms", and "square terms".
        multiply_square_terms_with_residuals (bool): Indicator whether we
            multiply the main model's "square terms" with residuals, i.e.
            the intercepts of the residual model.

    Returns:
        main_model (dict): Dictionary containing the updated parameters of the
        main model, i.e. "linear_terms" and "square terms".
    """ # Multiply 3d array *square_terms_residual_model* with # 1d array *intercepts_residual_model* along axis 0 of the former.
main_model (dict): Dictionary containing the updated parameters of the
main model, i.e. "linear_terms" and "square terms".
main_model ( dict ) : Dictionary containing the updated parameters of the main model i . e . " linear_terms " and " square terms " .
residual_model
Dictionary containing the parameters of the
residual model, i.e. "intercepts", "linear_terms", and "square terms".
Dictionary containing the parameters of the residual model i . e . " intercepts " " linear_terms " and " square terms " .
multiply_square_terms_with_residuals
Indicator whether we
multiply the main model's "square terms" with residuals, i.e.
the intercepts of the residual model.
Indicator whether we multiply the main model ' s " square terms " with residuals i . e . the intercepts of the residual model .