(我对这个问题的解释可能是错误的。如果问题是如何从离散的PDF转换为离散的CDF,则将np.cumsum
除以合适的常数将在样本np.cumsum
。不np.cumsum
,则将数组的np.cumsum
乘以点之间的距离即可。)
如果您有一个离散的样本数组,并且想知道样本的CDF,则可以对数组进行排序。如果查看排序结果,您会发现最小值代表0%,最大值代表100%。如果您想知道分布的50%处的值,只需查看位于已排序数组中间的array元素即可。
让我们用一个简单的例子仔细看一下:
import matplotlib.pyplot as plt
import numpy as np
# create some randomly ddistributed data:
data = np.random.randn(10000)
# sort the data:
data_sorted = np.sort(data)
# calculate the proportional values of samples
p = 1. * np.arange(len(data)) / (len(data) - 1)
# plot the sorted data:
fig = figure()
ax1 = fig.add_subplot(121)
ax1.plot(p, data_sorted)
ax1.set_xlabel('$p$')
ax1.set_ylabel('$x$')
ax2 = fig.add_subplot(122)
ax2.plot(data_sorted, p)
ax2.set_xlabel('$x$')
ax2.set_ylabel('$p$')
这给出了以下图,其中右侧图是传统的累积分布函数。它应该反映出点背后的过程的CDF,但是自然地,只要点数是有限的,它就不是。
此函数易于反转,并且取决于您的应用程序所需的形式。
0
如何在python中计算累积分布函数(CDF) ?
我想从我拥有的点数组(离散分布)中进行计算,而不是从scipy具有的连续分布中进行计算。