pub struct Beta { /* private fields */ }Expand description
A continuous distribution on the interval (0, 1), commonly used for modeling probabilities and proportions.
Conjugate prior for Bernoulli/Binomial distributions.
Mathematical Properties:
- Support: (0, 1); the closed endpoints 0 and 1 are handled as limits
- PDF: f(x) = (x^(α-1) × (1-x)^(β-1)) / B(α,β)
- Mean: α / (α + β)
- Variance: (αβ) / ((α+β)²(α+β+1))
Boundary semantics (matching scipy.stats.beta.logpdf): at x = 0,
log_prob is -∞ when α > 1 (density → 0), ln(β) when α == 1, and
+∞ when α < 1 (density diverges, e.g. the Jeffreys prior Beta(0.5, 0.5)).
The endpoint x = 1 is symmetric in β.
Example:
// Uniform on [0,1]
let uniform = sample(addr!("p"), Beta::new(1.0, 1.0).unwrap());
// Prior for success probability
let prob_prior = sample(addr!("success_rate"), Beta::new(2.0, 5.0).unwrap());
// Conjugate prior-likelihood pair
let model = sample(addr!("p"), Beta::new(3.0, 7.0).unwrap())
.bind(|p| observe(addr!("trial"), Bernoulli::new(p).unwrap(), true));
// Skewed towards 0 (beta > alpha)
let skewed = sample(addr!("proportion"), Beta::new(2.0, 8.0).unwrap());Implementations§
Source§impl Beta
impl Beta
Sourcepub fn new(alpha: f64, beta: f64) -> FugueResult<Self>
pub fn new(alpha: f64, beta: f64) -> FugueResult<Self>
Create a new Beta distribution with validated parameters.
Sourcepub fn uniform_prior() -> Self
pub fn uniform_prior() -> Self
Create the uniform-prior Beta distribution Beta(1, 1).
FG-29: infallible constructor for the statically-valid α = β = 1 case,
which is exactly the uniform distribution on (0, 1) and the standard
uninformative conjugate prior for a Bernoulli/Binomial probability;
avoids new(1.0, 1.0).unwrap().
let prior = Beta::uniform_prior();
assert_eq!(prior.alpha(), 1.0);
assert_eq!(prior.beta(), 1.0);Trait Implementations§
impl Copy for Beta
Source§impl Distribution<f64> for Beta
impl Distribution<f64> for Beta
Source§fn sample(&self, rng: &mut dyn RngCore) -> f64
fn sample(&self, rng: &mut dyn RngCore) -> f64
T, from the distribution, using the provided random number generator, rng. Read more