def test1DCDFandPPF(self): # prepare data U = Normal(0.5, 0.1, 0, 1) train_samples = U.rvs(1000).reshape(1000, 1) dist = SGDEdist.byLearnerSGDEConfig(train_samples, config={ "grid_level": 5, "grid_type": "poly", "refinement_numSteps": 0, "refinement_numPoints": 10, "regularization_type": "Laplace", "crossValidation_lambda": 0.000562341, "crossValidation_enable": False, "crossValidation_kfold": 5, "crossValidation_silent": True }, bounds=U.getBounds()) fig = plt.figure() plt.hist(train_samples, bins=10, normed=True) plotDensity1d(U) plotDensity1d(dist) plt.title("original space") fig.show() transformed_samples = dist.cdf(train_samples) fig = plt.figure() plt.hist(transformed_samples, bins=10, normed=True) plt.title("uniform space") fig.show() transformed_samples = dist.ppf(transformed_samples) fig = plt.figure() plt.hist(transformed_samples, bins=10, normed=True) plotDensity1d(U) plotDensity1d(dist) plt.title("original space") 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()