Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed
- Preserve continuous Gamma samples instead of truncating them to integers. (@jackiectl2)

## [0.2.9](https://github.com/avhz/RustQuant/compare/v0.2.8...v0.2.9) - 2024-10-27

### Added
Expand Down
11 changes: 10 additions & 1 deletion crates/RustQuant_math/src/distributions/gamma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl Distribution for Gamma {
let mut variates: Vec<f64> = Vec::with_capacity(n);

for _ in 0..variates.capacity() {
variates.push(dist.sample(&mut rng) as usize as f64);
variates.push(dist.sample(&mut rng));
}

Ok(variates)
Expand All @@ -220,6 +220,15 @@ mod tests {
use super::*;
use RustQuant_utils::{assert_approx_equal, RUSTQUANT_EPSILON as EPS};

#[test]
fn test_gamma_samples_retain_fractional_values() {
let samples = Gamma::new(2.0, 3.0).sample(64).unwrap();

assert_eq!(samples.len(), 64);
assert!(samples.iter().all(|x| x.is_finite() && *x > 0.0));
assert!(samples.iter().any(|x| x.fract() != 0.0));
}

#[test]
fn test_gamma_characteristic_function() {
let dist: Gamma = Gamma::new(1.0, 1.0);
Expand Down