Skip to content
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

Add an exponential generator #298

Merged
merged 6 commits into from
Dec 7, 2024
Merged

Add an exponential generator #298

merged 6 commits into from
Dec 7, 2024

Conversation

jmid
Copy link
Collaborator

@jmid jmid commented Dec 6, 2024

This PR adds an exponential generator to both QCheck and QCheck2, using a mapping from a uniform [0;1] distribution
https://en.wikipedia.org/wiki/Relationships_among_probability_distributions
https://en.wikipedia.org/wiki/Exponential_distribution#Random_variate_generation

All of them takes a mean/average parameter, e.g., exponential 10., and results in a distribution where samples approximate that mean/average:

+++ Stats for exponential 10. dist ++++++++++++++++++++++++++++++++++++++++++++++++++++++++

stats dist:
  num: 5000, avg: 9.56, stddev: 9.91, median 7, min 0, max 89
    0..  4: #######################################################        1934
    5..  9: ##################################                             1202
   10.. 14: ####################                                            727
   15.. 19: ############                                                    452
   20.. 24: ########                                                        284
   25.. 29: ####                                                            164
   30.. 34: ##                                                              103
   35.. 39: #                                                                51
   40.. 44:                                                                  26
   45.. 49:                                                                  24
   50.. 54:                                                                  15
   55.. 59:                                                                   7
   60.. 64:                                                                   3
   65.. 69:                                                                   2
   70.. 74:                                                                   2
   75.. 79:                                                                   1
   80.. 84:                                                                   1
   85.. 89:                                                                   2
   90.. 94:                                                                   0
   95.. 99:                                                                   0

We've found the combinator useful in QCheck-STM to generate cmd lists of a reasonable length ocaml-multicore/multicoretests#472 but thought the combinator could be more generally useful.

We may even consider switching our list, array, string, and bytes generators to output lengths following such an exponential distribution, but that will be for another day - and PR...

@jmid jmid force-pushed the add-exponential-gen branch from 74f7f61 to c30deb1 Compare December 7, 2024 11:41
@jmid
Copy link
Collaborator Author

jmid commented Dec 7, 2024

Rebased on main after merging #299

@jmid jmid merged commit 7b6e50c into c-cube:main Dec 7, 2024
13 checks passed
@jmid jmid deleted the add-exponential-gen branch December 7, 2024 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant