-
Notifications
You must be signed in to change notification settings - Fork 430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merging Rust Random Choice #110
Comments
Looks like a good crate!
I doubt there’s much drive to merge anything into |
Well, we are finally looking at weighted sampling algorithms. @StefanoD this Stochastic Universal Sampling algorithm has some slightly surprising limitations. Given Put simply: elements with weight less than I guess for some applications this is okay, but it's not the same as taking The main attraction of this algorithm seems to be speed, specifically optimisation to use only a single random value. Modern PRNGs can be quite fast, so this may not be a good general-purpose choice, although may still be the fastest option. (The "correct" sampling approach would be to place |
I wrote a little about it at the bottom of this comment dhardy#82 (comment). The are fields where it is useful, but it is definitely not one of the two 'standard' weighted choice algorithms. |
But yes, this approach is more about weights and only an approximation of probabilities, but this might be good enough for the most use cases and interesting for embedded devices or real time applications, because of its performance. Actually I think many approaches are also only approximations of probabilities, but with a worse time complexity. |
@StefanoD I'm just pointing out that the limits of the approximation are not clear. The highlighted text is more pointing out problems with other approaches than it is discussing limitations. |
If I understand you correctly, you say, that an element can be sampled maximum two times. But this is not correct. If there are 4 samples with one element with a weight of 100 (given as parameter!) and the other three only 0.1 and the user wants 100 samples, than If you are interested of an respective unit test, let me know. EDIT: After rereading your post, I think, I misunderstood you, but I'm still not sure if your claim is correct. |
It's easy enough to test. Simply run let mut samples = vec![1, 2, 3, 4];
let a = 10.0f64;
let b = 20.0f64;
let weights: Vec<f64> = vec![1.0, 1.0, a, b];
let choices = random_choice().random_choice_f64(&samples, &weights, 1000); You'll see that the difference in number of 0s and number of 1s returned will never be greater than 1. No matter what values you use for a and b. and if you change |
There does not appear to much more interest in this, and I'd prefer not to add this type of approximation to Rand. We also now support |
Hi,
I want to ask, if there is an interested, to merge my small lib to this crate.
As far as I know, this random crate doesn't support to choose randomly samples by their weight/probabilities.
I have still to refactor the API and write more tests, but the implementation of the algorithm is finished. I have to implement the special case where I get a vec of Box, though.
https://github.com/StefanoD/Rust_Random_Choice
The text was updated successfully, but these errors were encountered: