Created
May 29, 2022 22:21
-
-
Save rahulbhadani/49f6c2fb967070428a469b14817b8b2e to your computer and use it in GitHub Desktop.
Uniform Distribution and the Second Moment
This file contains hidden or 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
from scipy.stats import rv_continuous | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import seaborn as s | |
import matplotlib as mpl | |
import pyplot_themes as themes | |
themes.theme_paul_tol( grid=False, ticks=False,) | |
mpl.rcParams['font.family'] = 'Serif' | |
class Uniform(rv_continuous): | |
"Uniform distribution" | |
def _pdf(self, x): | |
y = 0 | |
if (x < (self.a)): | |
y = 0 | |
elif (x > (self.b)): | |
y = 0 | |
else: | |
y= 1.0/(self.b-self.a) | |
return y | |
P = Uniform(name='Uniform', a= 0, b =1) | |
B = P.rvs(size = 10000) | |
s.distplot(B) | |
plt.xlabel('$y$', color = '#DAD6D6') | |
plt.ylabel('f(y)', color = '#DAD6D6') | |
plt.show() | |
print('Second moment of the uniform distribution is {}'.format(P.moment(n=2))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment