Python Forum
How to create a random library for an specific function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to create a random library for an specific function
#4
If we consider source code of distributions.py, we can find that rv_continous class uses numerical differentiation/integration if only
few methods were defined to describe probability distribution. E.g. if we define only _pdf method, all other methods, such as .cdf, becomes defined due to machinery in rv_continous (but this machinery is numerical); So, it is better to define (override) other methods, such as ._cdf, ._icdf explicitly; If these methods are defined explicitly, no numerical differentiaion/integration or other complex stuff be applied; Therefore, it is better to define as many helpers ._pdf, _cdf etc. as possible. This will increase speed and reliability of further computations. In our case, we define ._pdf only... What is .rvs? .rvs is based on uniform distribution on [0,1) and inverse cdf; if you didn't define inverse cdf explicitly for your distribution, rv_continous class tries to do all work numerically (numerical approach is less robust than computing analytical formula of icdf). This is why some warnings or even errors can occur.
I just replaced return y with return y if x>0 else 0.0 and tried to call .rvs (parameters were shape_=3, scale_=1): everything went fine. So, what to do?! You need to generate random numbers from Jaya distribution, ok. You can drop using rv_continous at all. Look at implementation of _rvs method and, if you know inverse cdf of the distribution, just generate uniformly distributed values in [0,1) and apply inverse cdf to them and you get values that have specific distribution.
So, is it possible to find analytical forms of cdf or better inverse cdf for Jaya distribution? This is the question to be investigated.
Reply


Messages In This Thread
RE: How to create a random library for an specific function - by scidam - Apr-04-2019, 10:55 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Create a function vector Cooketaker 4 1,017 Dec-27-2022, 08:22 PM
Last Post: Cooketaker
  substring function to create new column Chandan 6 2,526 Feb-14-2020, 10:11 AM
Last Post: scidam
  Removing rows at random based on the value of a specific column Mr_Keystrokes 4 5,672 Aug-24-2018, 11:15 AM
Last Post: Mr_Keystrokes

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020