mod tpe

module tpe

TPE-style dual-density allocation (Bergstra et al. 2011).

Observations (config, score) are split by a quantile gamma into a “good” set (top scores) and a “bad” set. Independent Parzen / Dirichlet densities l(config) and g(config) are fit to each set; selection maximises the density ratio l/g (equivalent to expected improvement under TPE’s model). This module is pure: no I/O, no portfolio types.

Variables

const DEFAULT_ALPHA: f64

Dirichlet / Laplace smoothing for categorical densities.

const DEFAULT_GAMMA: f64

Default good-quantile used by Auto portfolio allocation.

Structs and Unions

struct TpeCategorical

Categorical TPE over n_categories discrete choices (e.g. arm indices).

Score convention: higher is better (improvement magnitude, not cost).

Implementations

impl TpeCategorical

Functions

fn best(&self) -> usize

Argmax of density ratio (deterministic exploit).

fn density_ratio(&self, category: usize) -> f64

Density ratio l(cat) / g(cat) with Dirichlet smoothing.

l and g are smoothed multinomials over the good and bad sets.

fn density_ratios(&self) -> Vec<f64>

Density ratio for every category.

fn is_empty(&self) -> bool

Returns true when no observations have been recorded.

fn len(&self) -> usize

Number of recorded observations.

fn new(n_categories: usize) -> Self

Empty history over n_categories choices.

fn pick<R: Rng + ?Sized>(&self, rng: &mut R) -> usize

Sample a category with probability proportional to l/g.

fn record(&mut self, category: usize, score: f64)

Record one (category, score) observation. Higher score = better.

fn with_params(n_categories: usize, gamma: f64, alpha: f64) -> Self

Full constructor.

struct TpeContinuous1d

One-dimensional continuous TPE with isotropic Gaussian kernels.

Used for continuous portfolio knobs (e.g. relative slice scale). Score is higher-is-better. Proposal support is the observed range expanded by one bandwidth on each side.

Implementations

impl TpeContinuous1d

Functions

fn density_ratio(&self, x: f64) -> f64

Density ratio l(x)/g(x).

fn is_empty(&self) -> bool

Returns true when no observations have been recorded.

fn len(&self) -> usize

Number of recorded (x, score) pairs.

fn new() -> Self

Empty continuous TPE with default gamma.

fn pick_candidates<R: Rng + ?Sized>(&self, n_candidates: usize, rng: &mut R) -> f64

Sample candidates uniformly in the expanded range and return the maximiser of l/g.

fn record(&mut self, x: f64, score: f64)

Record (x, score).