DistributionMethods

Trait DistributionMethods 

Source
pub trait DistributionMethods: Distribution {
    // Required methods
    fn mean(&self) -> Array1<f64>;
    fn variance(&self) -> Array1<f64>;
    fn pdf(&self, y: &Array1<f64>) -> Array1<f64>;
    fn cdf(&self, y: &Array1<f64>) -> Array1<f64>;
    fn ppf(&self, q: &Array1<f64>) -> Array1<f64>;
    fn sample(&self, n_samples: usize) -> Array2<f64>;

    // Provided methods
    fn std(&self) -> Array1<f64> { ... }
    fn logpdf(&self, y: &Array1<f64>) -> Array1<f64> { ... }
    fn interval(&self, alpha: f64) -> (Array1<f64>, Array1<f64>) { ... }
    fn sf(&self, y: &Array1<f64>) -> Array1<f64> { ... }
    fn median(&self) -> Array1<f64> { ... }
    fn mode(&self) -> Array1<f64> { ... }
}
Expand description

A trait providing common distribution helper methods.

This trait provides scipy-like methods for distributions:

  • mean(), std(), var() - moments
  • pdf(), logpdf() - probability density functions
  • cdf() - cumulative distribution function
  • ppf() - percent point function (inverse CDF / quantile function)
  • sample() - random sampling
  • interval() - confidence intervals

Required Methods§

Source

fn mean(&self) -> Array1<f64>

Returns the mean of the distribution for each observation.

Source

fn variance(&self) -> Array1<f64>

Returns the variance of the distribution for each observation.

Source

fn pdf(&self, y: &Array1<f64>) -> Array1<f64>

Evaluates the probability density function at point y for each observation.

Source

fn cdf(&self, y: &Array1<f64>) -> Array1<f64>

Evaluates the cumulative distribution function at point y for each observation.

Source

fn ppf(&self, q: &Array1<f64>) -> Array1<f64>

Evaluates the percent point function (inverse CDF / quantile function). Returns the value y such that P(Y <= y) = q.

Source

fn sample(&self, n_samples: usize) -> Array2<f64>

Generates random samples from the distribution.

§Arguments
  • n_samples - Number of samples to generate per observation
§Returns

Array of shape (n_samples, n_observations)

Provided Methods§

Source

fn std(&self) -> Array1<f64>

Returns the standard deviation of the distribution for each observation.

Source

fn logpdf(&self, y: &Array1<f64>) -> Array1<f64>

Evaluates the log probability density function at point y for each observation.

Source

fn interval(&self, alpha: f64) -> (Array1<f64>, Array1<f64>)

Returns the confidence interval for each observation.

§Arguments
  • alpha - Significance level (e.g., 0.05 for 95% CI)
§Returns

Tuple of (lower bounds, upper bounds)

Source

fn sf(&self, y: &Array1<f64>) -> Array1<f64>

Returns the survival function (1 - CDF) at point y for each observation.

Source

fn median(&self) -> Array1<f64>

Returns the median of the distribution for each observation.

Source

fn mode(&self) -> Array1<f64>

Returns the mode of the distribution for each observation (if well-defined). Default implementation returns the mean; override for distributions where mode != mean.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§