(
moments: Vec<f64>,
epsilon: f64,
factor: f64,
n_runs: usize,
variant: usize,
max_iter: usize,
num_workers: isize,
)
| 45 | //! assert!(step.iter().zip(&truth).all(|(a, b)| (a - b).abs() < 1e-9)); |
| 46 | //! } |
| 47 | //! ``` |
| 48 | |
| 49 | use crate::util::stats; |
| 50 | use crate::util::InputError; |
| 51 | use rand::RngExt; |
| 52 | use std::collections::{BTreeMap, HashSet}; |
| 53 | |
| 54 | /// An EF3M fitter for a mixture of two Gaussians: the target moments, the search settings, |
| 55 | /// and the best fit found so far. |
| 56 | /// |
| 57 | /// Build it with [`M2N::new`] or [`M2N::with_defaults`] and run [`M2N::mp_fit`] or |
| 58 | /// [`M2N::single_fit_loop`]. Parameter vectors are `[mu_1, mu_2, sigma_1, sigma_2, p_1]`. |
| 59 | #[derive(Debug, Clone)] |
| 60 | pub struct M2N { |
| 61 | /// Target raw moments `E[x^k]`, `k = 1..=5`. The fit needs all five. |
| 62 | pub moments: Vec<f64>, |
| 63 | /// Convergence tolerance on `p_1`; also the spacing of the `mu_2` start grid, which has |
| 64 | /// about `1 / epsilon` points. Must be finite and `> 0` ([`M2N::single_fit_loop`] checks). |
| 65 | pub epsilon: f64, |
| 66 | /// Width of the `mu_2` start grid in standard deviations: starts run from |
| 67 | /// `m_1 + epsilon * factor * sigma` to about `m_1 + factor * sigma`. |
| 68 | pub factor: f64, |
| 69 | /// Number of independent searches [`M2N::mp_fit`] runs. |
| 70 | pub n_runs: usize, |
| 71 | /// `1` to fit four moments ([`M2N::iter_4`]) or `2` to fit five ([`M2N::iter_5`]). |
| 72 | pub variant: usize, |
nothing calls this directly
no outgoing calls
no test coverage detected