Function pressure
pub fn pressure(
dist: &Distribution,
side: Side,
values: &[ParamValue],
top_set_len: usize,
) -> Result<f64>Expand description
The crowding fraction on side: the share of the top set that band
counts as “at the bound” there — §8.1’s
pressure(side S) = |{ t in top set : t is in band(dist, S) }| / |top set|.
§values and top_set_len count two different things, on purpose
values is one parameter’s recorded value from each top-set trial
that recorded it — never the trials themselves, and never padded for the
ones that did not record it (a trial that never took a conditional branch
simply contributes no entry). top_set_len is |top set|: the size of
the whole top set top_set produced, regardless of how many of its
trials happen to carry this particular parameter. §8’s formula divides by
the second number, never the first; the two coincide only when every
top-set trial recorded the parameter, which is not true for one reached
through a conditional branch.
This is a real, deliberate consequence for a conditional (define-by-run)
parameter, not an edge case filed off: one that only 3 of a 16-member top
set ever reached can score at most 3 / 16 = 0.1875 — never 3 / 3 = 1.0 — however tightly those 3 sit against the bound. A rarely-taken
branch therefore cannot clear the pressure >= 0.5 firing threshold (§8)
on the strength of the few trials that ever reached it, because
top_set’s warmup gate (completed >= max(16, 4 * dim_k), §8.4) is
global, not per-parameter: there is no separate, smaller warmup for a
branch most trials never take. atune documents conditional parameters as
a supported pattern, so a reader of this function will meet this case —
it is the formula’s own reading of §8, not a gap in it.
§Out-of-range values are the strongest evidence, not an error (§8.1)
A value can legitimately sit outside dist’s current range: a
warm-started study’s seed trials may be drawn from a wider range than the
study’s own declared bounds, and a veto rollback can narrow a
bound under trials already recorded. Such a value counts as maximally in
the band on the side it overshoots. It is never filtered out and never
raises Error::OutOfRange — filtering would silently hide exactly the
crowding evidence this rule exists to detect.
Returns 0.0, never NaN, when values is empty but top_set_len is
not: the case above, where no top-set trial recorded the parameter. An
empty top set itself (top_set_len == 0) is refused instead — see Errors.
§Errors
- Everything
bandreturns fordist. Error::InvalidSpaceiftop_set_lenis0— there is no top set to measure crowding against — or ifvalues.len() > top_set_len, sincevaluesmust be a subset of the top set it was drawn from.Error::OutOfRangeif a member ofvaluesis not the kind of valuedistproduces.
use atune_core::space::{Distribution, ParamValue, Side, pressure};
let lr = Distribution::float(0.0, 1.0).unwrap();
let top = [ParamValue::F64(0.99), ParamValue::F64(0.5)];
assert_eq!(pressure(&lr, Side::High, &top, top.len()).unwrap(), 0.5);
assert_eq!(pressure(&lr, Side::Low, &top, top.len()).unwrap(), 0.0);
// A value beyond the range still counts, on the side it overshoots.
let drifted = [ParamValue::F64(5.0)];
assert_eq!(pressure(&lr, Side::High, &drifted, 1).unwrap(), 1.0);
// A parameter only 1 of a 4-trial top set ever recorded scores at most
// 0.25, even sitting exactly on the bound -- see the note above.
assert_eq!(
pressure(&lr, Side::High, &[ParamValue::F64(1.0)], 4).unwrap(),
0.25
);