forked from scipy/scipy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: stats.unuran: add a higher level API
This adds a higher-level class called `GenericGenerator` which can be used to create generators using UNU.RAN's String API. Currently, only strings are allowed but it can be extended to accept a object containing a UNU.RAN distribution. One can simply pass a string with the distribution to sample from and create a generator: >>> rng = GenericGenerator("normal") >>> rvs = rng.rvs(100_000) It is also possible to pass the method and its parameters as keyword arguments. >>> rng = GenericGenerator("normal", method="tdr", domain=(-5, 5), c=0., ... cpoints=(-4.5, -3.5, -2.5, 0.0, 2.5, 3.5, 4.5)) >>> rvs = rng.rvs(100_000) It is also possible to change the parameters of the distribution. The below example creates a samplers for the normal distribution with mean 6 and standard deviation 4.25: >>> rng = GenericGenerator("normal(6, 4.25)") Advanced use case includes passing a custom distribution with methods coded as strings. >>> rng = GenericGenerator("distr = cont; pdf = 'exp(-0.5 * x^2)'") >>> rvs = rng.rvs(100_000)
- Loading branch information
1 parent
ca45d2b
commit cd2bd96
Showing
1 changed file
with
121 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters