Hello everyone!
I feel the intersection with statisticians and systems level programmers is quite narrow, but I happen to be one of those! I’ve implemented a small Distributions library!
I had two objectives in mind: 1) refactor from another project where I need random number generation following some distributions (the ones which are actually implemented) and 2) to finally understand how Intrusive Interfaces actually work (or I hope so at least), let me explain.
I realized that a Statistical Distribution is an amazing problem to teach to a newbie - like myself - how knows some statistics how this pattern goes and understands what a more traditional interface (like in Java or Go) works. You have several functions that every distribution must implement (pdf, ppf, cdf, sample) and you can have functions on the Interface that the implementees do not need to implement (as sampleBuffer, which just calls sample from the children).
I just learnt about Intrusive Interfaces with the Io new implementation, so if someone could actually verify to me if what I did complies as that I would be very glad :))
Regarding features, it literally has two distributions: you just can generate random samples from an Exponential and a Uniform with single or double precision. I also don’t intend to work on this a lot, so if you need an specific distribution or feature just open an issue or send me a mail!
const Unif = stats.Uniform(f32);
const Exp = stats.Exponential(f32);
const Dist = stats.Distribution(f32);
const seed = blk: {
var os_seed: u64 = undefined;
init.io.random(std.mem.asBytes(&os_seed));
break :blk os_seed;
};
var prng = std.Random.DefaultPrng.init(seed);
const rng = prng.random();
var exp: Exp = .init(2);
const dexp: *Dist = &exp.interface; //ptr distribution
const e = dexp.sample(rng);
var esample: [40]f32 = undefined;
dexp.sampleBuffer(&esample, rng);
Have a nice day :))