src/estimagic/optimization/pounders_auxiliary.py
def add_points_to_make_main_model_fully_linear(
    history,
    main_model,
    model_improving_points,
    model_indices,
    x_accepted,
    n_modelpoints,
    delta,
    criterion,
    lower_bounds,
    upper_bounds,
    batch_evaluator,
    n_cores,
):
    """Add points until main model is fully linear.

    Args:
        history (class): Class storing history of xs, residuals, and critvals.
        main_model (dict): Dictionary containing the parameters of the main model,
            i.e. "linear_terms" and "square terms".
        model_improving_points (np.ndarray): Array of shape (n, n) including
            points to improve the main model.
        model_indices (np.ndarray): Indices of the candidates of x that are
            currently in the main model. Shape (2 * n + 1,).
        x_accepted (np.ndarray): Accepted solution vector of the subproblem.
            Shape (n,).
        n_modelpoints (int): Current number of model points.
        delta (float): Delta, current trust-region radius.
        criterion (callable): Criterion function.
        lower_bounds (np.ndarray): Lower bounds.
            Must have same length as the initial guess of the
            parameter vector. Equal to -1 if not provided by the user.
        upper_bounds (np.ndarray): Upper bounds.
            Must have same length as the initial guess of the
            parameter vector. Equal to 1 if not provided by the user.
        batch_evaluator (str or callable): Name of a pre-implemented batch evaluator
            (currently 'joblib' and 'pathos_mp') or Callable with the same interface
            as the estimagic batch_evaluators.
        n_cores (int): Number of processes used to parallelize the function
            evaluations.

    Returns:
        Tuple:
        - history (class): Class storing history of xs, residuals, and critvals.
        - model_indices (np.ndarray): Indices of the candidates of x that are
            currently in the main model. Shape (2 * n + 1,).
    """
    n = x_accepted.shape[0]

    current_history = history.get_n_fun()
    linear_terms = main_model["linear_terms"]

    x_candidate = np.zeros(n)
    x_candidates_list = []
    criterion_candidates_list = []

    model_improving_points, _ = qr_multiply(model_improving_points, np.eye(3))

    for i in range(n_modelpoints, n):
        change_direction = np.dot(model_improving_points[:, i], linear_terms)

        if change_direction > 0:
            model_improving_points[:, i] *= -1

        x_candidate = delta * model_improving_points[:, i] + x_accepted

        # Project into feasible region
        if lower_bounds is not None and upper_bounds is not None:
            x_candidate = np.median(
                np.stack([lower_bounds, x_candidate, upper_bounds]), axis=0
            )
        x_candidates_list.append(x_candidate)
        model_indices[i] = current_history + i - n_modelpoints

    criterion_candidates_list = batch_evaluator(
        criterion, arguments=x_candidates_list, n_cores=n_cores
    )

    history.add_entries(x_candidates_list, criterion_candidates_list)

    return history, model_indices
Add points until main model is fully linear.

    Args:
        history (class): Class storing history of xs, residuals, and critvals.
        main_model (dict): Dictionary containing the parameters of the main model,
            i.e. "linear_terms" and "square terms".
        model_improving_points (np.ndarray): Array of shape (n, n) including
            points to improve the main model.
        model_indices (np.ndarray): Indices of the candidates of x that are
            currently in the main model. Shape (2 * n + 1,).
        x_accepted (np.ndarray): Accepted solution vector of the subproblem.
            Shape (n,).
        n_modelpoints (int): Current number of model points.
        delta (float): Delta, current trust-region radius.
        criterion (callable): Criterion function.
        lower_bounds (np.ndarray): Lower bounds.
            Must have same length as the initial guess of the
            parameter vector. Equal to -1 if not provided by the user.
        upper_bounds (np.ndarray): Upper bounds.
            Must have same length as the initial guess of the
            parameter vector. Equal to 1 if not provided by the user.
        batch_evaluator (str or callable): Name of a pre-implemented batch evaluator
            (currently 'joblib' and 'pathos_mp') or Callable with the same interface
            as the estimagic batch_evaluators.
        n_cores (int): Number of processes used to parallelize the function
            evaluations.

    Returns:
        Tuple:
        - history (class): Class storing history of xs, residuals, and critvals.
        - model_indices (np.ndarray): Indices of the candidates of x that are
            currently in the main model. Shape (2 * n + 1,).
    
Add points until main model is fully linear.
Add points until main model is fully linear .
def add_points_to_make_main_model_fully_linear(
    history,
    main_model,
    model_improving_points,
    model_indices,
    x_accepted,
    n_modelpoints,
    delta,
    criterion,
    lower_bounds,
    upper_bounds,
    batch_evaluator,
    n_cores,
):
    n = x_accepted.shape[0]
    current_history = history.get_n_fun()
    linear_terms = main_model["linear_terms"]
    x_candidate = np.zeros(n)
    x_candidates_list = []
    criterion_candidates_list = []
    model_improving_points, _ = qr_multiply(model_improving_points, np.eye(3))
    for i in range(n_modelpoints, n):
        change_direction = np.dot(model_improving_points[:, i], linear_terms)
        if change_direction > 0:
            model_improving_points[:, i] *= -1
        x_candidate = delta * model_improving_points[:, i] + x_accepted
        if lower_bounds is not None and upper_bounds is not None:
            x_candidate = np.median(
                np.stack([lower_bounds, x_candidate, upper_bounds]), axis=0
            )
        x_candidates_list.append(x_candidate)
        model_indices[i] = current_history + i - n_modelpoints
    criterion_candidates_list = batch_evaluator(
        criterion, arguments=x_candidates_list, n_cores=n_cores
    )
    history.add_entries(x_candidates_list, criterion_candidates_list)
    return history, model_indices
def add_points_to_make_main_model_fully_linear ( history , main_model , model_improving_points , model_indices , x_accepted , n_modelpoints , delta , criterion , lower_bounds , upper_bounds , batch_evaluator , n_cores , ) : n = x_accepted . shape [ 0 ] current_history = history . get_n_fun ( ) linear_terms = main_model [ "linear_terms" ] x_candidate = np . zeros ( n ) x_candidates_list = [ ] criterion_candidates_list = [ ] model_improving_points , _ = qr_multiply ( model_improving_points , np . eye ( 3 ) ) for i in range ( n_modelpoints , n ) : change_direction = np . dot ( model_improving_points [ : , i ] , linear_terms ) if change_direction > 0 : model_improving_points [ : , i ] *= - 1 x_candidate = delta * model_improving_points [ : , i ] + x_accepted if lower_bounds is not None and upper_bounds is not None : x_candidate = np . median ( np . stack ( [ lower_bounds , x_candidate , upper_bounds ] ) , axis = 0 ) x_candidates_list . append ( x_candidate ) model_indices [ i ] = current_history + i - n_modelpoints criterion_candidates_list = batch_evaluator ( criterion , arguments = x_candidates_list , n_cores = n_cores ) history . add_entries ( x_candidates_list , criterion_candidates_list ) return history , model_indices
Add points until main model is fully linear.
Add points until main model is fully linear .
"""Add points until main model is fully linear.

    Args:
        history (class): Class storing history of xs, residuals, and critvals.
        main_model (dict): Dictionary containing the parameters of the main model,
            i.e. "linear_terms" and "square terms".
        model_improving_points (np.ndarray): Array of shape (n, n) including
            points to improve the main model.
        model_indices (np.ndarray): Indices of the candidates of x that are
            currently in the main model. Shape (2 * n + 1,).
        x_accepted (np.ndarray): Accepted solution vector of the subproblem.
            Shape (n,).
        n_modelpoints (int): Current number of model points.
        delta (float): Delta, current trust-region radius.
        criterion (callable): Criterion function.
        lower_bounds (np.ndarray): Lower bounds.
            Must have same length as the initial guess of the
            parameter vector. Equal to -1 if not provided by the user.
        upper_bounds (np.ndarray): Upper bounds.
            Must have same length as the initial guess of the
            parameter vector. Equal to 1 if not provided by the user.
        batch_evaluator (str or callable): Name of a pre-implemented batch evaluator
            (currently 'joblib' and 'pathos_mp') or Callable with the same interface
            as the estimagic batch_evaluators.
        n_cores (int): Number of processes used to parallelize the function
            evaluations.

    Returns:
        Tuple:
        - history (class): Class storing history of xs, residuals, and critvals.
        - model_indices (np.ndarray): Indices of the candidates of x that are
            currently in the main model. Shape (2 * n + 1,).
    """ # Project into feasible region
history (class): Class storing history of xs, residuals, and critvals.
model_indices (np.ndarray): Indices of the candidates of x that are
currently in the main model.
history ( class ) : Class storing history of xs residuals and critvals . model_indices ( np . ndarray ) : Indices of the candidates of x that are currently in the main model .
Tuple
history
Class storing history of xs, residuals, and critvals.
Class storing history of xs residuals and critvals .
main_model
Dictionary containing the parameters of the main model,
i.e. "linear_terms" and "square terms".
Dictionary containing the parameters of the main model i . e . " linear_terms " and " square terms " .
model_improving_points
Array of shape (n, n) including
points to improve the main model.
Array of shape ( n n ) including points to improve the main model .
model_indices
Indices of the candidates of x that are
currently in the main model.
Indices of the candidates of x that are currently in the main model .
x_accepted
Accepted solution vector of the subproblem.
Accepted solution vector of the subproblem .
n_modelpoints
Current number of model points.
Current number of model points .
delta
Delta, current trust-region radius.
Delta current trust - region radius .
criterion
None
lower_bounds
Lower bounds.
Must have same length as the initial guess of the
parameter vector. Equal to -1 if not provided by the user.
Lower bounds . Must have same length as the initial guess of the parameter vector . Equal to - 1 if not provided by the user .
upper_bounds
Upper bounds.
Must have same length as the initial guess of the
parameter vector. Equal to 1 if not provided by the user.
Upper bounds . Must have same length as the initial guess of the parameter vector . Equal to 1 if not provided by the user .
batch_evaluator
Name of a pre-implemented batch evaluator
(currently 'joblib' and 'pathos_mp') or Callable with the same interface
as the estimagic batch_evaluators.
Name of a pre - implemented batch evaluator ( currently ' joblib ' and ' pathos_mp ' ) or Callable with the same interface as the estimagic batch_evaluators .
n_cores
Number of processes used to parallelize the function
evaluations.
Number of processes used to parallelize the function evaluations .