Skip to content

Commit a0cdfea

Browse files
authored
Merge pull request #15 from SyntaxSpirits/docs/discrete-distribution-readme
docs: document discrete distribution examples
2 parents e775746 + e5b7ae7 commit a0cdfea

1 file changed

Lines changed: 31 additions & 1 deletion

File tree

README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ A comprehensive Rust library for Bayesian inference with MCMC samplers, featurin
99
## Features
1010

1111
- **MCMC Samplers**: Metropolis-Hastings, Gibbs, and Hamiltonian Monte Carlo (HMC)
12-
- **Statistical Distributions**: Normal, Multivariate Normal, Gamma, Beta, Exponential, Uniform, Student's t
12+
- **Statistical Distributions**: Normal, Multivariate Normal, Gamma, Beta, Exponential, Uniform, Student's t, Bernoulli, Binomial, Poisson
1313
- **MCMC Diagnostics**: Effective sample size, R-hat statistic, MCSE summaries, autocorrelation analysis, trace plots
1414
- **Multi-chain workflows**: Run multiple seeded chains with a shared warmup/sample schedule
1515
- **Best Practices**: Comprehensive error handling, extensive testing, performance benchmarks
@@ -180,6 +180,27 @@ let x = DVector::from_vec(vec![1.0, -1.0]);
180180
println!("Log PDF: {}", mvn.log_pdf(&x));
181181
```
182182

183+
### Discrete Distributions
184+
185+
Use `DiscreteDistribution` for count-valued distributions with probability mass functions and seeded sampling. `Poisson::new(lambda)` requires `lambda` to be finite, positive, and no greater than `1e12`. Add `rand = "0.8"` to your application dependencies when using the seeded sampling example.
186+
187+
```rust
188+
use bayes_rs::distributions::{Bernoulli, Binomial, DiscreteDistribution, Poisson};
189+
use rand::{rngs::StdRng, SeedableRng};
190+
191+
let bernoulli = Bernoulli::new(0.3)?;
192+
let binomial = Binomial::new(10, 0.3)?;
193+
let poisson = Poisson::new(2.5)?;
194+
195+
println!("Bernoulli P(X=1): {}", bernoulli.pmf(1));
196+
println!("Binomial log P(X=3): {}", binomial.log_pmf(3));
197+
println!("Poisson P(X=2): {}", poisson.pmf(2));
198+
199+
let mut rng = StdRng::seed_from_u64(42);
200+
let draw = poisson.sample(&mut rng);
201+
println!("Seeded Poisson draw: {}", draw);
202+
```
203+
183204
## MCMC Diagnostics
184205

185206
Comprehensive diagnostic tools to assess convergence and sample quality:
@@ -356,6 +377,15 @@ See the `examples/` directory for complete examples:
356377
```bash
357378
# Bayesian linear regression example
358379
cargo run --example linear_regression
380+
381+
# Discrete Bernoulli, Binomial, and Poisson distributions
382+
cargo run --example discrete_distributions
383+
384+
# Conjugate Bayesian model examples
385+
cargo run --example conjugate_models
386+
387+
# Serde-enabled diagnostics serialization example
388+
cargo run --features serde --example serde_diagnostics
359389
```
360390

361391
## Contributing

0 commit comments

Comments
 (0)