pub struct ProbabilityMeasure {
pub density: Box<dyn Fn(&[f64]) -> f64>,
pub domain: MeasurableSet,
pub n_samples: usize,
}Expand description
A probability measure on ℝⁿ with density function.
P(A) = ∫_A f(x) dx where ∫ f dx = 1 (normalization).
Supports numerical expectation and variance via Monte Carlo estimation.
Fields§
§density: Box<dyn Fn(&[f64]) -> f64>Probability density function f(x) ≥ 0.
domain: MeasurableSetDomain of the density (support box).
n_samples: usizeNumber of Monte Carlo samples for numerical computations.
Implementations§
Source§impl ProbabilityMeasure
impl ProbabilityMeasure
Sourcepub fn new(
density: impl Fn(&[f64]) -> f64 + 'static,
domain: MeasurableSet,
n_samples: usize,
) -> Self
pub fn new( density: impl Fn(&[f64]) -> f64 + 'static, domain: MeasurableSet, n_samples: usize, ) -> Self
Create a probability measure from a density and domain.
Sourcepub fn probability(&self, set: &MeasurableSet) -> f64
pub fn probability(&self, set: &MeasurableSet) -> f64
Estimate P(A) via Monte Carlo integration.
Samples uniformly from the domain and averages the density over A.
Sourcepub fn total_mass(&self) -> f64
pub fn total_mass(&self) -> f64
Estimate the total mass (should be ≈ 1 for a true probability measure).
Sourcepub fn expectation(&self, g: &dyn Fn(&[f64]) -> f64) -> f64
pub fn expectation(&self, g: &dyn Fn(&[f64]) -> f64) -> f64
Estimate the expectation E[g(X)] of a function g under this measure.
Auto Trait Implementations§
impl Freeze for ProbabilityMeasure
impl !RefUnwindSafe for ProbabilityMeasure
impl !Send for ProbabilityMeasure
impl !Sync for ProbabilityMeasure
impl Unpin for ProbabilityMeasure
impl UnsafeUnpin for ProbabilityMeasure
impl !UnwindSafe for ProbabilityMeasure
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.