python - How to assign weights to a set of variables based on pdf? -
this continuation of previous question had doubt , asked ask new question! here goes.
say have array of size 100.
how calculate probability of each of value in array?
my understanding far:
import numpy np import scipy.stats scipy import stats import matplotlib.pyplot plt def getdistribution(data): kernel = stats.gaussian_kde(data,bw_method=0.07) class rv(stats.rv_continuous): def _rvs(self, *x, **y): return kernel.resample(int(self._size)) #random variates def _cdf(self, x): return kernel.integrate_box_1d(0,max(x)) #integrate pdf between 2 bounds (-inf x here!) def _pdf(self, x): return kernel.evaluate(x) #evaluate estimated pdf on provided set of points return rv(name='kdedist') data = np.random.random(100) sorted_data = np.sort(data) dist = getdistribution(sorted_data) pdf = dist.pdf(sorted_data) plt.plot(sorted_data,pdf_data,'-o') plt.hist(sorted_data,normed=true) plt.show()
i know above code gives me pdf , when plotted alongside histogram of data, this.
i know how can probability on each of points belong data. want assign same weights each of data points.
Comments
Post a Comment