def test_KMN_adaptive_noise(self): adaptive_noise_fn = lambda n, d: 0.0 if n < 1000 else 5.0 X, Y = self.get_samples(mu=0, std=1, n_samples=999) est = KernelMixtureNetwork("kmn_999", 1, 1, n_centers=5, y_noise_std=0.0, x_noise_std=0.0, adaptive_noise_fn=adaptive_noise_fn) est.fit(X, Y) std_999 = est.std_(x_cond=np.array([[0.0]]))[0] X, Y = self.get_samples(mu=0, std=1, n_samples=1002) est = KernelMixtureNetwork("kmn_1002", 1, 1, n_centers=5, y_noise_std=0.0, x_noise_std=0.0, adaptive_noise_fn=adaptive_noise_fn) est.fit(X, Y) std_1002 = est.std_(x_cond=np.array([[0.0]]))[0] self.assertLess(std_999, std_1002) self.assertGreater(std_1002, 2)
X, Y = density_simulator.simulate(n_samples=3000) """ fit density model """ model = KernelMixtureNetwork("KDE_demo", ndim_x=1, ndim_y=1, n_centers=50, x_noise_std=0.2, y_noise_std=0.1, random_seed=22) model.fit(X, Y) """ query the conditional pdf and cdf""" x_cond = np.zeros((1, 1)) y_query = np.ones((1, 1)) * 0.1 prob = model.pdf(x_cond, y_query) cum_prob = model.cdf(x_cond, y_query) """ compute conditional moments & VaR """ x_cond = np.zeros((1, 1)) mean = model.mean_(x_cond)[0][0] std = model.std_(x_cond)[0][0] skewness = model.skewness(x_cond)[0] VaR = model.value_at_risk(x_cond, alpha=0.01)[0] print("Mean:", mean) print("Std:", std) print("Skewness:", skewness) print("Value-at-Risk", VaR) """ plot the fitted distribution """ x_cond_plot = np.array([-0.5, 0, 0.5]) model.plot2d(x_cond_plot, ylim=(-0.25, 0.15), show=True)