def test2DCDFandPPF(self): # prepare data C = np.array([[0.1, 0.08], [0.08, 0.1]]) / 10. U = dists.MultivariateNormal([0.5, 0.5], C, 0, 1) train_samples = U.rvs(1000) fig = plt.figure() plotDensity2d(U) plt.title('true density') fig.show() dist = KDEDist(train_samples, bounds=U.getBounds()) fig = plt.figure() plotDensity2d(dist) plt.title('estimated KDE density') fig.show() samples = dists.J([dists.Uniform(0, 1), dists.Uniform(0, 1)]).rvs(1000) fig = plt.figure() plt.plot(samples[:, 0], samples[:, 1], "o ") plt.title('u space') plt.xlim(0, 1) plt.ylim(0, 1) fig.show() transformed_samples = dist.ppf(samples) fig = plt.figure() plt.plot(transformed_samples[:, 0], transformed_samples[:, 1], "o ") plt.title('x space (transformed)') plt.xlim(0, 1) plt.ylim(0, 1) fig.show() samples = dist.cdf(transformed_samples) fig = plt.figure() plt.plot(samples[:, 0], samples[:, 1], "o ") plt.title('u space (transformed)') plt.xlim(0, 1) plt.ylim(0, 1) fig.show() plt.show()
def test1DCDFandPPF(self): # prepare data U = Normal(0.5, 0.1, 0, 1) train_samples = U.rvs(1000).reshape(1000, 1) dist = KDEDist(train_samples, kernelType=KernelType_EPANECHNIKOV) rc('font', **{'size': 18}) fig = plt.figure() x = np.linspace(0, 1, 1000) plt.plot(x, dist.cdf(x), label="estimated") plt.plot(x, [U.cdf(xi) for xi in x], label="analytic") plt.legend(loc="lower right") fig.show() fig = plt.figure() plt.hist(train_samples, normed=True) plotDensity1d(U, label="analytic") plotDensity1d(dist, label="estimated") plt.title("original space") plt.legend() fig.show() transformed_samples = dist.cdf(train_samples) fig = plt.figure() plt.hist(transformed_samples, normed=True) plt.title("uniform space") fig.show() transformed_samples = dist.ppf(transformed_samples) fig = plt.figure() plt.hist(transformed_samples, normed=True) plotDensity1d(U, label="analytic") plotDensity1d(dist, label="estimated") plt.title("original space") plt.legend() fig.show() plt.show()
def test2DPPF(self): # prepare data C = np.array([[0.1, 0.08], [0.08, 0.1]]) / 10. U = dists.MultivariateNormal([0.5, 0.5], C, 0, 1) fig = plt.figure() plotDensity2d(U) plt.title('true density') fig.show() dist = KDEDist(U.rvs(1000), kernelType=KernelType_EPANECHNIKOV, bounds=U.getBounds()) fig = plt.figure() plotDensity2d(dist) plt.title('estimated KDE density') fig.show() samples = dists.J([dists.Uniform(0, 1), dists.Uniform(0, 1)]).rvs(1000) fig = plt.figure() plt.plot(samples[:, 0], samples[:, 1], "o ") plt.title('uniformly drawn samples') plt.xlim(0, 1) plt.ylim(0, 1) fig.show() transformed_samples = dist.ppf(samples) fig = plt.figure() plt.plot(transformed_samples[:, 0], transformed_samples[:, 1], "o ") plt.title('transformed samples') plt.xlim(0, 1) plt.ylim(0, 1) fig.show() plt.show()