https://github.com/dyedgreen/uncertain
Fast and correct computations with uncertain values
https://github.com/dyedgreen/uncertain
crates rust-crate trait uncertain-values
Last synced: 8 months ago
JSON representation
Fast and correct computations with uncertain values
- Host: GitHub
- URL: https://github.com/dyedgreen/uncertain
- Owner: dyedgreen
- License: mit
- Created: 2021-02-21T19:57:17.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2025-06-08T20:29:16.000Z (about 1 year ago)
- Last Synced: 2025-08-07T11:16:04.998Z (10 months ago)
- Topics: crates, rust-crate, trait, uncertain-values
- Language: Rust
- Homepage: https://crates.io/crates/uncertain
- Size: 48.8 KB
- Stars: 95
- Watchers: 2
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `Uncertain`
[](https://crates.io/crates/uncertain)
[](https://docs.rs/uncertain)
[](https://github.com/dyedgreen/uncertain/actions/workflows/ci.yml)
[](./LICENSE)
Fast and correct computations with uncertain values.
When working with values which are not exactly determined, such as sensor data, it
can be difficult to handle uncertainties correctly.
The `Uncertain` trait makes such computations as natural as regular computations:
```rust
use uncertain::{Uncertain, Distribution};
use rand_distr::Normal;
// Some inputs about which we are not sure
let x = Distribution::from(Normal::new(5.0, 2.0).unwrap());
let y = Distribution::from(Normal::new(7.0, 3.0).unwrap());
// Do some computations
let distance = x.sub(y).map(|diff: f64| diff.abs());
// Ask a question about the result
let is_it_far = distance.map(|dist| dist > 2.0);
// Check how certain the answer is
assert_eq!(is_it_far.pr(0.9), false);
assert_eq!(is_it_far.pr(0.5), true);
```
This works by sampling a Bayesian network which is implicitly created by describing the computation
on the uncertain type. The `Uncertain` trait only permits tests for simple boolean hypotheses. This
is by design: using Wald's [sequential probability ratio test][sprt], evaluation typically
takes less than `100` samples.
## Stability
While this crate is released as version `0.x`, breaking API changes should be expected.
## References
The `Uncertain` trait exported from the library is an implementation of
the paper [`Uncertain`][paper].
[paper]: https://www.cs.utexas.edu/users/mckinley/papers/uncertainty-asplos-2014.pdf
[sprt]: https://en.wikipedia.org/wiki/Sequential_probability_ratio_test