Skip to main content

Calibration

Struct Calibration 

Source
pub struct Calibration {
Show 21 fields pub sigma_rate: Matrix9, pub block_length: usize, pub sigma_t: f64, pub l_r: Matrix9, pub prior_cov_marginal: Matrix9, pub theta_ns: f64, pub calibration_samples: usize, pub discrete_mode: bool, pub mde_shift_ns: f64, pub mde_tail_ns: f64, pub calibration_snapshot: CalibrationSnapshot, pub timer_resolution_ns: f64, pub samples_per_second: f64, pub c_floor: f64, pub projection_mismatch_thresh: f64, pub theta_tick: f64, pub theta_eff: f64, pub theta_floor_initial: f64, pub rng_seed: u64, pub batch_k: u32, pub preflight_result: PreflightResult,
}
Expand description

Calibration results from the initial measurement phase (no_std compatible).

This struct contains the essential statistical data needed for the adaptive sampling loop. It is designed for use in no_std environments like SGX enclaves.

For full calibration with preflight checks, see tacet::Calibration.

§Student’s t Prior (v5.4+)

The prior is a Student’s t distribution with ν=4 degrees of freedom: δ ~ t_ν(0, σ_t²R)

This is implemented via scale mixture: λ ~ Gamma(ν/2, ν/2), δ|λ ~ N(0, (σ_t²/λ)R). The marginal variance is (ν/(ν-2)) σ_t² R = 2σ_t² R for ν=4.

Fields§

§sigma_rate: Matrix9

Covariance “rate” - multiply by 1/n to get Sigma_n for n samples. Computed as Sigma_cal * n_cal where Sigma_cal is calibration covariance. This allows O(1) covariance scaling as samples accumulate.

§block_length: usize

Block length from Politis-White algorithm. Used for block bootstrap to preserve autocorrelation structure.

§sigma_t: f64

Calibrated Student’s t prior scale (v5.4). This is the σ in δ|λ ~ N(0, (σ²/λ)R).

§l_r: Matrix9

Cholesky factor L_R of correlation matrix R. Used for Gibbs sampling: δ = (σ/√λ) L_R z.

§prior_cov_marginal: Matrix9

Marginal prior covariance: 2σ²R (for ν=4). This is the unconditional prior variance of δ under the t-prior.

§theta_ns: f64

The theta threshold being used (in nanoseconds).

§calibration_samples: usize

Number of calibration samples collected per class.

§discrete_mode: bool

Whether discrete mode is active (< 10% unique values). When true, use mid-quantile estimators and m-out-of-n bootstrap.

§mde_shift_ns: f64

Minimum detectable effect (shift component) from calibration.

§mde_tail_ns: f64

Minimum detectable effect (tail component) from calibration.

§calibration_snapshot: CalibrationSnapshot

Statistics snapshot from calibration phase for drift detection.

§timer_resolution_ns: f64

Timer resolution in nanoseconds.

§samples_per_second: f64

Measured throughput for time estimation (samples per second). The caller is responsible for measuring this during calibration.

§c_floor: f64

Floor-rate constant. Computed once at calibration: 95th percentile of max_k|Z_k| where Z ~ N(0, Σ_rate). Used for analytical theta_floor computation: theta_floor_stat(n) = c_floor / sqrt(n).

§projection_mismatch_thresh: f64

Projection mismatch threshold. 99th percentile of bootstrap Q_proj distribution.

§theta_tick: f64

Timer resolution floor component. theta_tick = (1 tick in ns) / K where K is the batch size.

§theta_eff: f64

Effective threshold for this run. theta_eff = max(theta_user, theta_floor) or just theta_floor in research mode.

§theta_floor_initial: f64

Initial measurement floor at calibration time.

§rng_seed: u64

Deterministic RNG seed used for this run.

§batch_k: u32

Batch size K for adaptive batching. When K > 1, samples contain K iterations worth of timing. Effect estimates must be divided by K to report per-call differences.

§preflight_result: PreflightResult

Results of core preflight checks run during calibration (no_std compatible). Platform-specific checks (like system configuration) are handled by the tacet crate’s wrapper.

Implementations§

Source§

impl Calibration

Source

pub fn new( sigma_rate: Matrix9, block_length: usize, sigma_t: f64, l_r: Matrix9, theta_ns: f64, calibration_samples: usize, discrete_mode: bool, mde_shift_ns: f64, mde_tail_ns: f64, calibration_snapshot: CalibrationSnapshot, timer_resolution_ns: f64, samples_per_second: f64, c_floor: f64, projection_mismatch_thresh: f64, theta_tick: f64, theta_eff: f64, theta_floor_initial: f64, rng_seed: u64, batch_k: u32, ) -> Self

Create a new Calibration with v5.4+ Student’s t prior.

Source

pub fn with_preflight( sigma_rate: Matrix9, block_length: usize, sigma_t: f64, l_r: Matrix9, theta_ns: f64, calibration_samples: usize, discrete_mode: bool, mde_shift_ns: f64, mde_tail_ns: f64, calibration_snapshot: CalibrationSnapshot, timer_resolution_ns: f64, samples_per_second: f64, c_floor: f64, projection_mismatch_thresh: f64, theta_tick: f64, theta_eff: f64, theta_floor_initial: f64, rng_seed: u64, batch_k: u32, preflight_result: PreflightResult, ) -> Self

Create a new Calibration with all fields including preflight results.

Source

pub fn n_eff(&self, n: usize) -> usize

Compute effective sample size accounting for dependence (spec §3.3.2 v5.6).

Under strong temporal dependence, n samples do not provide n independent observations. The effective sample size approximates the number of effectively independent blocks.

n_eff = max(1, floor(n / block_length))

where block_length is the estimated dependence length from Politis-White selector.

Source

pub fn covariance_for_n(&self, n: usize) -> Matrix9

Scale sigma_rate to get covariance for n samples using effective sample size (v5.6).

Σ_n = Σ_rate / n_eff

where n_eff = max(1, floor(n / block_length)) to correctly account for reduced information under temporal dependence.

Source

pub fn covariance_for_n_raw(&self, n: usize) -> Matrix9

Scale sigma_rate to get covariance using raw n samples (ignoring dependence).

Σ_n = Σ_rate / n

Use this only when you need the raw scaling without n_eff correction.

Source

pub fn estimate_collection_time_secs(&self, n: usize) -> f64

Estimate time to collect n additional samples based on calibration throughput.

Returns estimated seconds. Caller should add any overhead.

Source

pub fn to_summary(&self) -> CalibrationSummary

Convert to an FFI-friendly summary containing only scalar fields.

Trait Implementations§

Source§

impl Clone for Calibration

Source§

fn clone(&self) -> Calibration

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Calibration

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.