# Statistical intelligence: method revision 5 (Cloud Master 4.3.135)

## Product promise
Security, accuracy, efficiency, usability, then wow factor. Independent standard-library-only module `cm_stat_engine.py`, API v1, method revision 5. No file/network/command access in the engine, no new measurement permissions, no browser analytics, no automatic health changes. Existing adapter and publication policy remain in force. The interface describes what was observed, not a causal diagnosis. Missing is not zero. The output is a screened descriptive hypothesis, not a significance test.

| Concept | Plain English | Implementation |
|---|---|---|
| Robust reference | One burst should not redefine normal | Median and MAD on reference readings; exclude the two previous candidate elevations. |
| Replication over time | Did the pattern happen repeatedly, or just once? | Three disjoint equal-duration sections, each with meaningful within-section activity and pressure contrast. |
| Detrending | Two rising graphs do not necessarily explain each other | Fit separate least-squares straight lines against actual elapsed time; correlate residuals; require meaningful residual variation. |
| Duration weighting | Ten seconds of waiting matter ten times as much as one second | Sum observed stall percentages times interval duration, divided by total measured seconds. |
| Holdout validation | Could the model have predicted data it had not been fitted to? | Fit first half; compare MAE on later half against constant last training value. |
| Sensitivity analysis | How soon might capacity be reached if growth is faster or slower? | Project from current use with each half-window slope; label as conditional scenarios. |
| Similar-demand comparison | Compare peer activity when the affected workload had similar own demand | Existing narrow demand matching, stronger repetition and trend screens. |

## Exact definitions and engineering defaults

- 300-second bounded window, up to 128 observations per resource, 64 workloads. A gap >15 s or counter reset breaks relevant evidence. Host `some` PSI = 100 * (counter delta in microseconds)/(elapsed seconds * 1e6); range 0–100. No impossible values clamped. This is fraction of wall time with at least one stalled task, not sum of per-task time. `avg = sum(p_i*d_i)/sum(d_i)` using only complete measured intervals within window; extrema are interval-level, not instantaneous. Missing intervals excluded; coverage seconds and sample count emitted. CPU/RAM resource profiles retain arithmetic averages and additionally publish explicitly estimated time averages and covered seconds (revision 4 below).
- Association: at least 12 pairs over 45 seconds, activity range floor (10 CPU percentage points, 16 MiB memory, 64 KiB/s I/O), pressure range at least 1 percentage point, Pearson r >= .70, high/low activity quartiles non-overlapping, mean pressure contrast >= 1 point and repeated high-cohort elevation. Method 2 adds three equal-duration blocks, >=4 pairs and >=8 seconds of observations in each; median upper/lower halves differ by >= half the activity floor and >=1 pressure point within each block. Linear residuals must vary by >= half the activity floor and >=1 pressure point; residual Pearson r >= .65. Raw r, detrended r, observation count, span and number of qualifying blocks are reported. No independence assertion: adjacent data and blocks can be serially dependent. Cohort contrasts are descriptive, not controlled effects; revision 5 weights measured interval duration as specified below. Peer analysis keeps only the contiguous suffix of valid target local-pressure readings and drops cached associations on evidence loss. No p-values, confidence percentage, independent sample-size estimate or false-discovery rate is claimed. Multiple searches and shared nonlinear causes can still yield spurious associations. Thresholds are conservative product heuristics, not universal statistical constants.
- Behavioral baseline: >=12 reference observations spanning >=45 s, plus two previous candidate observations. Reference median m and MAD = median(|x-m|). Band = max(physical floor, 4*1.4826*MAD). This is an empirical deviation threshold, not a normal-distribution probability interval. Current and two preceding values must exceed m+band. Reference adapts; seasonal patterns and permanent regime change are not modeled.
- Forecast: >=12 readings over >=60 s, two positive half-window slopes with max/min <=3, overall correlation with time >=.90, each half spans >=20 s, meaningful growth, current use >=50% of reference capacity and below it, central crossing <=3600 s. Chronological first-half least-squares fit is evaluated on the second half: MAE must be <0.8 times MAE of the constant last training value. This is a holdout screening rule, not independent external validation or rolling-origin cross-validation. Central crossing = (limit-current)/mean(half slopes). Scenario crossings use max and min slopes, respectively. They may extend beyond the central one-hour eligibility horizon; not confidence intervals, not calibrated probabilities, not safety deadlines. Sudden changes, quotas, memory reclaim, OOM, changing demand and unobserved future events can invalidate any projection. The same holdout is used to select reports, so published scores are selection-conditioned.
- Events: actual timed transfer attempts use before/after cumulative PSI, baseline duration-weighted over complete preceding intervals excluding recorded transfer windows. May include failed attempts or unrelated concurrent activity. Local cgroup measurements require supported scope and available counters; storage size remains opt-in and excludes mounted volumes/shared physical allocation. See STATISTICAL_ENGINE_API.md for limits and integration contract.

## Reproducibility and research

Run `python3 tests/test_statistical_evidence.py`, `python3 tests/test_stat_engine_extended.py`, `python3 tests/test_workload_intelligence.py`. Synthetic fixtures cover shared trend, one change point, repeat association, missing/reset counters, unequal duration and forecast holdout. Seeded independent-noise trials are smoke tests, not empirical production false-positive calibration. All six original feature paths remain present and tested under fixtures; actual Pi, actual rootless cgroup/disk availability and real transfer measurements require field qualification.

- NIST Engineering Statistics Handbook, autocorrelation: https://itl.nist.gov/div898/handbook/eda/section3/eda35c.htm
- NIST, robust scale: https://itl.nist.gov/div898/handbook/eda/section3/eda356.htm
- Hyndman & Athanasopoulos, Forecasting: Principles and Practice, regression diagnostics: https://otexts.com/fpp3/regression-evaluation.html ; time-series validation: https://otexts.com/fpp3/tscv.html
- Linux PSI: https://docs.kernel.org/accounting/psi.html

## Further study (not implemented)
Rolling-origin horizon-specific calibration, block resampling preserving dependence, multiple-comparison control on a defined hypothesis family, robust change-point and seasonal models, and controlled intervention designs. Require long field traces and measured false-positive/coverage/resource budgets before adopting them. No statistical method can establish causation from coincident observational telemetry alone. Keep the engine separable and independently versioned; do not add heavy libraries without a measurable improvement on relevant held-out field data.

## Revision 3: continuity of peer evidence
A previously computed peer association is withdrawn immediately if either activity stream becomes unavailable, the target local PSI becomes invalid, or either memory reference capacity changes. A memory capacity change also breaks paired host-pressure evidence; old and new capacity regimes are not pooled. No new inference claims are introduced.

## Revision 4: workload averaging and evidence presentation
For valid sampled observations (t_i, x_i), `avg = sum(x_i)/n` is the arithmetic sample mean. `time_avg = sum((x_i+x_{i+1})/2 * (t_{i+1}-t_i))/sum(t_{i+1}-t_i)` is an estimated time average using linear interpolation. Count only adjacent valid samples, both inside the 300-second window, separated by a positive interval <=15 seconds. A missing reading breaks adjacency; no extrapolation, gap fill or artificial zero. `observed_seconds` is the summed duration; `intervals` counts the accepted pairs. If no intervals exist, `time_avg` is null, even for a valid zero observation. Min/max are extrema of actual samples, not continuous or lifetime extremes. Memory percentages use the latest contiguous reported-limit regime; memory bytes and CPU sample histories are separate. Inventory loss clears profiles; duplicate timestamps are not appended, and clock rollback clears the stream.

Example: CPU samples at t=1,2,11 s with values 0,0,100% yield sample mean 33.3%, interpolated time estimate 45% over 10 s. This is not measured CPU-seconds: runtime CPU readings are already estimates over runtime-specific intervals, and interpolating samples cannot recover the underlying exact counter integral. For cumulative kernel PSI, the interval duration weighting remains exact with respect to the accepted counter deltas and timestamps; exclude boundary-crossing intervals and report the actual included count. Kernel reads and timestamps are not atomic, so acquisition timing and kernel accounting precision still matter. The existing oscilloscope view average is a rendering-side estimate across displayed samples, not a substitute for server-side evidence.

Revision 4 used sample means of pressure in lowest/highest activity quartiles; revision 5 replaces those means for timed observations as described below. Neither is a causal effect. `holdout_improvement_percent = 100*(1 - MAE_trend/MAE_naive)` computed before rounding. This is conditional historical prediction error reduction, not confidence or future forecast accuracy. The UI displays held-out sample count, reference baseline sample count, and transfer baseline time coverage when available. No new inference or alarm rule.

Verification: exact rational arithmetic oracle on 30 fixed-seed irregular sequences, all-zero and isolated observations, missing samples, large gaps, rollback, duplicate timestamps, denominator changes, inventory loss, and desktop/mobile rendering. Reference: Linux PSI https://docs.kernel.org/accounting/psi.html ; time-weighted statistics https://docs.timescale.com/use-timescale/latest/hyperfunctions/time-weighted-averages/ ; irregular time series weighting https://academic.oup.com/mnras/article/437/1/147/993398.

## Revision 5 — duration-weighted activity cohorts
Production host and peer comparisons use low and high activity quartile cutoffs by observation count, retaining all tied activity observations at each cutoff; overlapping cutoffs are rejected. Each cohort pressure is sum(stall_percent × elapsed_seconds)/sum(elapsed_seconds). The higher group must exceed the lower by at least one percentage point; repeated high values must represent at least half the high-group duration and satisfy the existing sample-count screen. The same descriptive Pearson and detrended correlation and three-block screens remain sample-based; no significance or causality asserted. The peer calculation carries the victim PSI interval duration. Three-column internal analytical inputs are explicitly sample-weighted; mixed or invalid durations are rejected. Publication adds cohort sample counts, covered seconds and pressure difference in percentage points. These are observed interval comparisons, not causal effects.
