def test_10_bins(self): """ Test that marginals sum to 1 and have correct shape. """ (bins, marginals) = plotP.calculate_1D_marginal_probs(self.P_samples, self.samples, self.lam_domain, nbins=10) nptest.assert_almost_equal(np.sum(marginals[0]), 1.0) nptest.assert_equal(marginals[0].shape, (10,))
def test_1D_smoothing(self): """ Test :meth:`bet.postProcess.plotP.smooth_marginals_1D`. """ (bins, marginals) = plotP.calculate_1D_marginal_probs(self.P_samples, self.samples, self.lam_domain, nbins=10) marginals_smooth = plotP.smooth_marginals_1D(marginals, bins, sigma=10.0) nptest.assert_equal(marginals_smooth[0].shape, marginals[0].shape) nptest.assert_almost_equal(np.sum(marginals_smooth[0]), 1.0)
def test_10_bins(self): """ Test that marginals sum to 1 and have correct shape. """ (bins, marginals) = plotP.calculate_1D_marginal_probs(self.samples, nbins = 10) nptest.assert_almost_equal(np.sum(marginals[0]), 1.0) nptest.assert_equal(marginals[0].shape, (10,))
def test_1_bin(self): """ Test that marginals sum to 1 and have correct shape. """ (bins, marginals) = plotP.calculate_1D_marginal_probs(self.samples, nbins = 1) nptest.assert_almost_equal(marginals[0][0], 1.0) nptest.assert_equal(marginals[0].shape, (1,))
def test_1_bin_1D(self): """ Test that 1D marginals sum to 1 and have right shape. """ (bins, marginals) = plotP.calculate_1D_marginal_probs(self.P_samples, self.samples, self.lam_domain, nbins=1) nptest.assert_almost_equal(marginals[0][0], 1.0) nptest.assert_almost_equal(marginals[1][0], 1.0) nptest.assert_equal(marginals[0].shape, (1,)) nptest.assert_equal(marginals[1].shape, (1,))
def test_10_bins_1D(self): """ Test that 1D marginals sum to 1 and have right shape. """ (bins, marginals) = plotP.calculate_1D_marginal_probs(self.samples, nbins = 10) nptest.assert_almost_equal(np.sum(marginals[0]), 1.0) nptest.assert_almost_equal(np.sum(marginals[1]), 1.0) nptest.assert_equal(marginals[0].shape, (10,))
def test_1_bin(self): """ Test that marginals sum to 1 and have correct shape. """ (bins, marginals) = plotP.calculate_1D_marginal_probs(self.P_samples, self.samples, self.lam_domain, nbins=1) nptest.assert_almost_equal(marginals[0][0], 1.0) nptest.assert_equal(marginals[0].shape, (1, ))
def test_1D_smoothing(self): """ Test :meth:`bet.postProcess.plotP.smooth_marginals_1D`. """ (bins, marginals) = plotP.calculate_1D_marginal_probs(self.samples, nbins = 10) marginals_smooth = plotP.smooth_marginals_1D(marginals, bins, sigma = 10.0) nptest.assert_equal(marginals_smooth[0].shape, marginals[0].shape) nptest.assert_almost_equal(np.sum(marginals_smooth[0]), 1.0)
def test_1_bin_1D(self): """ Test that 1D marginals sum to 1 and have right shape. """ (bins, marginals) = plotP.calculate_1D_marginal_probs(self.samples, nbins = 1) nptest.assert_almost_equal(marginals[0][0], 1.0) nptest.assert_almost_equal(marginals[1][0], 1.0) nptest.assert_equal(marginals[0].shape, (1,)) nptest.assert_equal(marginals[1].shape, (1,))
def test_10_bins_1D(self): """ Test that 1D marginals sum to 1 and have right shape. """ (bins, marginals) = plotP.calculate_1D_marginal_probs(self.P_samples, self.samples, self.lam_domain, nbins=10) nptest.assert_almost_equal(np.sum(marginals[0]), 1.0) nptest.assert_almost_equal(np.sum(marginals[1]), 1.0) nptest.assert_equal(marginals[0].shape, (10, ))
def test_plot_marginals_1D(self): """ Test :meth:`bet.postProcess.plotP.plot_1D_marginal_probs`. """ (bins, marginals) = plotP.calculate_1D_marginal_probs(self.samples, nbins = 10) try: plotP.plot_1D_marginal_probs(marginals, bins, self.samples, filename = "file", interactive=False) go = True except (RuntimeError, TypeError, NameError): go = False nptest.assert_equal(go, True)
def test_plot_marginals_1D(self): """ Test :meth:`bet.postProcess.plotP.plot_1D_marginal_probs`. """ (bins, marginals) = plotP.calculate_1D_marginal_probs(self.P_samples, self.samples, self.lam_domain, nbins=10) try: plotP.plot_1D_marginal_probs(marginals, bins, self.lam_domain, filename="file", interactive=False) go = True if os.path.exists("file_1D_0.eps"): os.remove("file_1D_0.eps") if os.path.exists("file_1D_1.eps"): os.remove("file_1D_1.eps") except (RuntimeError, TypeError, NameError): go = False nptest.assert_equal(go, True)
def test_plot_marginals_1D(self): """ Test :meth:`bet.postProcess.plotP.plot_1D_marginal_probs`. """ (bins, marginals) = plotP.calculate_1D_marginal_probs(self.P_samples, self.samples, self.lam_domain, nbins=10) try: plotP.plot_1D_marginal_probs(marginals, bins, self.lam_domain, filename="file", interactive=False) go = True if os.path.exists("file_1D_0.eps"): os.remove("file_1D_0.eps") if os.path.exists("file_1D_1.eps"): os.remove("file_1D_1.eps") except (RuntimeError, TypeError, NameError): go = False nptest.assert_equal(go, True)
# smooth 2D marginal probabilites for plotting (optional) marginals2D = plotP.smooth_marginals_2D(marginals2D, bins, sigma=1.0) # plot 2D marginal probabilities plotP.plot_2D_marginal_probs(marginals2D, bins, my_discretization, filename="contaminant_map", plot_surface=False, lam_ref=param_ref, lambda_label=labels, interactive=False) # calculate 1d marginal probs (bins, marginals1D) = plotP.calculate_1D_marginal_probs(my_discretization, nbins=20) # smooth 1d marginal probs (optional) marginals1D = plotP.smooth_marginals_1D(marginals1D, bins, sigma=1.0) # plot 1d marginal probs plotP.plot_1D_marginal_probs(marginals1D, bins, my_discretization, filename="contaminant_map", interactive=False, lam_ref=param_ref, lambda_label=labels) percentile = 1.0 # Sort samples by highest probability density and sample highest
and other similar methods), but we have not incorporated these into the code as lower-dimensional marginal plots have limited value in understanding the structure of a high dimensional non-parametric probability measure. ''' (bins, marginals2D) = plotP.calculate_2D_marginal_probs(P_samples=P, samples=lambda_emulate, lam_domain=lam_domain, nbins=[10, 10]) # smooth 2d marginals probs (optional) #marginals2D = plotP.smooth_marginals_2D(marginals2D,bins, sigma=0.01) # plot 2d marginals probs plotP.plot_2D_marginal_probs(marginals2D, bins, lam_domain, filename="linearMapValidation", plot_surface=False) # calculate 1d marginal probs (bins, marginals1D) = plotP.calculate_1D_marginal_probs(P_samples=P, samples=lambda_emulate, lam_domain=lam_domain, nbins=[10, 10]) # smooth 1d marginal probs (optional) #marginals1D = plotP.smooth_marginals_1D(marginals1D, bins, sigma=0.01) # plot 1d marginal probs plotP.plot_1D_marginal_probs(marginals1D, bins, lam_domain, filename="linearMapValidation")
# calculate 2D marginal probabilities (bins, marginals2D) = plotP.calculate_2D_marginal_probs(P_samples = P, samples = samples, lam_domain = lam_domain, nbins = 10) # smooth 2D marginal probabilites for plotting (optional) marginals2D = plotP.smooth_marginals_2D(marginals2D,bins, sigma=1.0) # plot 2D marginal probabilities plotP.plot_2D_marginal_probs(marginals2D, bins, lam_domain, filename = "contaminant_map", plot_surface=False, lam_ref = ref_lam, lambda_label=labels, interactive=False) # calculate 1d marginal probs (bins, marginals1D) = plotP.calculate_1D_marginal_probs(P_samples = P, samples = samples, lam_domain = lam_domain, nbins = 20) # smooth 1d marginal probs (optional) marginals1D = plotP.smooth_marginals_1D(marginals1D, bins, sigma=1.0) # plot 1d marginal probs plotP.plot_1D_marginal_probs(marginals1D, bins, lam_domain, filename = "contaminant_map", interactive=False, lam_ref=ref_lam, lambda_label=labels) percentile = 1.0 # Sort samples by highest probability density and sample highest percentile percent samples (num_samples, P_high, samples_high, lam_vol_high, data_high)= postTools.sample_highest_prob(top_percentile=percentile, P_samples=P, samples=samples, lam_vol=lam_vol,data = data,sort=True) # print the number of samples that make up the highest percentile percent samples and # ratio of the volume of the parameter domain they take up print (num_samples, np.sum(lam_vol_high))
At this point, the only thing that should change in the plotP.* inputs should be either the nbins values or sigma (which influences the kernel density estimation with smaller values implying a density estimate that looks more like a histogram and larger values smoothing out the values more). There are ways to determine "optimal" smoothing parameters (e.g., see CV, GCV, and other similar methods), but we have not incorporated these into the code as lower-dimensional marginal plots have limited value in understanding the structure of a high dimensional non-parametric probability measure. ''' (bins, marginals2D) = plotP.calculate_2D_marginal_probs(P_samples = P, samples = lambda_emulate, lam_domain = lam_domain, nbins = [10, 10]) # smooth 2d marginals probs (optional) #marginals2D = plotP.smooth_marginals_2D(marginals2D,bins, sigma=0.01) # plot 2d marginals probs plotP.plot_2D_marginal_probs(marginals2D, bins, lam_domain, filename = "linearMapValidation", plot_surface=False) # calculate 1d marginal probs (bins, marginals1D) = plotP.calculate_1D_marginal_probs(P_samples = P, samples = lambda_emulate, lam_domain = lam_domain, nbins = [10, 10]) # smooth 1d marginal probs (optional) #marginals1D = plotP.smooth_marginals_1D(marginals1D, bins, sigma=0.01) # plot 1d marginal probs plotP.plot_1D_marginal_probs(marginals1D, bins, lam_domain, filename = "linearMapValidation")
marginals2D = plotP.smooth_marginals_2D(marginals2D, bins, sigma=1.0) # plot 2D marginal probabilities plotP.plot_2D_marginal_probs( marginals2D, bins, lam_domain, filename="contaminant_map", plot_surface=False, lam_ref=ref_lam, lambda_label=labels, interactive=False, ) # calculate 1d marginal probs (bins, marginals1D) = plotP.calculate_1D_marginal_probs(P_samples=P, samples=samples, lam_domain=lam_domain, nbins=20) # smooth 1d marginal probs (optional) marginals1D = plotP.smooth_marginals_1D(marginals1D, bins, sigma=1.0) # plot 1d marginal probs plotP.plot_1D_marginal_probs( marginals1D, bins, lam_domain, filename="contaminant_map", interactive=False, lam_ref=ref_lam, lambda_label=labels ) percentile = 1.0 # Sort samples by highest probability density and sample highest percentile percent samples (num_samples, P_high, samples_high, lam_vol_high, data_high) = postTools.sample_highest_prob( top_percentile=percentile, P_samples=P, samples=samples, lam_vol=lam_vol, data=data, sort=True )
# calculate 2D marginal probabilities (bins, marginals2D) = plotP.calculate_2D_marginal_probs(my_discretization, nbins = 10) # smooth 2D marginal probabilites for plotting (optional) marginals2D = plotP.smooth_marginals_2D(marginals2D, bins, sigma=1.0) # plot 2D marginal probabilities plotP.plot_2D_marginal_probs(marginals2D, bins, my_discretization, filename = "contaminant_map", plot_surface=False, lam_ref = param_ref, lambda_label=labels, interactive=False) # calculate 1d marginal probs (bins, marginals1D) = plotP.calculate_1D_marginal_probs(my_discretization, nbins = 20) # smooth 1d marginal probs (optional) marginals1D = plotP.smooth_marginals_1D(marginals1D, bins, sigma=1.0) # plot 1d marginal probs plotP.plot_1D_marginal_probs(marginals1D, bins, my_discretization, filename = "contaminant_map", interactive=False, lam_ref=param_ref, lambda_label=labels) percentile = 1.0 # Sort samples by highest probability density and sample highest percentile percent samples (num_samples, my_discretization_highP, indices)= postTools.sample_highest_prob( percentile, my_discretization, sort=True)
# plot 2d marginals probs plotP.plot_2D_marginal_probs(marginals2D, bins, input_samples, filename = "validation_raw", file_extension = ".eps", plot_surface=False) # smooth 2d marginals probs (optional) marginals2D = plotP.smooth_marginals_2D(marginals2D, bins, sigma=0.1) # plot 2d marginals probs plotP.plot_2D_marginal_probs(marginals2D, bins, input_samples, filename = "validation_smooth", file_extension = ".eps", plot_surface=False) # calculate 1d marginal probs (bins, marginals1D) = plotP.calculate_1D_marginal_probs(input_samples, nbins = [30, 30]) # plot 2d marginal probs plotP.plot_1D_marginal_probs(marginals1D, bins, input_samples, filename = "validation_raw", file_extension = ".eps") # smooth 1d marginal probs (optional) marginals1D = plotP.smooth_marginals_1D(marginals1D, bins, sigma=0.1) # plot 2d marginal probs plotP.plot_1D_marginal_probs(marginals1D, bins, input_samples, filename = "validation_smooth", file_extension = ".eps")
There are ways to determine "optimal" smoothing parameters (e.g., see CV, GCV, and other similar methods), but we have not incorporated these into the code as lower-dimensional marginal plots have limited value in understanding the structure of a high dimensional non-parametric probability measure. ''' (bins, marginals2D) = \ plotP.calculate_2D_marginal_probs(P_samples=P, samples=lambda_emulate, lam_domain=lam_domain, nbins=10) # smooth 2d marginals probs (optional) # marginals2D = plotP.smooth_marginals_2D(marginals2D,bins, sigma=0.1) # plot 2d marginals probs plotP.plot_2D_marginal_probs(marginals2D, bins, lam_domain, filename="linearMap", plot_surface=False) # calculate 1d marginal probs (bins, marginals1D) = \ plotP.calculate_1D_marginal_probs(P_samples=P, samples=lambda_emulate, lam_domain=lam_domain, nbins=10) # smooth 1d marginal probs (optional) # marginals1D = plotP.smooth_marginals_1D(marginals1D, bins, sigma=0.1) # plot 2d marginal probs plotP.plot_1D_marginal_probs( marginals1D, bins, lam_domain, filename="linearMap")