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
, optionalbudget_bounds
, and custom constraints.The default sum constraint ensures that the sum of the optimized budget equals
total_budget
. Ifbudget_bounds
are not provided, each channel will be constrained to lie in [0, total_budget].- Parameters:
- total_budget
float
The total budget to allocate.
- budget_bounds
DataArray
ordict
, 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.
- x0
np.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_kwargs
dict
, 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.
- total_budget
- Returns:
- optimal_budgets
xarray.DataArray
The optimized budget allocation across channels.
- result
OptimizeResult
The raw scipy optimization result.
- callback_info
list
[dict
[str
,Any
]], optional Only returned if callback=True. List of dictionaries containing optimization information at each iteration.
- optimal_budgets
- Raises:
MinimizeException
If the optimization fails for any reason, the exception message will contain the details.