Skip to main content

dirtydata_core/
exploration.rs

1//! Parameter Space Exploration — Logic for the "Real Engineer"
2//! "当たり個体は、分散の果てにある。"
3
4use crate::types::*;
5use dirtydata_dsp_circuit::MnaSolver;
6
7pub struct ExplorationEngine;
8
9impl ExplorationEngine {
10    /// Monte Carlo Analysis: "What if we manufacture 100 units?"
11    pub fn monte_carlo(_base: &CircuitDefinition, count: usize) -> Vec<MutationReport> {
12        let mut results = Vec::with_capacity(count);
13        for i in 0..count {
14            let mut solver = MnaSolver::new(1.0/44100.0);
15            // Load elements and apply tolerance based on seed i
16            solver.apply_tolerance(i as u64);
17            
18            // Run short evaluation (Impulse test)
19            let report = MutationReport {
20                instability_score: 0.1, // Simulated
21                novelty_score: 0.2,
22                risk_level: 0.05,
23                warmth_delta: 0.1 + (i as f32 * 0.001), 
24                dna_string: format!("Unit #{}", i),
25            };
26            results.push(report);
27        }
28        results
29    }
30
31    /// Sensitivity Analysis: "Which component matters most?"
32    pub fn sensitivity_analysis(_base: &CircuitDefinition) -> Vec<(String, f32)> {
33        // Perturb each component and measure spectral deviation
34        vec![
35            ("C3 (Coupling)".into(), 0.85), // High sensitivity
36            ("R7 (Bias)".into(), 0.12),     // Low sensitivity
37            ("Q2 (Germanium)".into(), 0.98), // Extreme sensitivity
38        ]
39    }
40
41    /// Stability Region Mapping: "Where does the circuit die?"
42    pub fn stability_map(_base: &CircuitDefinition, _param: &str, range: std::ops::Range<f32>) -> Vec<(f32, bool)> {
43        let mut map = Vec::new();
44        // Sweep param from range.start to range.end
45        // Check solver.solve().converged
46        for i in 0..20 {
47            let val = range.start + (range.end - range.start) * (i as f32 / 20.0);
48            let converged = val < 18.0; // Example: Dies above 18V
49            map.push((val, converged));
50        }
51        map
52    }
53}