Production-oriented MoonBit change-point detection, streaming windows, multivariate monitoring, replay, SLO and alert routing
moon add Zy789kl/moon-change-point///|
import {
"Zy789kl/moon-change-point" @cp,
}
///|
fn main {
let detector = @cp.Cusum::new(target_mean=0.0, control_limit=5.0, drift=0.5)
println(detector.update_result(2.0, index=1).summary())
}pub struct AdaptiveBaseline {
moments : OnlineMoments
value : Double
learning_rate : Double
initialized : Bool
}pub struct AdaptiveThreshold {
threshold : Double
rate : Double
minimum : Double
maximum : Double
count : Int
}fn AdaptiveThreshold::new(initial? : Double, rate? : Double, minimum? : Double, maximum? : Double) -> AdaptiveThresholdpub(all) enum AggregationKind {
MeanAggregate
SumAggregate
MinimumAggregate
MaximumAggregate
StandardDeviationAggregate
}pub struct AlertBudget {
capacity : Double
refill : Double
tokens : Double
suppressed : Int
}fn AlertEvent::new(metric : String, point : ChangePoint, suppressed? : Bool, ordinal? : Int) -> AlertEventpub struct AlertPolicy {
minimum_score : Double
minimum_confidence : Double
minimum_gap : Int
recovery_points : Int
quiet_points : Int
healthy_points : Int
}fn AlertPolicy::new(minimum_score? : Double, minimum_confidence? : Double, minimum_gap? : Int, recovery_points? : Int) -> AlertPolicypub(all) enum AlertSeverity {
Informational
Warning
Critical
}pub struct Ar1Forecaster {
mean : Double
covariance : Double
variance : Double
previous : Double
count : Int
forgetting : Double
}pub struct BenchmarkResult {
name : String
samples : Int
passes : Int
detections : Int
first_detection : Int
checksum : Double
truth_count : Int
metrics : ChangePointMetrics
}pub struct BootstrapEstimate {
mean : Double
lower : Double
upper : Double
standard_error : Double
replicates : Int
}pub(all) enum ChangeDirection {
Increase
Decrease
VarianceIncrease
VarianceDecrease
DistributionShift
Unknown
}pub struct ChangePoint {
timestamp : Int64
index : Int
score : Double
confidence : Double
severity : AlertSeverity
direction : ChangeDirection
detector : String
baseline : Double
observed : Double
}fn ChangePoint::from_result(point : SignalPoint, result : DetectionResult, detector : String, baseline : Double) -> ChangePointpub struct ChangePointMetrics {
true_positives : Int
false_positives : Int
false_negatives : Int
precision : Double
recall : Double
f1 : Double
mean_detection_delay : Double
}pub struct ConsecutiveRule {
required : Int
hits : Int
misses : Int
}pub struct Cusum {
target_mean : Double
control_limit : Double
drift : Double
g_positive : Double
g_negative : Double
t : Int
}pub struct DataQualityGate {
minimum_ratio : Double
reject_non_monotonic : Bool
reject_dimension_mismatch : Bool
}fn DataQualityGate::new(minimum_ratio? : Double, reject_non_monotonic? : Bool, reject_dimension_mismatch? : Bool) -> DataQualityGatepub struct DetectionExplanation {
result : DetectionResult
baseline : Double
observed : Double
deviation : Double
relative_change : Double
contributions : Array[EvidenceContribution]
recommendation : String
}pub struct DetectionResult {
changed : Bool
score : Double
confidence : Double
direction : ChangeDirection
index : Int
evidence : Double
}fn DetectionResult::new(changed : Bool, score : Double, confidence : Double, direction : ChangeDirection, index : Int, evidence? : Double) -> DetectionResultpub struct DetectorSpec {
name : String
family : String
online : Bool
multivariate : Bool
robust : Bool
default_threshold : Double
description : String
}fn DetectorSpec::new(name : String, family : String, online : Bool, multivariate : Bool, robust : Bool, default_threshold : Double, description : String) -> DetectorSpecpub(all) enum DetectorType {
CusumDetector(Cusum)
PageHinkleyDetector(PageHinkley)
BayesianDetector(Bayesian)
}pub struct DeterministicRng {
state : Int64
}pub struct DistributionShiftDetector {
reference : DoubleWindow
current : DoubleWindow
threshold : Double
index : Int
}fn DistributionShiftDetector::new(window_size? : Int, threshold? : Double) -> DistributionShiftDetectorfn DistributionShiftDetector::update(self : DistributionShiftDetector, value : Double) -> DetectionResultpub struct EnsembleResult {
result : DetectionResult
votes : Int
detector_count : Int
agreement : Double
}pub struct EvidenceContribution {
name : String
value : Double
weight : Double
contribution : Double
}fn EvidenceContribution::new(name : String, value : Double, weight? : Double) -> EvidenceContributionpub struct EwmaDetector {
baseline : Double
variance : Double
alpha : Double
threshold : Double
warmup : Int
count : Int
index : Int
initialized : Bool
}fn EwmaDetector::new(alpha? : Double, threshold? : Double, warmup? : Int, initial_mean? : Double, initial_variance? : Double) -> EwmaDetectorpub struct FeatureExtractor {
left : DoubleWindow
right : DoubleWindow
threshold : Double
index : Int
}pub struct ForecastPoint {
prediction : Double
lower : Double
upper : Double
residual : Double
}fn ForecastPoint::new(prediction : Double, residual : Double, uncertainty? : Double) -> ForecastPointpub struct Histogram {
minimum : Double
maximum : Double
bins : Int
counts : Array[Int]
total : Int
}pub struct HoltForecaster {
level : Double
trend : Double
alpha : Double
beta : Double
count : Int
}pub struct HysteresisRule {
enter_threshold : Double
exit_threshold : Double
active : Bool
}pub struct Incident {
metric : String
first_timestamp : Int64
last_timestamp : Int64
alerts : Int
critical : Int
maximum_score : Double
direction : ChangeDirection
}pub(all) enum LateDataPolicy {
Drop
KeepForCorrection
ReplaceSameTimestamp
}fn LinearForecaster::new(window_size? : Int, horizon? : Int, uncertainty_multiplier? : Double) -> LinearForecasterpub struct MahalanobisDetector {
stats : OnlineVectorStats
threshold : Double
warmup : Int
index : Int
}fn MahalanobisDetector::new(dimension : Int, threshold? : Double, warmup? : Int) -> MahalanobisDetectorfn MahalanobisDetector::update(self : MahalanobisDetector, values : Array[Double]) -> DetectionResultpub struct MeanVarianceDetector {
baseline : DoubleWindow
current : DoubleWindow
mean_threshold : Double
variance_threshold : Double
index : Int
}fn MeanVarianceDetector::new(window_size? : Int, mean_threshold? : Double, variance_threshold? : Double) -> MeanVarianceDetectorpub struct MetricPipeline {
name : String
detector : PipelineDetector
policy : AlertPolicy
index : Int
ordinal : Int
baseline : Double
}fn MetricPipeline::new(name : String, detector : PipelineDetector, policy? : AlertPolicy, baseline? : Double) -> MetricPipelinepub struct MultiMetricMonitor {
pipelines : Array[MetricPipeline]
processed : Int
emitted : Int
suppressed : Int
}fn MultiMetricMonitor::process(self : MultiMetricMonitor, metric_index : Int, timestamp : Int64, value : Double) -> AlertEvent?fn MultiMetricMonitor::process_batch(self : MultiMetricMonitor, metric_index : Int, points : Array[SignalPoint]) -> Array[AlertEvent]pub struct MultiScaleDetector {
short : RobustZDetector
medium : RobustZDetector
long : TrendShiftDetector
minimum_consensus : Double
index : Int
}fn MultiScaleDetector::new(short? : Int, medium? : Int, long? : Int, minimum_consensus? : Double) -> MultiScaleDetectorfn MultivariateEnsemble::new(detectors : Array[ProjectionDetector], quorum? : Int) -> MultivariateEnsemblefn MultivariateEnsemble::update(self : MultivariateEnsemble, values : Array[Double]) -> DetectionResultpub struct OfflineChange {
index : Int
score : Double
left_mean : Double
right_mean : Double
left_variance : Double
right_variance : Double
direction : ChangeDirection
}pub struct OnlineMoments {
count : Int
mean : Double
m2 : Double
minimum : Double
maximum : Double
}fn OnlineVectorStats::standardized(self : OnlineVectorStats, values : Array[Double]) -> Array[Double]pub struct PageHinkley {
target_mean : Double
control_limit : Double
delta : Double
alpha : Double
sum : Double
min_sum : Double
n : Int
}fn PageHinkley::new(target_mean? : Double, control_limit? : Double, delta? : Double, alpha? : Double) -> PageHinkleypub(all) enum PipelineDetector {
LegacyDetector(Detector)
Ewma(EwmaDetector)
RobustZ(RobustZDetector)
VarianceShift(VarianceShiftDetector)
TrendShift(TrendShiftDetector)
IqrSpike(IqrSpikeDetector)
}fn PipelineDetector::update(self : PipelineDetector, value : Double, index : Int) -> DetectionResultpub struct ProjectionDetector {
weights : Array[Double]
baseline : Double
variance : Double
alpha : Double
threshold : Double
count : Int
index : Int
}fn ProjectionDetector::new(weights : Array[Double], alpha? : Double, threshold? : Double) -> ProjectionDetectorpub(all) enum QualityIssue {
MissingValue
NonFiniteValue
OutOfRange
NonMonotonicTimestamp
ExcessiveGap
DimensionMismatch
}pub struct QualityReport {
count : Int
valid : Int
missing : Int
non_finite : Int
out_of_range : Int
non_monotonic : Int
excessive_gaps : Int
issues : Array[QualityIssue]
}pub struct RankShiftDetector {
left : DoubleWindow
right : DoubleWindow
threshold : Double
index : Int
}pub struct RecoveryPlan {
severity : AlertSeverity
immediate_action : String
verification_window : Int
cooldown : Int
escalation_score : Double
}pub struct RecoveryTracker {
plan : RecoveryPlan
attempts : Int
acknowledged : Bool
recovered : Bool
}pub struct ReorderBuffer {
capacity : Int
policy : LateDataPolicy
pending : Array[OrderedPoint]
watermark : Int64
arrival_order : Int
dropped : Int
late_count : Int
}pub struct ReplayComparator {
score_tolerance : Double
confidence_tolerance : Double
compared : Int
mismatches : Int
}fn ReplayComparator::compare(self : ReplayComparator, expected : DetectionResult, actual : DetectionResult) -> Boolfn ReplayComparator::new(score_tolerance? : Double, confidence_tolerance? : Double) -> ReplayComparatorfn ReplayRecord::new(point : SignalPoint, result : DetectionResult, elapsed : Int64) -> ReplayRecordpub struct ReplaySummary {
total : Int
changed : Int
first_change : Int
last_change : Int
mean_score : Double
max_score : Double
elapsed : Int64
}pub struct ReservoirSample {
capacity : Int
values : Array[Double]
seen : Int
rng : DeterministicRng
}pub struct RoutingBudget {
capacity : Int
used : Int
}pub struct RoutingDecision {
metric : String
channel : String
priority : Int
acknowledged : Bool
reason : String
}fn RoutingDecision::new(metric : String, channel : String, priority : Int, reason : String) -> RoutingDecisionpub struct ScaleEvidence {
short_score : Double
medium_score : Double
long_score : Double
consensus : Double
changed : Bool
}pub struct ScoreCalibrator {
observations : Array[ScoreObservation]
max_observations : Int
positive_weight : Double
negative_weight : Double
}fn ScoreCalibrator::push(self : ScoreCalibrator, score : Double, changed : Bool, weight? : Double) -> Unitpub struct ScoreObservation {
score : Double
changed : Bool
weight : Double
}fn SeasonalAnomalyDetector::new(period : Int, threshold? : Double, alpha? : Double) -> SeasonalAnomalyDetectorfn SeasonalAnomalyDetector::update(self : SeasonalAnomalyDetector, value : Double) -> DetectionResultpub struct SegmentQuality {
count : Int
mean : Double
deviation : Double
stability : Double
completeness : Double
score : Double
}pub struct SegmentRange {
start : Int
end : Int
}pub(all) enum SignalPattern {
Stable
MeanShift
VarianceShift
Trend
Spike
MeanAndVarianceShift
}pub struct SignalPoint {
timestamp : Int64
value : Double
sequence : Int
}pub struct SignalScenario {
name : String
length : Int
change_at : Int
baseline : Double
shift : Double
noise : Double
post_noise : Double
trend : Double
pattern : SignalPattern
seed : Int64
}fn SignalScenario::mean_and_variance(length? : Int, change_at? : Int, baseline? : Double, shift? : Double, noise? : Double, post_noise? : Double, seed? : Int64) -> SignalScenariofn SignalScenario::mean_shift(length? : Int, change_at? : Int, baseline? : Double, shift? : Double, noise? : Double, seed? : Int64) -> SignalScenariofn SignalScenario::spike(length? : Int, spike_at? : Int, baseline? : Double, spike? : Double, noise? : Double, seed? : Int64) -> SignalScenariofn SignalScenario::stable(length? : Int, baseline? : Double, noise? : Double, seed? : Int64) -> SignalScenariofn SignalScenario::trend(length? : Int, change_at? : Int, baseline? : Double, trend? : Double, noise? : Double, seed? : Int64) -> SignalScenariofn SignalScenario::variance_shift(length? : Int, change_at? : Int, baseline? : Double, noise? : Double, post_noise? : Double, seed? : Int64) -> SignalScenariopub struct SloReport {
window : SloWindow
target : Double
budget : Double
burn : Double
breached : Bool
recommendation : String
}pub struct SloWindow {
total : Int
bad : Int
changed : Int
severe : Int
}pub struct StatsSummary {
count : Int
mean : Double
variance : Double
standard_deviation : Double
minimum : Double
maximum : Double
median : Double
first : Double
last : Double
}pub struct StepChangeDetector {
reference : DoubleWindow
current : DoubleWindow
threshold : Double
index : Int
}pub struct StreamEngine {
reorder : ReorderBuffer
tracker : WatermarkTracker
aggregator : WindowAggregator
pipeline : MetricPipeline
processed : Int
aggregates : Int
alerts : Int
}fn StreamEngine::new(metric : String, detector : PipelineDetector, window_size? : Int, lateness? : Int) -> StreamEnginepub struct ThresholdPoint {
index : Int
threshold : Double
score : Double
accepted : Bool
}pub struct ThresholdReport {
threshold : Double
true_positives : Int
false_positives : Int
true_negatives : Int
false_negatives : Int
precision : Double
recall : Double
f1 : Double
expected_cost : Double
}pub struct TimeWindow {
start : Int64
end : Int64
ordinal : Int
}pub struct TrendShiftDetector {
window : DoubleWindow
slope_threshold : Double
persistence : Int
consecutive : Int
index : Int
}fn TrendShiftDetector::new(window_size? : Int, slope_threshold? : Double, persistence? : Int) -> TrendShiftDetectorpub struct VarianceShiftDetector {
short_window : DoubleWindow
long_window : DoubleWindow
threshold : Double
warmup : Int
index : Int
}fn VarianceShiftDetector::new(short_window? : Int, long_window? : Int, threshold? : Double) -> VarianceShiftDetectorpub struct WatermarkTracker {
allowed_lateness : Int64
maximum_seen : Int64
accepted : Int
dropped : Int
}pub struct WindowAggregate {
start_timestamp : Int64
end_timestamp : Int64
count : Int
value : Double
summary : StatsSummary
}pub struct WindowAggregator {
size : Int
kind : AggregationKind
window : DoubleWindow
start_timestamp : Int64
end_timestamp : Int64
count : Int
}pub struct WindowDiagnostic {
before : StatsSummary
after : StatsSummary
mean_shift : Double
variance_ratio : Double
distribution_shift : Double
severity : AlertSeverity
actionable : Bool
}pub struct WindowFeatures {
count : Int
mean : Double
standard_deviation : Double
median : Double
mad : Double
minimum : Double
maximum : Double
range : Double
slope : Double
autocorrelation : Double
change_rate : Double
}fn absolute(value : Double) -> Doublefn align_by_timestamp(left : Array[SignalPoint], right : Array[SignalPoint]) -> (Array[Double], Array[Double])fn best_f1_threshold(scores : Array[Double], labels : Array[Bool], candidates : Array[Double]) -> ThresholdPointfn best_threshold(observations : Array[ScoreObservation], candidates : Array[Double], false_positive_cost? : Double, false_negative_cost? : Double) -> ThresholdReportfn binary_segmentation(values : Array[Double], threshold? : Double, min_segment? : Int, max_changes? : Int) -> Array[OfflineChange]fn bootstrap_change_score(left : Array[Double], right : Array[Double], replicates? : Int, seed? : Int64) -> BootstrapEstimatefn bucket_timestamp(timestamp : Int64, origin : Int64, width : Int64) -> Int64fn clamp_probability(value : Double) -> Doublefn correlation_alert(before : Array[Array[Double]], after : Array[Array[Double]], threshold? : Double) -> DetectionResultfn diagnose_windows(before_values : Array[Double], after_values : Array[Double], shift_threshold? : Double, distribution_threshold? : Double) -> WindowDiagnosticfn evaluate_change_points(predicted : Array[Int], truth : Array[Int], tolerance? : Int) -> ChangePointMetricsfn evaluate_threshold(observations : Array[ScoreObservation], threshold : Double, false_positive_cost? : Double, false_negative_cost? : Double) -> ThresholdReportfn evidence_strength(score : Double, confidence : Double, deviation : Double) -> Doublefn expected_alert_cost(false_positive_rate : Double, false_negative_rate : Double, false_positive_cost? : Double, false_negative_cost? : Double) -> Doublefn explain_batch(results : Array[DetectionResult], baseline : Double, values : Array[Double], detector : String) -> Array[DetectionExplanation]fn is_finite(value : Double) -> Boolfn make_explanation(result : DetectionResult, baseline : Double, observed : Double, detector : String) -> DetectionExplanationfn merge_nearby_changes(changes : Array[OfflineChange], minimum_distance : Int) -> Array[OfflineChange]fn recommended_detector(multivariate : Bool, offline : Bool, robust : Bool) -> Stringfn rolling_origins(length : Int, train_size : Int, horizon : Int, step? : Int) -> Array[SegmentRange]fn weighted_consensus(results : Array[DetectionResult], weights : Array[Double], quorum : Double) -> DetectionResultfn window_summaries(points : Array[SignalPoint], windows : Array[TimeWindow]) -> Array[StatsSummary]Production-oriented MoonBit change-point detection, streaming windows, multivariate monitoring, replay, SLO and alert routing