docs.rs failed to build polya-gamma-0.5.2
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build:
polya-gamma-0.5.3
Polya-Gamma Sampler for Rust
A high-performance sampler for Polya-Gamma random variates.
Installation
Run cargo add polya-gamma or add this to your Cargo.toml:
[]
= "0.5.2"
Regression features require additional dependencies:
[]
= { = "0.5.2", = ["regression"] }
Quick Start
use PolyaGamma;
use ;
## Features
- **Exact Sampling**: Implements Devroye's algorithm for exact sampling from PG
- **Parallel Processing**: Optional Rayon support for generating multiple samples in parallel
- **Bayesian Regression Models**: Built-in Gibbs samplers for:
- Logistic Regression
- Negative Binomial Regression
- **Documentation**: Comprehensive API documentation with examples
## Usage Examples
### Basic Sampling
```rust
use PolyaGamma;
use thread_rng;
let mut pg = new;
let mut rng = thread_rng;
// Draw a single sample
let sample = pg.draw;
// Draw multiple samples
let samples = pg.draw_vec;
Bayesian Logistic Regression
use GibbsLogit;
use array; // Assuming ndarray is used for x and y
use SeedableRng;
// Example data (replace with actual data)
let x_data = array!;
let y_data = array!;
let prior_variance = 100.0;
let n_chains = 4;
let seed = 42;
// It's assumed x_data includes an intercept column if desired.
let model = new;
let results = model.run.unwrap; // 1000 burn-in, 5000 samples
// Process and print results (e.g., posterior means)
// The `results` struct (LogisticResults) contains `beta_posterior_mean` and `raw_samples`
println!;
// For Negative Binomial regression with GibbsNegativeBinomial, the usage pattern is similar.
Performance
The implementation is optimized for both single-threaded and parallel workloads. For large-scale sampling, the rayon feature provides significant speedups on multi-core systems.
Even in the single-threaded case, this crate has far better performance than BayesLogit:
- If $b < 1.0$, this crate is about 2.5x faster.
- If $b == 1.0$, this crate is about 1.3x faster.
- If $b > 1.0$, this crate can be up to 75x faster(!) If multithreaded operation is enabled, performance also scales with the number of cores available. See the benchmarks for details.
Documentation
Full API documentation is available on docs.rs.
References
- Polson, N.G., Scott, J.G., & Windle, J. (2013). Bayesian Inference for Logistic Models Using Polya-Gamma Latent Variables. Journal of the American Statistical Association, 108(504): 1339–1349.
- Windle, J., Polson, N.G., & Scott, J.G. (2014). Sampling Pólya-Gamma random variates: alternate and approximate techniques. arXiv:1405.0506.
License
This project is licensed under the terms of the MIT OR Apache-2.0 license. See the LICENSE-MIT and LICENSE-APACHE files for details.