pub struct AnomalyInjector { /* private fields */ }Expand description
Main anomaly injection engine.
Implementations§
Source§impl AnomalyInjector
impl AnomalyInjector
Sourcepub fn new(config: AnomalyInjectorConfig) -> Self
pub fn new(config: AnomalyInjectorConfig) -> Self
Creates a new anomaly injector.
Sourcepub fn process_entries(
&mut self,
entries: &mut [JournalEntry],
) -> InjectionBatchResult
pub fn process_entries( &mut self, entries: &mut [JournalEntry], ) -> InjectionBatchResult
Processes a batch of journal entries, potentially injecting anomalies.
Sourcepub fn inject_specific(
&mut self,
entry: &mut JournalEntry,
anomaly_type: AnomalyType,
) -> Option<LabeledAnomaly>
pub fn inject_specific( &mut self, entry: &mut JournalEntry, anomaly_type: AnomalyType, ) -> Option<LabeledAnomaly>
Injects a specific anomaly type into an entry.
Sourcepub fn create_self_approval(
&mut self,
entry: &mut JournalEntry,
user_id: &str,
) -> Option<LabeledAnomaly>
pub fn create_self_approval( &mut self, entry: &mut JournalEntry, user_id: &str, ) -> Option<LabeledAnomaly>
Creates a self-approval anomaly.
Sourcepub fn create_sod_violation(
&mut self,
entry: &mut JournalEntry,
user_id: &str,
conflicting_duties: (&str, &str),
) -> Option<LabeledAnomaly>
pub fn create_sod_violation( &mut self, entry: &mut JournalEntry, user_id: &str, conflicting_duties: (&str, &str), ) -> Option<LabeledAnomaly>
Creates a segregation of duties violation.
Sourcepub fn create_ic_mismatch(
&mut self,
entry: &mut JournalEntry,
matching_company: &str,
expected_amount: Decimal,
actual_amount: Decimal,
) -> Option<LabeledAnomaly>
pub fn create_ic_mismatch( &mut self, entry: &mut JournalEntry, matching_company: &str, expected_amount: Decimal, actual_amount: Decimal, ) -> Option<LabeledAnomaly>
Creates an intercompany mismatch anomaly.
Sourcepub fn get_labels(&self) -> &[LabeledAnomaly]
pub fn get_labels(&self) -> &[LabeledAnomaly]
Returns all generated labels.
Sourcepub fn get_summary(&self) -> AnomalySummary
pub fn get_summary(&self) -> AnomalySummary
Returns the anomaly summary.
Sourcepub fn get_stats(&self) -> &InjectorStats
pub fn get_stats(&self) -> &InjectorStats
Returns injection statistics.
Sourcepub fn cluster_count(&self) -> usize
pub fn cluster_count(&self) -> usize
Returns the number of clusters created.
Sourcepub fn set_entity_contexts(
&mut self,
vendors: HashMap<String, VendorContext>,
employees: HashMap<String, EmployeeContext>,
accounts: HashMap<String, AccountContext>,
)
pub fn set_entity_contexts( &mut self, vendors: HashMap<String, VendorContext>, employees: HashMap<String, EmployeeContext>, accounts: HashMap<String, AccountContext>, )
Sets entity contexts for risk-adjusted anomaly injection.
When entity contexts are provided, the injector adjusts anomaly injection rates based on entity risk factors. Entries involving high-risk vendors, new employees, or sensitive accounts will have higher effective injection rates.
Pass empty HashMaps to clear previously set contexts.
Sourcepub fn vendor_contexts(&self) -> &HashMap<String, VendorContext>
pub fn vendor_contexts(&self) -> &HashMap<String, VendorContext>
Returns a reference to the vendor context map.
Sourcepub fn employee_contexts(&self) -> &HashMap<String, EmployeeContext>
pub fn employee_contexts(&self) -> &HashMap<String, EmployeeContext>
Returns a reference to the employee context map.
Sourcepub fn account_contexts(&self) -> &HashMap<String, AccountContext>
pub fn account_contexts(&self) -> &HashMap<String, AccountContext>
Returns a reference to the account context map.
Sourcepub fn advance_schemes(
&mut self,
date: NaiveDate,
company_code: &str,
) -> Vec<SchemeAction>
pub fn advance_schemes( &mut self, date: NaiveDate, company_code: &str, ) -> Vec<SchemeAction>
Advances all active fraud schemes by one time step.
Call this method once per simulated day to generate scheme actions. Returns the scheme actions generated for this date.
Sourcepub fn maybe_start_scheme(
&mut self,
date: NaiveDate,
company_code: &str,
available_users: Vec<String>,
available_accounts: Vec<String>,
available_counterparties: Vec<String>,
) -> Option<Uuid>
pub fn maybe_start_scheme( &mut self, date: NaiveDate, company_code: &str, available_users: Vec<String>, available_accounts: Vec<String>, available_counterparties: Vec<String>, ) -> Option<Uuid>
Potentially starts a new fraud scheme based on probabilities.
Call this method periodically (e.g., once per period) to allow new schemes to start based on configured probabilities. Returns the scheme ID if a scheme was started.
Sourcepub fn get_near_miss_labels(&self) -> &[NearMissLabel]
pub fn get_near_miss_labels(&self) -> &[NearMissLabel]
Returns all near-miss labels generated.
Sourcepub fn get_scheme_actions(&self) -> &[SchemeAction]
pub fn get_scheme_actions(&self) -> &[SchemeAction]
Returns all scheme actions generated.
Sourcepub fn get_difficulty_distribution(
&self,
) -> &HashMap<AnomalyDetectionDifficulty, usize>
pub fn get_difficulty_distribution( &self, ) -> &HashMap<AnomalyDetectionDifficulty, usize>
Returns the detection difficulty distribution.
Sourcepub fn check_behavioral_deviations(
&self,
entity_id: &str,
observation: &Observation,
) -> Vec<BehavioralDeviation>
pub fn check_behavioral_deviations( &self, entity_id: &str, observation: &Observation, ) -> Vec<BehavioralDeviation>
Checks for behavioral deviations for an entity with an observation.
Sourcepub fn get_entity_baseline(&self, entity_id: &str) -> Option<&EntityBaseline>
pub fn get_entity_baseline(&self, entity_id: &str) -> Option<&EntityBaseline>
Gets the baseline for an entity.
Sourcepub fn active_scheme_count(&self) -> usize
pub fn active_scheme_count(&self) -> usize
Returns the number of active schemes.
Sourcepub fn has_enhanced_features(&self) -> bool
pub fn has_enhanced_features(&self) -> bool
Returns whether enhanced features are enabled.
Auto Trait Implementations§
impl !Freeze for AnomalyInjector
impl !RefUnwindSafe for AnomalyInjector
impl !UnwindSafe for AnomalyInjector
impl Send for AnomalyInjector
impl Sync for AnomalyInjector
impl Unpin for AnomalyInjector
impl UnsafeUnpin for AnomalyInjector
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.