mod bernoulli;
mod beta;
mod binomial;
mod chi_squared;
mod discreteuniform;
mod exponential;
mod gamma;
mod gumbel;
mod multivariatenormal;
mod normal;
mod pareto;
mod poisson;
mod t;
mod uniform;
use crate::linalg::{Matrix, Vector};
pub trait Distribution: Send + Sync {
type Output;
fn sample(&self) -> Self::Output;
}
pub trait Distribution1D: Distribution<Output = f64> {
fn sample_n(&self, n: usize) -> Vector {
(0..n).map(|_| self.sample()).collect()
}
fn sample_matrix(&self, nrows: usize, ncols: usize) -> Matrix {
Matrix::new(self.sample_n(nrows * ncols), nrows as i32, ncols as i32)
}
fn update(&mut self, params: &[f64]);
}
pub trait DistributionND: Distribution<Output = Vector> {
fn get_dim(&self) -> usize;
fn sample_n(&self, n: usize) -> Matrix {
let mut data = Vector::with_capacity(n * self.get_dim());
for _ in 0..n {
data.extend(self.sample());
}
Matrix::new(data, n as i32, self.get_dim() as i32)
}
}
pub trait Mean {
type MeanType;
fn mean(&self) -> Self::MeanType;
}
pub trait Variance {
type VarianceType;
fn var(&self) -> Self::VarianceType;
}
pub trait Continuous {
type PDFType;
fn pdf(&self, x: Self::PDFType) -> f64;
fn ln_pdf(&self, x: Self::PDFType) -> f64 {
self.pdf(x).ln()
}
}
pub trait Discrete: Distribution1D {
fn pmf(&self, x: i64) -> f64;
}
pub use self::bernoulli::Bernoulli;
pub use self::beta::Beta;
pub use self::binomial::Binomial;
pub use self::chi_squared::ChiSquared;
pub use self::discreteuniform::DiscreteUniform;
pub use self::exponential::Exponential;
pub use self::gamma::Gamma;
pub use self::gumbel::Gumbel;
pub use self::multivariatenormal::*;
pub use self::normal::Normal;
pub use self::pareto::Pareto;
pub use self::poisson::Poisson;
pub use self::t::*;
pub use self::uniform::Uniform;