1 回答

TA貢獻(xiàn)1851條經(jīng)驗(yàn) 獲得超3個(gè)贊
獲得更平滑結(jié)果的一種可能性是使用更多樣本,通過(guò)使用,我得到以下圖像:10^5 samples100 bins
ws = norm.rvs(loc=4.0, scale=1.5, size=100000)
density, bins = np.histogram(ws, bins=100, normed=True, density=True)
通常,您可以使用 scipys 插值模塊來(lái)平滑 CDF。對(duì)于和平滑因子我得到:100 sampless=0.01
import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import splev, splrep
density1 = unity_density.cumsum()
x = bins[:-1]
y = density1
# Interpolation
spl = splrep(x, y, s=0.01, per=False)
x2 = np.linspace(x[0], x[-1], 200)
y2 = splev(x2, spl)
# Plotting
fig, ax = plt.subplots()
plt.plot(x, density1, 'o')
plt.plot(x2, y2, 'r-')
第三種可能性是分析計(jì)算CDF。如果你自己用一個(gè)/函數(shù)生成噪音,大多數(shù)時(shí)候已經(jīng)有可用的實(shí)現(xiàn),否則你應(yīng)該在維基百科上找到它。如果您的樣品來(lái)自測(cè)量值,那當(dāng)然是另一回事。numpyscipyCDF
import numpy as np
from scipy.stats import norm
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
x = np.linspace(-2, 10)
y = norm(loc=4.0, scale=1.5).cdf(x)
ax.plot(x, y, 'bo-')
添加回答
舉報(bào)