mod portfolio

module portfolio

Thompson-allocated portfolio over the typed algebra’s building blocks.

One generic global optimizer with a single knob: the budget. Each building block is an arm of a Bernoulli bandit; a discounted Beta-Bernoulli posterior tracks the probability that one budget slice of an arm improves the incumbent, and Thompson sampling allocates the next slice. A decaying uniform-selection probability min(1, 1/m) on round m gives each of K arms probability at least 1/(Km). The divergent harmonic mass keeps every arm scheduled infinitely often and preserves the randomized restart guarantee.

Scheduler quantities derive from the problem and the budget rather than from tuning knobs: the slice size affords a few gradient- equivalents and at least several expected rounds per arm; the posterior discount sets the effective memory to the slice horizon; the active arm count is capped by what the horizon can rank; the budget tail funds a final polish from the incumbent. Arm-internal constants reuse the defaults of the standalone drivers they wrap.

Work accounting is uniform: every true-objective evaluation and every native-gradient evaluation costs one unit of the shared budget. The additive surrogate is fit from the archive of already- charged evaluations, so its proposals cost only their acceptance tests.

Functions

fn discovery_value(n1: usize, n: usize, w: usize) -> f64

D9.3: Good-Turing x record discovery value theta_disc = n1 / (n (w+1)).

fn portfolio_optimize<O, G>(obj: &O, grad: Option<&G>, budget: usize, seed: u64, noise_sigma: Option<f64>) -> PortfolioResult
where
    O: Objective<f64>,
    G: Gradient<f64>

Runs the portfolio under the default auto policy.

fn portfolio_optimize_with_policy<O, G>(obj: &O, grad: Option<&G>, budget: usize, seed: u64, noise_sigma: Option<f64>, policy: PortfolioPolicy) -> PortfolioResult
where
    O: Objective<f64>,
    G: Gradient<f64>

Runs the portfolio driver under a shared work-unit budget.

budget bounds combined true-objective and native-gradient evaluations and is the driver’s only required parameter. grad enables the gradient arms and the final polish. policy selects regime auto-routing (Auto) or flat legacy order.

fn win_objective_discovery(remaining: usize, polish: usize, slice_size: usize, theta_disc: f64, p_conv: f64) -> f64

D10.1 win objective under D9 discovery: W(p) = (q0+(1-q0)(1-pi_e))*P_conv.

theta_disc is discovery_value; p_conv is polish conversion probability for the proposed polish work polish; slice_size is exploration slice length.

Enums

enum PortfolioPolicy

Portfolio scheduling policy (GJQ-style: auto vs flat legacy for A/B).

Auto

Feature-based regime selection + prior boosts (default shipped path).

Legacy

Pre-regime behaviour: fixed Default arm order, uninformative Beta(1,1). Used only for same-protocol regression / A-B measurement.

Structs and Unions

struct ArmStat

Per-arm pull statistics reported by the driver.

name: &'static str

Stable arm identifier.

pulls: usize

Slices allocated to the arm.

successes: usize

Slices that improved the incumbent past the success threshold.

struct PortfolioResult

Result of a portfolio run.

best_pos: Vec<f64>

Best-seen position.

best_val: f64

Best-seen objective value.

n_evals: usize

True-objective evaluations charged.

n_grads: usize

Native-gradient evaluations charged.

arm_stats: Vec<ArmStat>

Per-arm allocation statistics.