rv

Random variables for Rust

https://github.com/promised-ai/rv

Science Score: 44.0%

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

  • CITATION.cff file
    Found 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
Last synced: 6 months ago · JSON representation ·

Repository

Random variables for Rust

Basic Info
  • Host: GitHub
  • Owner: promised-ai
  • License: mit
  • Language: Rust
  • Default Branch: master
  • Size: 1.98 MB
Statistics
  • Stars: 20
  • Watchers: 4
  • Forks: 2
  • Open Issues: 8
  • Releases: 0
Created almost 2 years ago · Last pushed 10 months ago
Metadata Files
Readme Changelog License Citation

README.md

rv

Random variables (RV) for rust.

docs.rs Crates.io License Crates.io MSRV GitHub Actions Workflow Status Codecov

rv offers basic functionality for many probability distributions. For example, if we wanted to perform a conjugate analysis of Bernoulli trials:

```rust use rv::prelude::*;

// Prior over the unknown coin weight. Assume all weights are equally // likely. let prior = Beta::uniform();

// observations generated by a fair coin let obs_fair: Vec = vec![0, 1, 0, 1, 1, 0, 1];

// observations generated by a coin rigged to always show heads. Note that // we're using bools here. Bernoulli supports multiple types. let obs_fixed: Vec = vec![true; 6];

let datafair: BernoulliData<> = DataOrSuffStat::Data(&obsfair); let datafixed: BernoulliData<> = DataOrSuffStat::Data(&obsfixed);

// Let's compute the posterior predictive probability (pp) of a heads given // the observations from each coin. let postpredfair = prior.pp(&1u8, &datafair); let postpredfixed = prior.pp(&true, &datafixed);

// The probability of heads should be greater under the all heads data assert!(postpredfixed > postpredfair);

// We can also get the posteriors let postfair: Beta = prior.posterior(&datafair); let postfixed: Beta = prior.posterior(&datafixed);

// And compare their means let postmeanfair: f64 = postfair.mean().unwrap(); let postmeanfixed: f64 = postfixed.mean().unwrap();

assert!(postmeanfixed > postmeanfair); ```

Feature flags

  • serde1: enables serialization and de-serialization of structs via serde
  • process: Gives you access to Gaussian processes.
  • arraydist: Enables distributions and statistical tests that require the nalgebra crate.

Design

Random variables are designed to be flexible. For example, we don't just want a Beta distribution that works with f64; we want it to work with a bunch of things like

```rust use rv::prelude::*;

// Beta(0.5, 0.5) let beta = Beta::jeffreys();

let mut rng = rand::thread_rng();

// 100 f64 weights in (0, 1) let f64s: Vec = beta.sample(100, &mut rng); let pdfx = beta.lnpdf(&f64s[42]);

// 100 f32 weights in (0, 1) let f32s: Vec = beta.sample(100, &mut rng); let pdfy = beta.lnpdf(&f32s[42]);

// 100 Bernoulli distributions -- Beta is a prior on the weight let berns: Vec = beta.sample(100, &mut rng); let pdfbern = beta.lnpdf(&berns[42]); ```

For more interesting examples, including use in machine learning, see examples/.

Contributing

Bjork has had a great influence on how I create things. She once said in an interview:

When I did "Debut" I thought, 'OK, I've pleased enough people, I'm gonna get really selfish.' And I never sold as many records as with "Debut". So, I don't know, it seems the more selfish I am, the more generous I am. I'm not going to pretend I know the formula. I can only please myself.

And so our goal with rv is to please ourselves. We use it in our tools and we've designed it to do what we want. We are happy if you find rv useful, and we will entertain ideas for changes -- and accept them if we like them -- but in the end, rv is for us.

If you'd like to offer a contribution:

  1. Please create an issue before starting any work. We're far from stable, so we might actually be working on what you want, or we might be working on something that will change the way you might implement it.
  2. If you plan on implementing a new distribution, implement at least Rv, Support, and either ContinuousDistr or DiscreteDistr. Of course, more is better!
  3. Implement new distributions for the appropriate types. For example, don't just implement Rv<f64>, also implement Rv<f32>. Check out other distributions to see how it can be done easily with macros.
  4. Write tests, docs, and doc tests.
  5. Use rustfmt. We've included a .rustfmt.toml in the project directory.

Owner

  • Name: promised-ai
  • Login: promised-ai
  • Kind: organization

Citation (CITATION.cff)

# This CITATION.cff file was generated with cffinit.
# Visit https://bit.ly/cffinit to generate yours today!

cff-version: 1.2.0
title: RV
message: Random Variables for Rust
type: software
authors:
  - given-names: Baxter
    family-names: Eaves
    name-suffix: Jr
    email: bax@redpoll.ai
    affiliation: Redpoll
  - given-names: Michael
    family-names: Schmidt
    email: schmidt@redpoll.ai
    orcid: 'https://orcid.org/0000-0002-1658-6283'
    affiliation: Redpoll
identifiers:
  - type: url
    value: 'https://github.com/promised-ai/rv'
    description: GitHub Repository
repository-code: 'https://github.com/promised-ai/rv'
abstract: >-
  rv is a library for operating with random variables in
  Rust.
keywords:
  - Bayesian
  - Machine Learning
  - Mathematics
license: MIT
version: 0.18.1
date-released: '2025-02-28'

GitHub Events

Total
  • Issues event: 6
  • Watch event: 9
  • Delete event: 23
  • Issue comment event: 30
  • Push event: 234
  • Pull request review comment event: 44
  • Pull request review event: 65
  • Pull request event: 54
  • Fork event: 2
  • Create event: 29
Last Year
  • Issues event: 6
  • Watch event: 9
  • Delete event: 23
  • Issue comment event: 30
  • Push event: 234
  • Pull request review comment event: 44
  • Pull request review event: 65
  • Pull request event: 54
  • Fork event: 2
  • Create event: 29

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 5
  • Total pull requests: 32
  • Average time to close issues: 21 days
  • Average time to close pull requests: 9 days
  • Total issue authors: 1
  • Total pull request authors: 3
  • Average comments per issue: 0.4
  • Average comments per pull request: 0.69
  • Merged pull requests: 17
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 5
  • Pull requests: 32
  • Average time to close issues: 21 days
  • Average time to close pull requests: 9 days
  • Issue authors: 1
  • Pull request authors: 3
  • Average comments per issue: 0.4
  • Average comments per pull request: 0.69
  • Merged pull requests: 17
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • cscherrer (5)
Pull Request Authors
  • cscherrer (31)
  • BaxterEaves (8)
  • schmidmt (2)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • cargo 840,609 total
  • Total dependent packages: 3
  • Total dependent repositories: 7
  • Total versions: 61
  • Total maintainers: 2
crates.io: rv

Random variables

  • Documentation: https://docs.rs/rv/
  • License: MIT
  • Latest release: 0.18.1
    published about 1 year ago
  • Versions: 61
  • Dependent Packages: 3
  • Dependent Repositories: 7
  • Downloads: 840,609 Total
Rankings
Downloads: 6.6%
Dependent repos count: 8.7%
Dependent packages count: 9.2%
Average: 15.1%
Stargazers count: 24.7%
Forks count: 26.3%
Maintainers (2)
Last synced: 7 months ago

Dependencies

.github/workflows/changelog.yaml actions
  • actions/checkout v4 composite
.github/workflows/citation.yaml actions
  • actions/checkout v4 composite
  • dieghernan/cff-validator v3 composite
.github/workflows/rust-build-test.yaml actions
  • Swatinem/rust-cache v2 composite
  • actions-rs/cargo v1 composite
  • actions/checkout v4 composite
  • dtolnay/rust-toolchain stable composite
Cargo.lock cargo
  • 149 dependencies
Cargo.toml cargo
  • approx 0.5 development
  • assert 0.7 development
  • criterion 0.5 development
  • indoc 2 development
  • rand_xoshiro 0.6 development
  • serde_json 1 development
  • serde_yaml 0.9 development
  • argmin 0.8
  • argmin-math 0.3
  • doc-comment 0.3
  • lru 0.9.0
  • nalgebra 0.32
  • num 0.4
  • num-traits 0.2.17
  • peroxide 0.32.1
  • rand 0.8.5
  • rand_distr 0.4.3
  • serde 1
  • special 0.10