Production-oriented robust statistics, streaming analytics, anomaly detection, and risk toolkit for MoonBit.
fn init {
let sensor = [1.0, 2.0, 3.0, 4.0, 100.0]
let center = @robust_stats.median(sensor)
let scale = @robust_stats.mad(sensor)
let clean = @robust_stats.hampel_filter(sensor, 3)
let interval = @robust_stats.bootstrap_median_interval(sensor, 200, seed=202608)
println("center=" + center.to_string())
println("scale=" + scale.to_string())
println("clean=" + clean.to_string())
println("CI=[" + interval.lower.to_string() + ", " + interval.upper.to_string() + "]")
}let detector = @robust_stats.WindowedAnomalyDetector::new(31, threshold=3.5)
for value in readings {
if detector.observe(value) {
println("anomaly")
}
}moon version --all
moon check --deny-warn
moon test --deny-warn
moon check --target all
moon test --target all
moon run cmd/benchmark| 文件/目录 | 作用 |
|---|---|
| mad.mbt, quantile.mbt, dispersion.mbt | 基础统计与分位数 |
| estimators.mbt, outlier.mbt, optimization.mbt | 稳健估计与异常点 |
| rolling.mbt, signal.mbt, timeseries.mbt | 时间序列与信号处理 |
| regression.mbt, correlation.mbt, matrix.mbt | 模型、相关和矩阵 |
| stream.mbt, streaming_advanced.mbt, window_detector.mbt | 流式与在线监控 |
| resampling.mbt, risk.mbt, diagnostics.mbt | 置信区间、风险与诊断 |
| pipeline.mbt | 面向业务的组合流程 |
| cmd/benchmark | 可复现 benchmark 入口 |
| *_test.mbt | 黑盒边界与回归测试 |
pub struct AdaptiveClipper {
center : Double
scale : Double
alpha : Double
threshold : Double
initialized : Bool
}pub struct AnomalyDetector {
center : Double
scale : Double
threshold : Double
fitted : Bool
}pub struct BenchmarkCase {
name : String
sample_size : Int
mean : Double
median : Double
mad : Double
trimmed_mean : Double
winsorized_mean : Double
huber_location : Double
outlier_count : Int
covariance : Double
stream_mean : Double
}pub struct BootstrapInterval {
estimate : Double
lower : Double
upper : Double
confidence : Double
replicates : Int
}pub struct ConfusionMatrix {
true_positive : Int
false_positive : Int
true_negative : Int
false_negative : Int
}pub struct DatasetSummary {
count : Int
minimum : Double
maximum : Double
mean : Double
median : Double
q1 : Double
q3 : Double
iqr : Double
mad : Double
standard_deviation : Double
skewness : Double
outlier_count : Int
outlier_fraction : Double
}pub struct DeterministicRng {
state : Int
}pub struct LinearRegressionResult {
slope : Double
intercept : Double
scale : Double
r_squared : Double
iterations : Int
converged : Bool
residuals : Array[Double]
}pub struct LocationScaleEstimate {
location : Double
scale : Double
iterations : Int
converged : Bool
}pub struct RobustPipeline {
window : Int
trim_percent : Double
threshold : Double
detector : AnomalyDetector
fitted : Bool
}fn RobustPipeline::fit_transform(self : RobustPipeline, reference : Array[Double]) -> PipelineResultpub struct StreamingCovariance {
count : Int
mean_x : Double
mean_y : Double
co_moment : Double
m2_x : Double
m2_y : Double
}pub struct StreamingMoments {
count : Int
mean : Double
m2 : Double
m3 : Double
m4 : Double
}pub struct StreamingQuantileSketch {
capacity : Int
values_buffer : Array[Double]
seen : Int
state : Int
}fn StreamingQuantileSketch::quantile(self : StreamingQuantileSketch, probability : Double) -> Doubletype StreamingRobustStatspub struct WindowedAnomalyDetector {
window : StreamingWindow
threshold : Double
total_seen : Int
total_anomalies : Int
}fn WindowedAnomalyDetector::observe_many(self : WindowedAnomalyDetector, data : Array[Double]) -> Array[Bool]fn bootstrap_difference_interval(first : Array[Double], second : Array[Double], replicates : Int, confidence? : Double, seed? : Int) -> BootstrapIntervalfn bootstrap_mad_interval(data : Array[Double], replicates : Int, confidence? : Double, seed? : Int) -> BootstrapIntervalfn bootstrap_mean_interval(data : Array[Double], replicates : Int, confidence? : Double, seed? : Int) -> BootstrapIntervalfn bootstrap_median_interval(data : Array[Double], replicates : Int, confidence? : Double, seed? : Int) -> BootstrapIntervalfn bootstrap_trimmed_mean_interval(data : Array[Double], trim_percent : Double, replicates : Int, confidence? : Double, seed? : Int) -> BootstrapIntervalfn golden_section_location(data : Array[Double], lower : Double, upper : Double, iterations : Int) -> Doublefn gradient_descent_location(data : Array[Double], initial : Double, learning_rate : Double, iterations : Int, tuning : Double) -> Doublefn grid_search_location(data : Array[Double], lower : Double, upper : Double, steps : Int) -> Doublefn huber_location_estimate(data : Array[Double], tuning? : Double, max_iter? : Int, tol? : Double) -> LocationScaleEstimatefn huber_regression(x : Array[Double], y : Array[Double], tuning? : Double, max_iter? : Int, tol? : Double) -> LinearRegressionResultfn pipeline_resample(data : Array[Double], window : Int, threshold : Double, replicates : Int, seed? : Int) -> BootstrapIntervalfn quantile_range(data : Array[Double], lower_probability : Double, upper_probability : Double) -> Doublefn regression_prediction_interval(model : LinearRegressionResult, x_value : Double, z_value : Double) -> Array[Double]fn robust_bootstrap_ensemble(data : Array[Double], replicates : Int, seed? : Int) -> BootstrapIntervalfn tukey_bisquare_location(data : Array[Double], tuning? : Double, max_iter? : Int, tol? : Double) -> LocationScaleEstimatefn validate_bootstrap_configuration(data : Array[Double], replicates : Int, sample_size : Int) -> Boolfn validate_cluster_configuration(cluster_count : Int, max_iter : Int, tol : Double) -> Boolfn validate_detector_configuration(window : Int, threshold : Double) -> Boolfn validate_stream_configuration(capacity : Int, clip : Double) -> Boolfn weighted_linear_regression(x : Array[Double], y : Array[Double], weights : Array[Double]) -> LinearRegressionResultProduction-oriented robust statistics, streaming analytics, anomaly detection, and risk toolkit for MoonBit.