use crate::common::divector::DiVector; /** * This class maintains a simple discounted statistics. Setters are avoided * except for discount rate which is useful as initialization from raw scores */ #[repr(C)] #[derive(Clone)] pub struct AnomalyDescriptor { // the current input point; can have missing values pub current_input: Vec, // current timestamp pub current_timestamp: usize, // potential missing values in the current input (ideally None) pub missing_values: Option>, // potentially transformed point used by RCF, can have different dimensions than input pub rcf_point: Option>, pub score: f32, pub internal_timestamp: usize, pub threshold: f32, pub anomaly_grade: f32, pub data_confidence: f32, pub forecast_reasonable: bool, // present only if grade > 0 pub attribution: Option, pub expected_rcf_point: Option>, pub relative_index: Option, // useful for time augmented forests pub expected_timestamp: Option, pub start_of_anomaly: Option, pub in_high_score_region: Option, pub relevant_attribution: Option>, pub time_attribution: Option, // the values being replaced; may correspond to past pub past_values: Option>, pub past_timestamp: Option, pub expected_values_list: Option>>, pub likelihood_of_values: Option> } impl AnomalyDescriptor { pub fn new(point: &[f32], timestamp: usize) -> Self { AnomalyDescriptor { current_input: Vec::from(point), current_timestamp: timestamp, missing_values: None, rcf_point: None, score: 0.0, internal_timestamp: 0, threshold: 0.0, anomaly_grade: 0.0, data_confidence: 0.0, forecast_reasonable: false, attribution: None, expected_rcf_point: None, relative_index: None, expected_timestamp: None, start_of_anomaly: None, in_high_score_region: None, relevant_attribution: None, time_attribution: None, past_values: None, past_timestamp: None, expected_values_list: None, likelihood_of_values: None } } pub fn new_with_missing_values(point: Vec, timestamp: usize, missing_values: Vec) -> Self { assert!(missing_values.len() <= point.len(), "incorrect input"); for i in &missing_values { assert!( *i >=0 && (*i as usize) < point.len(), "incorrect input") } AnomalyDescriptor { current_input: point.clone(), current_timestamp: timestamp, missing_values: Some(missing_values.clone()), rcf_point: None, score: 0.0, internal_timestamp: 0, threshold: 0.0, anomaly_grade: 0.0, data_confidence: 0.0, forecast_reasonable: false, attribution: None, expected_rcf_point: None, relative_index: None, expected_timestamp: None, start_of_anomaly: None, in_high_score_region: None, relevant_attribution: None, time_attribution: None, past_values: None, past_timestamp: None, expected_values_list: None, likelihood_of_values: None } } }