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
#1
Dear experts,

I am working with a probability density function (PDF), that I named as "Jaya", as below:

f(x) = scale**(shape-1) * x**(-shape)*(np.exp(-scale/x)) / math.factorial(shape - 2)

I would like to know how can I create a function to generate random number based on the above PDF.

One example is the numpy.random.gamma that follows the Gamma PDF as below.

f(x) = x**(shape-1)*(np.exp(-bins/scale) / (sps.gamma(shape)*scale**shape))

import numpy as np
import matplotlib.pyplot as plt
import scipy.special as sps
import math


shape, scale = 3, 10**-6. 
s = np.random.gamma(shape, scale, 1000)


count, bins, ignored = plt.hist(s, 50, density=True)

#____________Gamma
y = bins**(shape-1)*(np.exp(-bins/scale) /
                     (sps.gamma(shape)*scale**shape))
plt.plot(bins, y, linewidth=2, color='r')
plt.show()

#____________Jaya
y = scale**(shape-1) * bins**(-shape)*(np.exp(-scale/bins)) / math.factorial(shape - 2)
plt.plot(bins, y, linewidth=1, color='r')
plt.show()
Thank you!
Reply


Messages In This Thread
How to create a random library for an specific function - by andre_fermart - Mar-31-2019, 03:40 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Create a function vector Cooketaker 4 959 Dec-27-2022, 08:22 PM
Last Post: Cooketaker
  substring function to create new column Chandan 6 2,403 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,533 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