pub struct MultivariateDensity<T, D>(/* private fields */)
where
T: Scalar,
D: Dim,
DefaultAllocator: Allocator<D>;Expand description
A D-dimensional distribution where each dimension is
independent with potentially different univariate distributions. This is a product distribution:
- Each marginal follows one of the available univariate distributions (Normal, Uniform, Cosine, etc.)
- The joint density is the product of marginals: f(x₁, …, xₐ) = f₁(x₁) × … × fₐ(xₐ)
§Construction & Examples
Create a mixed 3D distribution (Normal × Uniform × Constant):
let marginals = SVector::from([
NormalDensity::new(0.0, 1.0, None, None).unwrap().into(),
UniformDensity::new(-1.0, 1.0).unwrap().into(),
ConstantDensity::new(2.0).into(),
]);
let _dist = MultivariateDensity::<f64, Const<3>>::new(marginals);Create a 5D distribution with mixed univariates:
let mvpdf = MultivariateDensity::<f64, Const<5>>::new(SVector::from([
ConstantDensity::new(1.0).into(),
CosineDensity::new(0.1, 0.2).unwrap().into(),
LogUniformDensity::new(0.1, 0.5).unwrap().into(),
NormalDensity::new(0.1, 0.25, Some(-0.5), Some(1.5)).unwrap().into(),
UniformDensity::new(1.0, 2.0).unwrap().into(),
]));Evaluate density at a point:
let marginals = SVector::from([
NormalDensity::new(0.0, 1.0, None, None).unwrap().into(),
UniformDensity::new(-1.0, 1.0).unwrap().into(),
]);
let dist = MultivariateDensity::<f64, U2>::new(marginals);
let sample = SVector::from([0.0, 0.5]);
// Use the Density trait to evaluate - see crate::Density for usage patterns
if let Some(dens) = (&dist).density::<U1, U2>(&sample.as_view()) {
println!("Joint density: {}", dens);
}Sample from the distribution:
let marginals = SVector::from([
NormalDensity::new(0.0, 1.0, None, None).unwrap().into(),
UniformDensity::new(-1.0, 1.0).unwrap().into(),
]);
let dist = MultivariateDensity::<f64, U2>::new(marginals);
let mut rng = StdRng::seed_from_u64(42);
if let Some(sample) = (&dist).sample(&mut rng, &SamplingMode::default()) {
println!("Generated sample: {:?}", sample);
}Implementations§
Source§impl<T, D> MultivariateDensity<T, D>
impl<T, D> MultivariateDensity<T, D>
Sourcepub fn new(domains: OVector<UnivariateDensity<T>, D>) -> Self
pub fn new(domains: OVector<UnivariateDensity<T>, D>) -> Self
Create a new MultivariateDensity from a vector of UnivariateDensitys.
Sourcepub fn marginals(&self) -> &OVector<UnivariateDensity<T>, D>
pub fn marginals(&self) -> &OVector<UnivariateDensity<T>, D>
Return a reference to the underlying vector of UnivariateDensitys.
Trait Implementations§
Source§impl<T, D> Clone for MultivariateDensity<T, D>
impl<T, D> Clone for MultivariateDensity<T, D>
Source§fn clone(&self) -> MultivariateDensity<T, D>
fn clone(&self) -> MultivariateDensity<T, D>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T, D> Debug for MultivariateDensity<T, D>
impl<T, D> Debug for MultivariateDensity<T, D>
Source§impl<T, D> Density<T, D> for MultivariateDensity<T, D>where
T: RealField + SampleUniform,
D: Dim,
StandardNormal: Distribution<T>,
DefaultAllocator: Allocator<D>,
impl<T, D> Density<T, D> for MultivariateDensity<T, D>where
T: RealField + SampleUniform,
D: Dim,
StandardNormal: Distribution<T>,
DefaultAllocator: Allocator<D>,
Source§fn density<RStride: Dim, CStride: Dim>(
&self,
sample: &VectorView<'_, T, D, RStride, CStride>,
) -> Option<T>
fn density<RStride: Dim, CStride: Dim>( &self, sample: &VectorView<'_, T, D, RStride, CStride>, ) -> Option<T>
Source§fn sample(
&self,
rng: &mut impl RngExt,
mode: &SamplingMode,
) -> Option<OVector<T, D>>
fn sample( &self, rng: &mut impl RngExt, mode: &SamplingMode, ) -> Option<OVector<T, D>>
Draw a random sample from the probability density distribution using the provided random number generator and sampling mode. Read more
Source§impl<'de, T, D> Deserialize<'de> for MultivariateDensity<T, D>where
T: Scalar,
D: Dim,
DefaultAllocator: Allocator<D>,
OVector<UnivariateDensity<T>, D>: Deserialize<'de>,
impl<'de, T, D> Deserialize<'de> for MultivariateDensity<T, D>where
T: Scalar,
D: Dim,
DefaultAllocator: Allocator<D>,
OVector<UnivariateDensity<T>, D>: Deserialize<'de>,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<T> From<MultivariateDensity<T, Const<1>>> for UnivariateDensity<T>where
T: RealField,
impl<T> From<MultivariateDensity<T, Const<1>>> for UnivariateDensity<T>where
T: RealField,
Source§fn from(mv: MultivariateDensity<T, U1>) -> Self
fn from(mv: MultivariateDensity<T, U1>) -> Self
Convert a 1D MultivariateDensity to a UnivariateDensity by extracting its single marginal.
Source§impl From<MultivariateDensity<f64, Dyn>> for PyMultivariate
impl From<MultivariateDensity<f64, Dyn>> for PyMultivariate
Source§fn from(dist: MultivariateDensity<f64, Dyn>) -> Self
fn from(dist: MultivariateDensity<f64, Dyn>) -> Self
Convert a MultivariateDensity with runtime dimensions to a PyMultivariate.
Source§impl<'__deriveMoreLifetime, T, D> IntoIterator for &'__deriveMoreLifetime MultivariateDensity<T, D>where
&'__deriveMoreLifetime OVector<UnivariateDensity<T>, D>: IntoIterator,
T: Scalar,
D: Dim,
DefaultAllocator: Allocator<D>,
impl<'__deriveMoreLifetime, T, D> IntoIterator for &'__deriveMoreLifetime MultivariateDensity<T, D>where
&'__deriveMoreLifetime OVector<UnivariateDensity<T>, D>: IntoIterator,
T: Scalar,
D: Dim,
DefaultAllocator: Allocator<D>,
Source§type Item = <&'__deriveMoreLifetime Matrix<UnivariateDensity<T>, D, Const<1>, <DefaultAllocator as Allocator<D>>::Buffer<UnivariateDensity<T>>> as IntoIterator>::Item
type Item = <&'__deriveMoreLifetime Matrix<UnivariateDensity<T>, D, Const<1>, <DefaultAllocator as Allocator<D>>::Buffer<UnivariateDensity<T>>> as IntoIterator>::Item
The type of the elements being iterated over.
Source§type IntoIter = <&'__deriveMoreLifetime Matrix<UnivariateDensity<T>, D, Const<1>, <DefaultAllocator as Allocator<D>>::Buffer<UnivariateDensity<T>>> as IntoIterator>::IntoIter
type IntoIter = <&'__deriveMoreLifetime Matrix<UnivariateDensity<T>, D, Const<1>, <DefaultAllocator as Allocator<D>>::Buffer<UnivariateDensity<T>>> as IntoIterator>::IntoIter
Which kind of iterator are we turning this into?
Source§impl<T, D> IntoIterator for MultivariateDensity<T, D>where
OVector<UnivariateDensity<T>, D>: IntoIterator,
T: Scalar,
D: Dim,
DefaultAllocator: Allocator<D>,
impl<T, D> IntoIterator for MultivariateDensity<T, D>where
OVector<UnivariateDensity<T>, D>: IntoIterator,
T: Scalar,
D: Dim,
DefaultAllocator: Allocator<D>,
Source§type Item = <Matrix<UnivariateDensity<T>, D, Const<1>, <DefaultAllocator as Allocator<D>>::Buffer<UnivariateDensity<T>>> as IntoIterator>::Item
type Item = <Matrix<UnivariateDensity<T>, D, Const<1>, <DefaultAllocator as Allocator<D>>::Buffer<UnivariateDensity<T>>> as IntoIterator>::Item
The type of the elements being iterated over.
Source§type IntoIter = <Matrix<UnivariateDensity<T>, D, Const<1>, <DefaultAllocator as Allocator<D>>::Buffer<UnivariateDensity<T>>> as IntoIterator>::IntoIter
type IntoIter = <Matrix<UnivariateDensity<T>, D, Const<1>, <DefaultAllocator as Allocator<D>>::Buffer<UnivariateDensity<T>>> as IntoIterator>::IntoIter
Which kind of iterator are we turning this into?
Source§impl<T, D> Serialize for MultivariateDensity<T, D>where
T: Scalar,
D: Dim,
DefaultAllocator: Allocator<D>,
OVector<UnivariateDensity<T>, D>: Serialize,
impl<T, D> Serialize for MultivariateDensity<T, D>where
T: Scalar,
D: Dim,
DefaultAllocator: Allocator<D>,
OVector<UnivariateDensity<T>, D>: Serialize,
Auto Trait Implementations§
impl<T, D> !Freeze for MultivariateDensity<T, D>
impl<T, D> !RefUnwindSafe for MultivariateDensity<T, D>
impl<T, D> !Send for MultivariateDensity<T, D>
impl<T, D> !Sync for MultivariateDensity<T, D>
impl<T, D> !Unpin for MultivariateDensity<T, D>
impl<T, D> !UnsafeUnpin for MultivariateDensity<T, D>
impl<T, D> !UnwindSafe for MultivariateDensity<T, D>
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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<'py, T, I> IntoPyDict<'py> for Iwhere
T: PyDictItem<'py>,
I: IntoIterator<Item = T>,
impl<'py, T, I> IntoPyDict<'py> for Iwhere
T: PyDictItem<'py>,
I: IntoIterator<Item = T>,
Source§impl<T> Pointable for T
impl<T> Pointable for T
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.