stainless-steel / probability Goto Github PK
View Code? Open in Web Editor NEWProbability-theory toolbox
License: Other
Probability-theory toolbox
License: Other
Lib contains comparsions like:
impl distribution::Continuous for Exponential {
#[inline]
fn density(&self, x: f64) -> f64 {
if x < 0.0 {
0.0
} else {
self.lambda * (-self.lambda * x).exp()
}
}
}
but in fact f64
implements PartialOrd
only and comparsion contains some uncontrolled behaviour:
if x < 0.0 {
0.0
} else { // x >= 0.0 && x.is_nan()
self.lambda * (-self.lambda * x).exp()
}
What about to use PartialCmp
explicitly? I think It won't decline perfomance.
The following test results in an infinite loop in version 0.18 due to the Newton method not converging.
#[test]
fn inverse_non_converging() {
let p = 0.9810204628647335;
let n = 3666;
let q = 0.0033333333333332993;
let dist = Binomial::new(n, p);
let k = dist.inverse(q);
println!("k = {k}");
}
Should the parameters of a distribution be private?
Pros:
Cons:
()
, to access a parameter.Hi Ivan,
I've been working on some research using Rust and started programming a distributions/probability toolbox before realising you'd already done the job for me. One thing, however, that would be really useful is if each distribution not only defined what values it returns when sampling, but also the support over which it is defined. I originally did this by adding an associated type bound to take values implementing the Space
trait in my spaces crate.
Is this a feature you'd be happy to add? I'd be more than happy to actually code it up and contribute; not necessarily using my spaces code mind.
Let me know what you think.
Regards,
Tom
@IvanUkhov Your library is great! Good test coverage. I like it 👍
What about to add more features? I can help with PRs.
I've found a distributions list there.
What do you think about this list?
I already have implementations of some with C and want to move it to Rust and found your library is the best place to do it. What about to implement most of them?
Hey! I wanted to ask if you'd be open to merging a change that adds default implementations for various distributions? I've been using your crate and would like to implement default so that types that wrap the raw distributions can be made a bit more ergonomic for things like examples / tests etc.
Wikipedia's definition looks pretty straightforward. I started work by copying the exponential.rs and just replacing formulas.
What's the scope of work that needs to be done on all new distributions?
Should there be a clear separation of distributions into discrete and continuous?
Related thoughts and questions:
This package is great, and it's most of what I need. However, there doesn't seem to be a way to give it an iterator and have it derive the distribution coefficients. For example, if you created a new Gaussian distribution, you could initialize it with an iterator over f64
and it would traverse the iterator and compute the mean and variance, which could then be used in later computation.
If there is interest in such a feature from the maintainer(s), and a desire to help shape the architecture of such a feature, I could take a crack at implementing it...
Let me know.
Thanks.
There aren't constructors which returns Result<Self, Error>
. It's useful for software where user can set parameters for distributions. Without this kind of methods I have to repeat checks. For release the checking is lost at all. Library uses debug_assert
which can panic during testing, but it's better to provide explicit behaviour.
I offer to add something like this:
// categorical.rs
pub enum Error {
LessThanZero,
GreaterThanOne,
SumNotEqualOne,
}
impl Categorical {
pub fn new_with_check(p: &[f64]) -> Result<Self, Error>;
}
@IvanUkhov Your opinion?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.