https://github.com/minikin/uncertain-rs

A Rust library for uncertainty-aware programming, implementing the approach from "Uncertain<T>: A First-Order Type for Uncertain Data" by Bornholt, Mytkowicz, and McKinley.

https://github.com/minikin/uncertain-rs

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (10.7%) to scientific vocabulary

Keywords

rust uncertainty
Last synced: 6 months ago · JSON representation

Repository

A Rust library for uncertainty-aware programming, implementing the approach from "Uncertain<T>: A First-Order Type for Uncertain Data" by Bornholt, Mytkowicz, and McKinley.

Basic Info
Statistics
  • Stars: 2
  • Watchers: 0
  • Forks: 1
  • Open Issues: 0
  • Releases: 0
Topics
rust uncertainty
Created 8 months ago · Last pushed 6 months ago
Metadata Files
Readme License Code of conduct Security

README.md

uncertain-rs

CI codecov License: MIT

A Rust library for uncertainty-aware programming, implementing the approach from "Uncertain: A First-Order Type for Uncertain Data" by Bornholt, Mytkowicz, and McKinley.

Core Concept: Evidence-Based Conditionals

Instead of treating uncertain data as exact values (which leads to bugs), this library uses evidence-based conditionals that account for uncertainty:

```rust use uncertain_rs::Uncertain;

// Create uncertain values from probability distributions let speed = Uncertain::normal(55.2, 5.0); // GPS reading with ±5 mph error

// Evidence-based conditional (returns Uncertain) let speeding_evidence = speed.gt(60.0);

// Convert evidence to decision with confidence level if speedingevidence.probabilityexceeds(0.95) { // Only act if 95% confident println!("Issue speeding ticket"); } ```

Features

  • Evidence-based conditionals: Comparisons return evidence, not boolean facts
  • Uncertainty propagation: Arithmetic operations preserve uncertainty
  • Lazy evaluation: Computation graphs built lazily for efficiency
  • Graph optimization: Common subexpression elimination and caching for performance
  • SPRT hypothesis testing: Sequential Probability Ratio Test for optimal sampling
  • Rich distributions: Normal, uniform, exponential, binomial, categorical, etc.
  • Statistical analysis: Mean, std dev, confidence intervals, CDF, etc.

Installation

Add this to your Cargo.toml:

toml [dependencies] uncertain-rs = "0.1.0"

Quick Start

```rust use uncertain_rs::Uncertain;

fn main() { // Create uncertain values let x = Uncertain::normal(5.0, 1.0); let y = Uncertain::normal(3.0, 0.5);

// Perform arithmetic operations
let sum = x.clone() + y.clone();
let product = x * y;

// Sample from the distributions
println!("Sum sample: {}", sum.sample());
println!("Product sample: {}", product.sample());

// Statistical analysis
println!("Sum mean: {}", sum.expected_value(1000));
println!("Sum std dev: {}", sum.standard_deviation(1000));

} ```

For more examples, see the examples directory.

Advanced Features

Graph Optimization

The library includes a computation graph optimizer that can eliminate common subexpressions and improve performance:

```rust use uncertain_rs::{Uncertain, computation::GraphOptimizer};

// Create an expression with common subexpressions let x = Uncertain::normal(2.0, 0.1); let y = Uncertain::normal(3.0, 0.1); let z = Uncertain::normal(1.0, 0.1);

// Expression: (x + y) * (x + y) + (x + y) * z // The subexpression (x + y) appears 3 times let sum = x.clone() + y.clone(); let expr = (sum.clone() * sum.clone()) + (sum * z);

// Apply optimization to eliminate common subexpressions let mut optimizer = GraphOptimizer::new(); let optimized = optimizer.eliminatecommonsubexpressions(expr.intocomputationnode());

// The optimized graph reuses the (x + y) subexpression println!("Cache size: {}", optimizer.subexpression_cache.len()); ```

Development Workflow

We use just as a task runner. Available commands:

  • just fmt - Format code
  • just lint - Run clippy linting
  • just test - Run tests
  • just audit - Security audit (check for vulnerabilities)
  • just dev - Run the full development workflow (format + lint + test + audit)

Security

This project takes security seriously. We run cargo audit to check for known vulnerabilities in dependencies:

  • CI: Automated security audits run on every push and PR
  • Local: Run just audit or cargo audit before submitting changes
  • Installation: If you don't have cargo-audit, run cargo install cargo-audit

The security audit checks all dependencies against the RustSec Advisory Database.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Owner

  • Name: Oleksandr Prokhorenko
  • Login: minikin
  • Kind: user
  • Location: Remote

GitHub Events

Total
  • Watch event: 2
  • Delete event: 5
  • Public event: 1
  • Push event: 21
  • Pull request event: 10
  • Fork event: 1
  • Create event: 7
Last Year
  • Watch event: 2
  • Delete event: 5
  • Public event: 1
  • Push event: 21
  • Pull request event: 10
  • Fork event: 1
  • Create event: 7

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 0
  • Total pull requests: 6
  • Average time to close issues: N/A
  • Average time to close pull requests: 20 minutes
  • Total issue authors: 0
  • Total pull request authors: 2
  • Average comments per issue: 0
  • Average comments per pull request: 0.0
  • Merged pull requests: 4
  • Bot issues: 0
  • Bot pull requests: 1
Past Year
  • Issues: 0
  • Pull requests: 6
  • Average time to close issues: N/A
  • Average time to close pull requests: 20 minutes
  • Issue authors: 0
  • Pull request authors: 2
  • Average comments per issue: 0
  • Average comments per pull request: 0.0
  • Merged pull requests: 4
  • Bot issues: 0
  • Bot pull requests: 1
Top Authors
Issue Authors
Pull Request Authors
  • minikin (5)
  • dependabot[bot] (1)
Top Labels
Issue Labels
Pull Request Labels
dependencies (1) rust (1)

Packages

  • Total packages: 1
  • Total downloads:
    • cargo 268 total
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 1
  • Total maintainers: 1
crates.io: uncertain-rs

A Rust library for uncertainty-aware programming, implementing the approach from 'Uncertain<T>: A First-Order Type for Uncertain Data'

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 268 Total
Rankings
Dependent repos count: 20.7%
Dependent packages count: 27.4%
Average: 47.6%
Downloads: 94.6%
Maintainers (1)
Last synced: 6 months ago

Dependencies

.github/actions/build-project/action.yml actions
.github/actions/quality-checks/action.yml actions
.github/actions/run-tests/action.yml actions
.github/actions/setup-rust/action.yml actions
  • actions/cache v3 composite
  • dtolnay/rust-toolchain master composite
.github/workflows/ci.yml actions
  • ./.github/actions/build-project * composite
  • ./.github/actions/quality-checks * composite
  • ./.github/actions/run-tests * composite
  • ./.github/actions/setup-rust * composite
  • actions/checkout v4 composite
  • codecov/codecov-action v5 composite
  • taiki-e/install-action cargo-llvm-cov composite
  • taiki-e/install-action cargo-audit composite
Cargo.toml cargo
  • approx 0.5 development
  • rand 0.9.2
  • uuid 1.0