In [1]:
import numpy as np
import scipy.stats as spst
import matplotlib.pyplot as plt
import sympy
%matplotlib inline
Example 1:
$X$ from a uniform distribution $h(X)=X^2$
In [2]:
x=np.random.rand(10000)
hx=x**2
plt.hist(hx,bins=100)
plt.show()
np.std(hx,ddof=1)/10000**0.5

Out[2]:
0.0029909322969707513
In [3]:
x=np.linspace(0.0001,1,1000)
x_s=sympy.Symbol(“x”)
qx=x**2*1/ sympy.integrate(x_s**2,(x_s,0,1))
px=x/x
plt.plot(x,qx,label=”q(x)”)
plt.plot(x,px,label=”p(x)”)
plt.legend()
plt.show()

Example 2:
$X$ from a uniform distribution $h(X)=\sqrt{X}$
In [4]:
x=np.random.rand(10000)
hx=x**0.5
plt.hist(hx,bins=100)
plt.show()
np.std(hx,ddof=1)/10000**0.5

Out[4]:
0.0023552892475623764
In [5]:
x=np.linspace(0.0001,1,1000)
x_s=sympy.Symbol(“x”)
qx=x**0.5*1/ sympy.integrate(x_s**0.5,(x_s,0,1))
px=x/x
plt.plot(x,qx,label=”q(x)”)
plt.plot(x,px,label=”p(x)”)
plt.legend()
plt.show()

In [8]: