[SciPy-Dev] Integrating UNU.RAN in scipy.stats

Christoph Baumgarten christoph.baumgarten at gmail.com
Wed Aug 4 05:24:21 EDT 2021


Hi,

there was already a lot of feedback on the PR and it has been approved by
two developers. To meet the GSoC deadline, we plan to merge it early next
week. I just wanted to send another short mail in case someone still would
like to take a look. As Tirth mentioned, any additional feedback on the
approach to embed the C library is welcome.

Christoph

<scipy-dev-request at python.org> schrieb am Sa., 17. Juli 2021, 18:01:

> Send SciPy-Dev mailing list submissions to
>         scipy-dev at python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         https://mail.python.org/mailman/listinfo/scipy-dev
> or, via email, send a message with subject or body 'help' to
>         scipy-dev-request at python.org
>
> You can reach the person managing the list at
>         scipy-dev-owner at python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of SciPy-Dev digest..."
>
>
> Today's Topics:
>
>    1. Integrating UNU.RAN in scipy.stats (Tirth Patel)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Sat, 17 Jul 2021 01:18:24 +0530
> From: Tirth Patel <tirthasheshpatel at gmail.com>
> To: scipy-dev <scipy-dev at python.org>
> Subject: [SciPy-Dev] Integrating UNU.RAN in scipy.stats
> Message-ID:
>         <CABpuv3-GL6etTNVrvQBnFxK=
> f1iToNnRgnzM3pQDEZZT5SdJww at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> Hi all,
>
> I, Christoph, and Nicholas have been working on gh-14215 [1] to integrate
> UNU.RAN library in SciPy. We'd appreciate your thoughts on it!
>
> We have designed an object-oriented API for sampling from any continuous or
> discrete distributions using universal generators in UNU.RAN. For now, only
> the `TransformedDensityRejection` (for continuous distributions) and
> `DiscreteAliasUrn` (for discrete distributions) methods have been added.
> These methods take a distribution object with required methods like PDF,
> dPDF, CDF, etc as input and set-up a generator which can then be used to
> sample from that distribution:
>
>     >>> from scipy.stats import TransformedDensityRejection
>     >>> import numpy as np
>     >>>
>     >>> class StdNorm:
>     ...     def pdf(self, x: float) -> float:
>     ...         # notice that normalization constant is not required
>     ...         # and the pdf accepts and returns scalars.
>     ...         return np.exp(-0.5 * x*x)
>     ...     def dpdf(self, x: float) -> float:
>     ...         return -x * self.pdf(x)
>     ...
>     >>> dist = StdNorm()
>     >>> rng = TransformedDensityRejection(dist, seed=123)
>     >>> rng.rvs()
>     0.474548717355228
>
> One of the tricky parts about this PR is handling errors occurring in
> Python callbacks and UNU.RAN C library. We could use some reviews and ideas
> to build a maintainable infrastructure. Use of non-local returns causes
> memory leaks making the code for error handling a lot less trivial and
> possibly much more complex. I would really appreciate it if someone could
> take a look at the Cython and C code in the PR and help verify the approach
> or suggest an alternative approach, if any. There are some discussions
> about this in [2] and [3] and you can also look at the review comments on
> the main PR. Although the API design is not final yet, please feel free to
> comment on it as well. Thanks!
>
> [1]: https://github.com/scipy/scipy/pull/14215
> [2]: https://github.com/tirthasheshpatel/scipy/pull/9
> [3]: https://github.com/tirthasheshpatel/unuran/pull/1
>
>
> --
> Kind Regards,
> Tirth Patel
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <
> https://mail.python.org/pipermail/scipy-dev/attachments/20210717/65b4698c/attachment-0001.html
> >
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> SciPy-Dev mailing list
> SciPy-Dev at python.org
> https://mail.python.org/mailman/listinfo/scipy-dev
>
>
> ------------------------------
>
> End of SciPy-Dev Digest, Vol 213, Issue 14
> ******************************************
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/scipy-dev/attachments/20210804/b3761ab4/attachment.html>


More information about the SciPy-Dev mailing list