Skip to main content

MonteCarloResampling

Struct MonteCarloResampling 

Source
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: i64

Number of iterations.

§train_size: f64

Training fraction.

§random_seed: i64

Random seed.

§scheme_name: String

Unique name identifying a resampling scheme.

§description: String

Free-text description.

Implementations§

Source§

impl MonteCarloResampling

Source

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 of f.
§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());
Source

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 of f.
§Returns

A MonteCarloEstimate holding the mean, its standard error, and the configured iteration count.

§Errors
§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

Source§

fn clone(&self) -> MonteCarloResampling

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MonteCarloResampling

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MonteCarloResampling

Source§

fn default() -> MonteCarloResampling

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.