pub struct CostModel { /* private fields */ }Expand description
A rolling empirical cost model for a single subsystem (agent / strategy).
Records (n, time) samples in a bounded ring buffer and fits c · f(n) over
the candidate ComplexityClasses. Pure and dependency-free.
Implementations§
Source§impl CostModel
impl CostModel
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Creates a model that keeps the most recent capacity samples (min 1).
Sourcepub fn record(&mut self, n: f64, time_ms: f64)
pub fn record(&mut self, n: f64, time_ms: f64)
Records one (n, time_ms) observation. Overwrites the oldest sample once
the ring is full. Non-finite inputs are ignored.
Sourcepub fn best_fit(&self) -> Option<(ComplexityClass, f64)>
pub fn best_fit(&self) -> Option<(ComplexityClass, f64)>
Fits each complexity class by least squares and returns the best
(class, c) — the class with the smallest residual and the constant
factor that scales its f(n) to the data.
Returns None until there are at least two samples with distinct n
(a single workload size can’t distinguish the classes).
Sourcepub fn predict_ms(&self, n: f64) -> Option<f64>
pub fn predict_ms(&self, n: f64) -> Option<f64>
Predicts the cost in milliseconds at workload size n from the best fit.
None until best_fit is available.
Sourcepub fn latest_ms(&self) -> Option<f64>
pub fn latest_ms(&self) -> Option<f64>
The most recently recorded observation’s time in milliseconds, if any.
Fallback cost signal when predict_ms has no fit yet
(a stable workload never produces two distinct n values, so the model
can’t pick a complexity class — but the raw measurement is still the best
available anchor).