pub struct MonteCarloResampling {
pub number_of_iterations: i64,
pub train_size: f64,
pub random_seed: i64,
pub scheme_name: String,
pub description: String,
}Expand description
Repeated random train-validation splits.
Fields§
§number_of_iterations: i64Number of iterations.
train_size: f64Training fraction.
random_seed: i64Random seed.
scheme_name: StringUnique name identifying a resampling scheme.
description: StringFree-text description.
Implementations§
Source§impl MonteCarloResampling
impl MonteCarloResampling
Sourcepub fn estimate(
&self,
n_sims: usize,
rng: &mut SplitMix64,
sim: impl FnMut(&mut SplitMix64) -> f64,
) -> Result<MonteCarloEstimate>
pub fn estimate( &self, n_sims: usize, rng: &mut SplitMix64, sim: impl FnMut(&mut SplitMix64) -> f64, ) -> Result<MonteCarloEstimate>
Estimates E[f] by simulation, attaching the numeric to the
scheme type.
This is the framework’s inherent-impl entry point: it delegates verbatim to
the free monte_carlo_estimate using the explicit n_sims, generator,
and simulation closure. The scheme’s configured fields (its
number_of_iterations / random_seed) are intentionally not consulted —
the explicit arguments take precedence so a caller keeps full control of
the run.
§Arguments
n_sims— number of simulation replicates; must be>= 2.rng— the deterministic generator threaded through every replicate.sim— the simulation closure returning one realised value off.
§Returns
A MonteCarloEstimate holding the mean, its standard error, and n_sims.
§Errors
Returns Error::InsufficientData when n_sims < 2.
§Examples
use stats_claw::resampling::MonteCarloResampling;
use stats_claw::rng::SplitMix64;
let scheme = MonteCarloResampling::default();
let est = scheme.estimate(10_000, &mut SplitMix64::new(5), |r| r.next_f64())?;
assert!((est.mean() - 0.5).abs() < 4.0 * est.std_error(), "mean was {}", est.mean());Sourcepub fn run(
&self,
sim: impl FnMut(&mut SplitMix64) -> f64,
) -> Result<MonteCarloEstimate>
pub fn run( &self, sim: impl FnMut(&mut SplitMix64) -> f64, ) -> Result<MonteCarloEstimate>
Runs a Monte-Carlo estimate using this scheme’s own configuration.
Reads the replicate count from
number_of_iterations and seeds the
deterministic PRNG from random_seed, then delegates
to monte_carlo_estimate. The i64 seed is reinterpreted to u64
bit-for-bit via i64::cast_unsigned (not a numeric as cast, which the
style.rs guard bans), so a positive seed maps to the same magnitude —
mirroring CrossValidation::run.
Unlike estimate — which takes an explicit count and
generator and ignores these fields — run consumes the scheme’s
configured fields, so the parameter struct is itself executable against the
numerics.
§Arguments
sim— the simulation closure; each call may advance the seeded generator and returns one realised value off.
§Returns
A MonteCarloEstimate holding the mean, its standard error, and the
configured iteration count.
§Errors
Error::InvalidInputwhennumber_of_iterationsis non-positive or unrepresentable as ausizecount.Error::InsufficientDatawhen the configured count is below two (theddof = 1standard error is then undefined), propagated frommonte_carlo_estimate.
§Examples
use stats_claw::resampling::MonteCarloResampling;
let scheme = MonteCarloResampling {
number_of_iterations: 10_000,
random_seed: 5,
..Default::default()
};
// Estimating E[U] for U ~ Uniform[0, 1): the true mean is 0.5.
let est = scheme.run(|r| r.next_f64())?;
assert!((est.mean() - 0.5).abs() < 4.0 * est.std_error(), "mean was {}", est.mean());Trait Implementations§
Source§impl Clone for MonteCarloResampling
impl Clone for MonteCarloResampling
Source§fn clone(&self) -> MonteCarloResampling
fn clone(&self) -> MonteCarloResampling
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more