BudgetOptimizer.allocate_budget#

BudgetOptimizer.allocate_budget(total_budget, budget_bounds=None, x0=None, minimize_kwargs=None, return_if_fail=False, callback=False)[source]#

Allocate the budget based on total_budget, optional budget_bounds, and custom constraints.

The default sum constraint ensures that the sum of the optimized budget equals total_budget. If budget_bounds are not provided, each channel will be constrained to lie in [0, total_budget].

Parameters:
total_budgetfloat

The total budget to allocate.

budget_boundsDataArray or dict, optional
  • If None, default bounds of [0, total_budget] per channel are assumed.

  • If a dict, must map each channel to (low, high) budget pairs (only valid if there’s one dimension).

  • If an xarray.DataArray, must have dims (*budget_dims, “bound”), specifying [low, high] per channel cell.

x0np.ndarray, optional

Initial guess. Array of real elements of size (n,), where n is the number of driver budgets to optimize. If None, the total budget is spread uniformly across all drivers to be optimized.

minimize_kwargsdict, optional

Extra kwargs for scipy.optimize.minimize. Defaults to method=”SLSQP”, ftol=1e-9, maxiter=1_000.

return_if_failbool, optional

Return output even if optimization fails. Default is False.

callbackbool, optional

Whether to return callback information tracking optimization progress. When True, returns a third element containing a list of dictionaries with optimization information at each iteration including ‘x’ (parameter values), ‘fun’ (objective value), ‘jac’ (gradient), and constraint information. Default is False for backward compatibility.

Returns:
optimal_budgetsxarray.DataArray

The optimized budget allocation across channels.

resultOptimizeResult

The raw scipy optimization result.

callback_infolist[dict[str, Any]], optional

Only returned if callback=True. List of dictionaries containing optimization information at each iteration.

Raises:
MinimizeException

If the optimization fails for any reason, the exception message will contain the details.