pub trait Convolution<T: Distribution = Self> {
type Output: Distribution;
// Required method
fn convolve(self, rv: T) -> Result<Self::Output, Error>;
// Provided method
fn convolve_many(self, rvs: Vec<T>) -> Result<Self::Output, Error>
where Self::Output: Convolution<T, Output = Self::Output>,
Self: Sized { ... }
}Expand description
Trait for distributions that support the convolve operation.
The convolution of probability distributions amounts to taking linear combinations of independent random variables. For example, consider a set of \(N\) random variables \(X_i \sim \text{Bernoulli}(p)\), where \(p \in (0, 1)\) and \(1 \leq i \leq N\). We then have that the random variables \(Y = \sum_{i=1}^N X_i\) and \(Z \sim \text{Binomial}(N, p)\) are exactly equivalent, i.e. \(Y \stackrel{\text{d}}{=} Z\).
Required Associated Types§
Sourcetype Output: Distribution
type Output: Distribution
The resulting Distribution type.
Required Methods§
Sourcefn convolve(self, rv: T) -> Result<Self::Output, Error>
fn convolve(self, rv: T) -> Result<Self::Output, Error>
Return the unweighted linear sum of self with another
Distribution of type T.
§Examples
let dist_a = Normal::new_unchecked(0.0, 1.0f64.powi(2));
let dist_b = Normal::new_unchecked(1.0, 2.0f64.powi(2));
let dist_c = dist_a.convolve(dist_b).unwrap();
let params = dist_c.params();
assert_eq!(params.mu.value(), &1.0);
assert_eq!(params.Sigma.value(), &5.0f64);Provided Methods§
Sourcefn convolve_many(self, rvs: Vec<T>) -> Result<Self::Output, Error>
fn convolve_many(self, rvs: Vec<T>) -> Result<Self::Output, Error>
Return the unweighted linear sum of self with a set of
Distributions of type T.