Esempio n. 1
0
 def test_10_bins_2D(self):
     """ 
     Test that 2D marginals sum to 1 and have right shape.
     """
     (bins, marginals) = plotP.calculate_2D_marginal_probs(self.P_samples, self.samples, self.lam_domain, nbins=10)
     nptest.assert_almost_equal(np.sum(marginals[(0, 1)]), 1.0)
     nptest.assert_equal(marginals[(0, 1)].shape, (10, 10))
Esempio n. 2
0
 def test_2D_smoothing(self):
     """
     Test :meth:`bet.postProcess.plotP.smooth_marginals_2D`.
     """
     (bins, marginals) = plotP.calculate_2D_marginal_probs(self.P_samples, self.samples, self.lam_domain, nbins=10)
     marginals_smooth = plotP.smooth_marginals_2D(marginals, bins, sigma=10.0)
     nptest.assert_equal(marginals_smooth[(0, 1)].shape, marginals[(0, 1)].shape)
     nptest.assert_almost_equal(np.sum(marginals_smooth[(0, 1)]), 1.0)
Esempio n. 3
0
    def test_5_10_bins_2D(self):
        """ 
        Test that 1D marginals sum to 1 and have right shape.
        """
        (bins, marginals) = plotP.calculate_2D_marginal_probs(self.samples,
                                                              nbins = [5,10])

        nptest.assert_almost_equal(np.sum(marginals[(0,1)]), 1.0)
        nptest.assert_equal(marginals[(0,1)].shape, (5,10))
Esempio n. 4
0
    def test_1_bin_2D(self):
        """ 
        Test that 2D marginals sum to 1 and have right shape.
        """
        (bins, marginals) = plotP.calculate_2D_marginal_probs(self.samples,
                                                              nbins = 1)

        nptest.assert_almost_equal(marginals[(0,1)][0], 1.0)
        nptest.assert_equal(marginals[(0,1)].shape, (1,1))
Esempio n. 5
0
 def test_10_bins_2D(self):
     """ 
     Test that 2D marginals sum to 1 and have right shape.
     """
     (bins, marginals) = plotP.calculate_2D_marginal_probs(self.P_samples,
                                                           self.samples,
                                                           self.lam_domain,
                                                           nbins=10)
     nptest.assert_almost_equal(np.sum(marginals[(0, 1)]), 1.0)
     nptest.assert_equal(marginals[(0, 1)].shape, (10, 10))
Esempio n. 6
0
    def test_2D_smoothing(self):
        """
        Test :meth:`bet.postProcess.plotP.smooth_marginals_2D`.
        """
        (bins, marginals) = plotP.calculate_2D_marginal_probs(self.samples,
                                                              nbins = 10)

        marginals_smooth = plotP.smooth_marginals_2D(marginals, bins, sigma = 10.0)

        nptest.assert_equal(marginals_smooth[(0,1)].shape,  marginals[(0,1)].shape)
        nptest.assert_almost_equal(np.sum(marginals_smooth[(0,1)]), 1.0)
Esempio n. 7
0
 def test_plot_marginals_2D(self):
     """
     Test :meth:`bet.postProcess.plotP.plot_2D_marginal_probs`.
     """
     (bins, marginals) = plotP.calculate_2D_marginal_probs(self.P_samples, self.samples, self.lam_domain, nbins=10)
     marginals[(0, 1)][0][0] = 0.0
     marginals[(0, 1)][0][1] *= 2.0
     try:
         plotP.plot_2D_marginal_probs(marginals, bins, self.lam_domain, filename="file", interactive=False)
         go = True
         if os.path.exists("file_2D_0_1.eps"):
             os.remove("file_2D_0_1.eps")
     except (RuntimeError, TypeError, NameError):
         go = False
     nptest.assert_equal(go, True)
Esempio n. 8
0
 def test_plot_marginals_2D(self):
     """
     Test :meth:`bet.postProcess.plotP.plot_2D_marginal_probs`.
     """
     (bins, marginals) = plotP.calculate_2D_marginal_probs(self.samples,
                                                           nbins = 10)
     marginals[(0,1)][0][0]=0.0
     marginals[(0,1)][0][1]*=2.0
     try:
         plotP.plot_2D_marginal_probs(marginals, bins, self.samples,
                                      filename = "file", interactive=False)
         go = True
         if os.path.exists("file_2D_0_1.png") and comm.rank == 0:
             os.remove("file_2D_0_1.png")
     except (RuntimeError, TypeError, NameError):
         go = False
     nptest.assert_equal(go, True)
Esempio n. 9
0
'''
Suggested changes for user:

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 generally have limited value in understanding
the structure of a high dimensional non-parametric probability measure.
'''
# calculate 2d marginal probs
(bins, marginals2D) = plotP.calculate_2D_marginal_probs(input_samples,
                                                        nbins = [30, 30])

# 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
Esempio n. 10
0
        Q_ref=Q_ref,
        rect_scale=0.25,
        cells_per_dimension=1)
else:
    simpleFunP.uniform_partition_uniform_distribution_rectangle_scaled(
        data_set=my_discretization,
        Q_ref=Q_ref,
        rect_scale=0.25,
        M=50,
        num_d_emulate=1E5)

# calculate probabilities making Monte Carlo assumption
calculateP.prob(my_discretization)

# 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
Esempio n. 11
0
'''
Suggested changes for user:
    
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,
Esempio n. 12
0
                                                                              center_pts_per_edge = 1)
else:
  (d_distr_prob, d_distr_samples, d_Tree) = simpleFunP.unif_unif(data=data,
                                                                 Q_ref=Q_ref, 
                                                                 M=50, 
                                                                 bin_ratio=bin_ratio, 
                                                                 num_d_emulate=1E5)
  
# calculate probablities making Monte Carlo assumption
(P,  lam_vol, io_ptr) = calculateP.prob(samples=samples,
                                        data=data,
                                        rho_D_M=d_distr_prob,
                                        d_distr_samples=d_distr_samples)

# 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)
Esempio n. 13
0
# calculate 2d marginal probs
'''
Suggested changes for user:
    
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")

Esempio n. 14
0
if deterministic_discretize_D == True:
    (d_distr_prob, d_distr_samples, d_Tree) = simpleFunP.uniform_hyperrectangle(
        data=data, Q_ref=Q_ref, bin_ratio=bin_ratio, center_pts_per_edge=1
    )
else:
    (d_distr_prob, d_distr_samples, d_Tree) = simpleFunP.unif_unif(
        data=data, Q_ref=Q_ref, M=50, bin_ratio=bin_ratio, num_d_emulate=1e5
    )

# calculate probablities making Monte Carlo assumption
(P, lam_vol, io_ptr) = calculateP.prob(
    samples=samples, data=data, rho_D_M=d_distr_prob, d_distr_samples=d_distr_samples
)

# 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,
)
Esempio n. 15
0
  simpleFunP.regular_partition_uniform_distribution_rectangle_scaled(data_set=my_discretization,
                                                                     Q_ref=Q_ref,
                                                                     rect_scale=0.25,
                                                                     cells_per_dimension = 1)
else:
  simpleFunP.uniform_partition_uniform_distribution_rectangle_scaled(data_set=my_discretization,
                                                                     Q_ref=Q_ref,
                                                                     rect_scale=0.25,
                                                                     M=50,
                                                                     num_d_emulate=1E5)
  
# calculate probablities making Monte Carlo assumption
calculateP.prob(my_discretization)

# 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)
Suggested changes for user:

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)
# 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)