fraudtwin.simulation#
Simulation scenario composition and generation controls.
Status: Stable
Classes#
|
Stable, ordered behavior profiles and their generated payment stream. |
|
Generate customer profiles and their payment stream from M1 entities. |
|
Stable, ordered collections of all generated entities. |
|
Generate a reproducible population from a validated configuration. |
|
Complete payment stream plus explainable M6 truth records. |
|
Add only explicit F01-F05 campaigns to an existing legitimate stream. |
|
Stable M7 workflow records derived from M6 fraud records. |
|
Turn scenario-linked M6 records into a delayed operational truth path. |
|
Oracle descriptor for one deterministic scenario instance. |
|
Oracle membership for one generated graph-fraud campaign. |
|
Normalized lineage for a derived relationship. |
|
GraphFraudDataset(payments: tuple[fraudtwin.domain.payments.Payment, ...], payment_events: tuple[fraudtwin.domain.payments.PaymentEvent, ...], ledger_entries: tuple[fraudtwin.domain.payments.LedgerEntry, ...], fraud_records: tuple[fraudtwin.domain.fraud.FraudRecord, ...], memberships: tuple[fraudtwin.domain.graph.GraphCampaignMembership, ...], patterns: tuple[fraudtwin.domain.graph.GraphPattern, ...], campaigns: tuple[fraudtwin.domain.graph.GraphCampaign, ...] = (), evidence: tuple[fraudtwin.domain.graph.GraphEvidence, ...] = (), hyperedges: tuple[fraudtwin.domain.graph.GraphHyperedge, ...] = (), hyperedge_memberships: tuple[fraudtwin.domain.graph.GraphHyperedgeMembership, ...] = (), dynamic: 'DynamicCampaignDataset | None' = None) |
|
Generate graph scenarios using canonical participant allocation. |
|
Optional higher-order campaign incidence record. |
|
Membership of an entity in a higher-order graph relationship. |
|
A deterministic structural pattern descriptor. |
|
An opt-in synthetic network endpoint; absent from legacy runs. |
|
Stable, ordered payment business objects and their event envelopes. |
|
Generate positive, relationship-valid, legitimate payment events. |
|
Apply independently configurable, reproducible M8 faults. |
|
Complete, hashable M12 difficulty configuration. |
|
Resolved transformations for one fraud or graph scenario. |
Functions#
|
Apply resolved controls to one scenario without changing its objective. |
|
Count the explicit PIX lifecycle event types. |
|
Convenience function for deterministic behavior generation. |
|
Convenience function for deterministic entity generation. |
|
Resolve a level and its optional per-dimension replacements. |
Detailed API#
Deterministic entity generation and batch output adapters.
- class fraudtwin.simulation.BehaviorDataset(profiles, payments, payment_events, ledger_entries=(), fraud_records=(), alerts=(), fraud_cases=(), case_confirmations=(), customer_disputes=(), fraud_labels=(), label_observations=(), final_observed_labels=(), quality_fault_counts=<factory>, quality_fault_rates=<factory>, quality_diagnostics=<factory>, graph_memberships=(), graph_campaigns=(), graph_patterns=(), graph_evidence=(), graph_hyperedges=(), graph_hyperedge_memberships=(), camouflage_metadata=<factory>, oracle_tables=<factory>, quality_raw_faults=<factory>, schema_evolution_rows=<factory>, counterfactual=None, campaign_dynamics=None)[source][source]
Bases:
objectStable, ordered behavior profiles and their generated payment stream.
- Parameters:
profiles (tuple[BehaviorProfile, ...])
payments (tuple[Payment, ...])
payment_events (tuple[PaymentEvent, ...])
ledger_entries (tuple[LedgerEntry, ...])
fraud_records (tuple[FraudRecord, ...])
alerts (tuple[FraudAlert, ...])
fraud_cases (tuple[FraudCase, ...])
case_confirmations (tuple[FraudCaseConfirmation, ...])
customer_disputes (tuple[CustomerDispute, ...])
fraud_labels (tuple[DelayedFraudLabel, ...])
label_observations (tuple[LabelObservation, ...])
final_observed_labels (tuple[FinalObservedLabel, ...])
quality_fault_counts (dict[str, int])
quality_fault_rates (dict[str, float])
quality_diagnostics (dict[str, object])
graph_memberships (tuple[GraphCampaignMembership, ...])
graph_campaigns (tuple[GraphCampaign, ...])
graph_patterns (tuple[GraphPattern, ...])
graph_evidence (tuple[GraphEvidence, ...])
graph_hyperedges (tuple[GraphHyperedge, ...])
graph_hyperedge_memberships (tuple[GraphHyperedgeMembership, ...])
camouflage_metadata (dict[str, object])
oracle_tables (dict[str, tuple[BaseModel, ...]])
quality_raw_faults (tuple[dict[str, object], ...])
schema_evolution_rows (dict[str, tuple[dict[str, object], ...]])
counterfactual (CounterfactualDataset | None)
campaign_dynamics (DynamicCampaignDataset | None)
- property card_lifecycle_event_counts: dict[str, int]
Return counts for the explicit card event vocabulary.
- property event_counts: dict[str, int]
Return payment, lifecycle, ledger, and fraud counts for the manifest.
- property fraud_counts: dict[str, int]
Return manifest fraud counters, or empty counters when disabled.
- property fraud_events: tuple[PaymentEvent, ...]
Return scenario-linked payment events, excluding hard negatives.
- property fraud_rates: dict[str, float]
Return realized true-record rates by scenario.
- property fraud_record_counts: dict[str, int]
Count true scenario records for manifest reporting.
- property pix_lifecycle_event_counts: dict[str, int]
Return counts for the explicit PIX event vocabulary.
- class fraudtwin.simulation.BehaviorGenerator(config, entities, simulation_run_id=None, calibration=None, stage_timings=None)[source][source]
Bases:
objectGenerate customer profiles and their payment stream from M1 entities.
- Parameters:
config (SimulationRunConfig)
entities (EntityDataset)
simulation_run_id (str | None)
calibration (ResolvedCalibration | None)
stage_timings (dict[str, dict[str, float]] | None)
- class fraudtwin.simulation.EntityDataset(customers, institutions, accounts, cards, merchants, devices, pix_keys, state_history=(), network_endpoints=())[source][source]
Bases:
objectStable, ordered collections of all generated entities.
- Parameters:
customers (tuple[Customer, ...])
institutions (tuple[Institution, ...])
accounts (tuple[Account, ...])
cards (tuple[Card, ...])
merchants (tuple[Merchant, ...])
devices (tuple[Device, ...])
pix_keys (tuple[PixKey, ...])
state_history (tuple[EntityStateChange, ...])
network_endpoints (tuple[NetworkEndpoint, ...])
- property all_ids: frozenset[str]
Return every string identifier carried by the entity collections.
- all_tables()[source][source]
Return base entity tables plus optional effective-dated history.
- Return type:
dict[str,tuple[Account|Card|Customer|Device|EntityStateChange|Institution|Merchant|PixKey|NetworkEndpoint,...]]
- property counts: dict[str, int]
Return output counts using the population configuration names.
- property reference_ids: dict[str, frozenset[str]]
Return the stable IDs used by relationship validators.
- class fraudtwin.simulation.EntityGenerator(config, calibration=None)[source][source]
Bases:
objectGenerate a reproducible population from a validated configuration.
- Parameters:
config (SimulationRunConfig)
calibration (ResolvedCalibration | None)
- class fraudtwin.simulation.FraudDataset(payments, payment_events, ledger_entries, fraud_records)[source][source]
Bases:
objectComplete payment stream plus explainable M6 truth records.
- Parameters:
payments (tuple[Payment, ...])
payment_events (tuple[PaymentEvent, ...])
ledger_entries (tuple[LedgerEntry, ...])
fraud_records (tuple[FraudRecord, ...])
- class fraudtwin.simulation.FraudScenarioGenerator(config, accounts, cards, merchants, devices, pix_keys, baseline, simulation_run_id=None)[source][source]
Bases:
objectAdd only explicit F01-F05 campaigns to an existing legitimate stream.
- Parameters:
config (SimulationRunConfig)
accounts (tuple[Account, ...])
cards (tuple[Card, ...])
merchants (tuple[Merchant, ...])
devices (tuple[Device, ...])
pix_keys (tuple[PixKey, ...])
baseline (PaymentDataset)
simulation_run_id (str | None)
- class fraudtwin.simulation.FraudWorkflowDataset(alerts, cases, confirmations, disputes, labels)[source][source]
Bases:
objectStable M7 workflow records derived from M6 fraud records.
- Parameters:
alerts (tuple[FraudAlert, ...])
cases (tuple[FraudCase, ...])
confirmations (tuple[FraudCaseConfirmation, ...])
disputes (tuple[CustomerDispute, ...])
labels (tuple[DelayedFraudLabel, ...])
- class fraudtwin.simulation.FraudWorkflowGenerator(config, entities, fraud_dataset)[source][source]
Bases:
objectTurn scenario-linked M6 records into a delayed operational truth path.
- Parameters:
config (SimulationRunConfig)
entities (EntityDataset)
fraud_dataset (FraudDataset)
- class fraudtwin.simulation.PaymentDataset(payments, payment_events, ledger_entries=())[source][source]
Bases:
objectStable, ordered payment business objects and their event envelopes.
- Parameters:
payments (tuple[Payment, ...])
payment_events (tuple[PaymentEvent, ...])
ledger_entries (tuple[LedgerEntry, ...])
- class fraudtwin.simulation.PaymentGenerator(config, accounts, cards, merchants, devices, pix_keys=(), simulation_run_id=None, calibration=None, include_lifecycle=True, include_ledger=True)[source][source]
Bases:
objectGenerate positive, relationship-valid, legitimate payment events.
- Parameters:
config (SimulationRunConfig)
accounts (tuple[Account, ...])
cards (tuple[Card, ...])
merchants (tuple[Merchant, ...])
devices (tuple[Device, ...])
pix_keys (tuple[PixKey, ...])
simulation_run_id (str | None)
calibration (ResolvedCalibration | None)
include_lifecycle (bool)
include_ledger (bool)
- generate(profiles)[source][source]
Materialize the deterministic payment stream as an in-memory dataset.
- Return type:
PaymentDataset- Parameters:
profiles (tuple[BehaviorProfile, ...])
- fraudtwin.simulation.count_pix_lifecycle_events(events)[source][source]
Count the explicit PIX lifecycle event types.
- Return type:
dict[str,int]- Parameters:
events (Iterable[PaymentEvent])
- class fraudtwin.simulation.QualityFaultInjector(config)[source][source]
Bases:
objectApply independently configurable, reproducible M8 faults.
- Parameters:
config (SimulationRunConfig)
- fraudtwin.simulation.generate_behavior(config, entities)[source][source]
Convenience function for deterministic behavior generation.
- Return type:
BehaviorDataset- Parameters:
config (SimulationRunConfig)
entities (EntityDataset)
- fraudtwin.simulation.generate_entities(config)[source][source]
Convenience function for deterministic entity generation.
- Return type:
EntityDataset- Parameters:
config (SimulationRunConfig)
- class fraudtwin.simulation.GraphCampaignMembership(**data)[source][source]
Bases:
_EntityModelOracle membership for one generated graph-fraud campaign.
- Parameters:
campaign_id (str)
pattern_type (Literal['MULE_NETWORK', 'CYCLIC_RING', 'BENEFICIARY_NETWORK', 'SHARED_DEVICE_INFRASTRUCTURE', 'SHARED_IP_INFRASTRUCTURE', 'FAN_IN', 'FAN_OUT', 'SHORT_MONEY_DWELL', 'DENSE_CAMPAIGN', 'MERCHANT_CUSTOMER_COMMUNITY', 'BIPARTITE_NETWORK', 'STACKED_NETWORK', 'SCATTER_GATHER', 'GATHER_SCATTER', 'RANDOM_ALERT_CONTROL'])
member_id (str)
member_type (str)
role (str)
valid_from (datetime)
valid_to (datetime | None)
source_event_id (str | None)
payment_id (str | None)
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class fraudtwin.simulation.GraphCampaign(**data)[source][source]
Bases:
_EntityModelOracle descriptor for one deterministic scenario instance.
- Parameters:
campaign_id (str)
scenario_type (Literal['MULE_NETWORK', 'CYCLIC_RING', 'BENEFICIARY_NETWORK', 'SHARED_DEVICE_INFRASTRUCTURE', 'SHARED_IP_INFRASTRUCTURE', 'FAN_IN', 'FAN_OUT', 'SHORT_MONEY_DWELL', 'DENSE_CAMPAIGN', 'MERCHANT_CUSTOMER_COMMUNITY', 'BIPARTITE_NETWORK', 'STACKED_NETWORK', 'SCATTER_GATHER', 'GATHER_SCATTER', 'RANDOM_ALERT_CONTROL'])
scenario_code (str)
truth_label (Literal['FRAUD', 'CONTROL'])
valid_from (datetime)
valid_to (datetime)
participant_ids (tuple[str, ...])
modifiers (tuple[str, ...])
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class fraudtwin.simulation.GraphPattern(**data)[source][source]
Bases:
_EntityModelA deterministic structural pattern descriptor.
- Parameters:
pattern_id (str)
pattern_type (Literal['MULE_NETWORK', 'CYCLIC_RING', 'BENEFICIARY_NETWORK', 'SHARED_DEVICE_INFRASTRUCTURE', 'SHARED_IP_INFRASTRUCTURE', 'FAN_IN', 'FAN_OUT', 'SHORT_MONEY_DWELL', 'DENSE_CAMPAIGN', 'MERCHANT_CUSTOMER_COMMUNITY', 'BIPARTITE_NETWORK', 'STACKED_NETWORK', 'SCATTER_GATHER', 'GATHER_SCATTER', 'RANDOM_ALERT_CONTROL'])
campaign_id (str | None)
detected_at (datetime)
window_from (datetime)
window_to (datetime)
member_ids (tuple[str, ...])
source_event_ids (tuple[str, ...])
payment_ids (tuple[str, ...])
threshold (Annotated[int | None, Ge(ge=1)])
observed_value (float | None)
invariant_status (Literal['PASS', 'UNAVAILABLE', 'FAIL'])
truth_label (Literal['FRAUD', 'CONTROL'])
scenario_code (str | None)
reason (str | None)
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class fraudtwin.simulation.GraphEvidence(**data)[source][source]
Bases:
_EntityModelNormalized lineage for a derived relationship.
- Parameters:
evidence_id (str)
edge_id (str | None)
evidence_type (str)
resource_id (str | None)
source_event_id (str | None)
payment_id (str | None)
observed_at (datetime)
available_at (datetime | None)
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class fraudtwin.simulation.GraphHyperedge(**data)[source][source]
Bases:
_EntityModelOptional higher-order campaign incidence record.
- Parameters:
hyperedge_id (str)
hyperedge_type (Literal['STRUCTURAL', 'SEMANTIC'])
campaign_id (str | None)
pattern_id (str | None)
valid_from (datetime)
valid_to (datetime | None)
source_event_ids (tuple[str, ...])
payment_ids (tuple[str, ...])
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class fraudtwin.simulation.GraphHyperedgeMembership(**data)[source][source]
Bases:
_EntityModelMembership of an entity in a higher-order graph relationship.
- Parameters:
hyperedge_id (str)
member_id (str)
member_type (str)
role (str | None)
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class fraudtwin.simulation.NetworkEndpoint(**data)[source][source]
Bases:
_EntityModelAn opt-in synthetic network endpoint; absent from legacy runs.
- Parameters:
endpoint_id (str)
endpoint_type (Literal['IP', 'NETWORK'])
address_hash (str)
first_seen_at (datetime)
last_seen_at (datetime)
valid_from (datetime)
valid_to (datetime | None)
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class fraudtwin.simulation.GraphFraudDataset(payments, payment_events, ledger_entries, fraud_records, memberships, patterns, campaigns=(), evidence=(), hyperedges=(), hyperedge_memberships=(), dynamic=None)[source][source]
Bases:
object- Parameters:
payments (tuple[Payment, ...])
payment_events (tuple[PaymentEvent, ...])
ledger_entries (tuple[LedgerEntry, ...])
fraud_records (tuple[FraudRecord, ...])
memberships (tuple[GraphCampaignMembership, ...])
patterns (tuple[GraphPattern, ...])
campaigns (tuple[GraphCampaign, ...])
evidence (tuple[GraphEvidence, ...])
hyperedges (tuple[GraphHyperedge, ...])
hyperedge_memberships (tuple[GraphHyperedgeMembership, ...])
dynamic (DynamicCampaignDataset | None)
- class fraudtwin.simulation.GraphFraudGenerator(config, accounts, devices, endpoints, baseline, simulation_run_id=None, merchants=(), pix_keys=())[source][source]
Bases:
objectGenerate graph scenarios using canonical participant allocation.
- Parameters:
config (SimulationRunConfig)
accounts (tuple[Account, ...])
devices (tuple[Device, ...])
endpoints (tuple[NetworkEndpoint, ...])
baseline (PaymentDataset | FraudDataset)
simulation_run_id (str | None)
merchants (tuple[Merchant, ...])
pix_keys (tuple[PixKey, ...])
- class fraudtwin.simulation.ResolvedDifficulty(**data)[source][source]
Bases:
BaseModelComplete, hashable M12 difficulty configuration.
- Parameters:
enabled (bool)
resolver_version (str)
requested_difficulty (int | None)
requested_controls (dict[str, float | None])
resolved_controls (dict[str, float])
scenario_transformations (dict[str, dict[str, object]])
effective_configuration_hash (str)
- property level: int | None
Return the requested level for convenient API consumers.
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class fraudtwin.simulation.ScenarioDifficultyPlan(**data)[source][source]
Bases:
BaseModelResolved transformations for one fraud or graph scenario.
- Parameters:
scenario (str)
amount_similarity (float)
behavior_similarity (float)
merchant_similarity (float)
device_similarity (float)
channel_similarity (float)
geography_similarity (float)
scenario_subtlety (float)
noise_hard_negatives (float)
prevalence (float)
temporal_irregularity (float)
graph_structural_subtlety (float)
amount_multiplier (float)
timing_multiplier (float)
hard_negative_multiplier (float)
parameter_transformations (dict[str, object])
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- fraudtwin.simulation.resolve_difficulty(config)[source][source]
Resolve a level and its optional per-dimension replacements.
- Return type:
- Parameters:
config (SimulationRunConfig)
- fraudtwin.simulation.apply_difficulty(resolved, scenario, context=None)[source][source]
Apply resolved controls to one scenario without changing its objective.
contextis accepted for extension compatibility and is intentionally excluded from the plan hash; all stochastic choices use generator-owned M12 stream names.- Return type:
- Parameters:
resolved (ResolvedDifficulty)
scenario (str)
context (dict[str, Any] | None)