Ejemplo n.º 1
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)
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
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
(bins, marginals1D) = plotP.calculate_1D_marginal_probs(input_samples,
                                                        nbins = [30, 30])

# plot 2d marginal probs
Ejemplo n.º 4
0
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 = [10, 10, 10])

# smooth 2d marginals probs (optional)
marginals2D = plotP.smooth_marginals_2D(marginals2D, bins, sigma=0.2)

# plot 2d marginals probs
plotP.plot_2D_marginal_probs(marginals2D, bins, input_samples, filename = "linearMap",
                             lam_ref=param_ref, file_extension = ".eps", plot_surface=False)

# calculate 1d marginal probs
(bins, marginals1D) = plotP.calculate_1D_marginal_probs(input_samples,
                                                        nbins = [10, 10, 10])
# smooth 1d marginal probs (optional)
marginals1D = plotP.smooth_marginals_1D(marginals1D, bins, sigma=0.2)
# plot 2d marginal probs
plotP.plot_1D_marginal_probs(marginals1D, bins, input_samples, filename = "linearMap",
                             lam_ref=param_ref, 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 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=[20, 20])
# smooth 2d marginals probs (optional)
marginals2D = plotP.smooth_marginals_2D(marginals2D, bins, sigma=0.5)

# plot 2d marginals probs
plotP.plot_2D_marginal_probs(marginals2D,
                             bins,
                             input_samples,
                             filename="nomlinearMap",
                             lam_ref=param_ref,
                             file_extension=".eps",
                             plot_surface=False)

# calculate 1d marginal probs
(bins, marginals1D) = plotP.calculate_1D_marginal_probs(input_samples,
                                                        nbins=[20, 20])
# smooth 1d marginal probs (optional)
marginals1D = plotP.smooth_marginals_1D(marginals1D, bins, sigma=0.5)
# plot 2d marginal probs
plotP.plot_1D_marginal_probs(marginals1D,
                             bins,
                             input_samples,
                             filename="nonlinearMap",
                             lam_ref=param_ref,
Ejemplo n.º 6
0
calculateP.prob(my_discretization)

########################################
# Post-process the results
########################################
# calculate 2d marginal probs
(bins, marginals2D) = plotP.calculate_2D_marginal_probs(input_samples,
                                                        nbins=20)
# smooth 2d marginals probs (optional)
marginals2D = plotP.smooth_marginals_2D(marginals2D, bins, sigma=0.5)

# plot 2d marginals probs
plotP.plot_2D_marginal_probs(marginals2D,
                             bins,
                             input_samples,
                             filename="FEniCS",
                             lam_ref=param_ref[0, :],
                             file_extension=".eps",
                             plot_surface=False)

# calculate 1d marginal probs
(bins, marginals1D) = plotP.calculate_1D_marginal_probs(input_samples,
                                                        nbins=20)
# smooth 1d marginal probs (optional)
marginals1D = plotP.smooth_marginals_1D(marginals1D, bins, sigma=0.5)
# plot 1d marginal probs
plotP.plot_1D_marginal_probs(marginals1D,
                             bins,
                             input_samples,
                             filename="FEniCS",
                             lam_ref=param_ref[0, :],
Ejemplo n.º 7
0
# 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
(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,
Ejemplo n.º 8
0
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")
Ejemplo n.º 9
0
# 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)
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)
Ejemplo n.º 10
0
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 = [20, 20])
# smooth 2d marginals probs (optional)
marginals2D = plotP.smooth_marginals_2D(marginals2D,bins, sigma=0.5)

# plot 2d marginals probs
plotP.plot_2D_marginal_probs(marginals2D, bins, lam_domain, filename = "nonlinearMap",
                             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 = [20, 20])
# smooth 1d marginal probs (optional)
marginals1D = plotP.smooth_marginals_1D(marginals1D, bins, sigma=0.5)
# plot 1d marginal probs
plotP.plot_1D_marginal_probs(marginals1D, bins, lam_domain, filename = "nonlinearMap")





Ejemplo n.º 11
0
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")





        M=50, num_d_emulate=1E5)

# calculate probablities
calculateP.prob(my_discretization)

########################################
# Post-process the results
########################################
# calculate 2d marginal probs
(bins, marginals2D) = plotP.calculate_2D_marginal_probs(input_samples,
                                                        nbins=20)
# smooth 2d marginals probs (optional)
marginals2D = plotP.smooth_marginals_2D(marginals2D, bins, sigma=0.5)

# plot 2d marginals probs
plotP.plot_2D_marginal_probs(marginals2D, bins, input_samples, filename="FEniCS",
                             lam_ref=param_ref[0,:], file_extension=".eps",
                             plot_surface=False)

# calculate 1d marginal probs
(bins, marginals1D) = plotP.calculate_1D_marginal_probs(input_samples,
                                                        nbins=20)
# smooth 1d marginal probs (optional)
marginals1D = plotP.smooth_marginals_1D(marginals1D, bins, sigma=0.5)
# plot 2d marginal probs
plotP.plot_1D_marginal_probs(marginals1D, bins, input_samples, filename="FEniCS",
                             lam_ref=param_ref[0,:], file_extension=".eps")



Ejemplo n.º 13
0
(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)
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
)
Ejemplo n.º 14
0
calculateP.prob(my_discretization)


########################################
# Post-process the results
########################################

figurepath="figures_linearode/decay-"+str(decaynum)

if not os.path.isdir(figurepath):
    os.makedirs(figurepath)

#calculate 2d marginal probs
(bins, marginals2D) = plotP.calculate_2D_marginal_probs(input_samples,
                                                        nbins = 10)
plotP.plot_2D_marginal_probs(marginals2D, bins, input_samples, filename = figurepath+"/linearode_IVP_reg",
                             lam_ref=param_ref[0,:], file_extension = ".eps", plot_surface=False)

# smooth 2d marginals probs (optional)
#marginals2D = plotP.smooth_marginals_2D(marginals2D, bins,
#                                        sigma=0.2*(parameter_domain[:,1]-parameter_domain[:,0]))

# plot 2d marginals probs
#plotP.plot_2D_marginal_probs(marginals2D, bins, input_samples, filename = "linear_ODE_IVP",
#                             lam_ref=param_ref[0,:], file_extension = ".eps", plot_surface=False)

# # calculate 1d marginal probs
# (bins, marginals1D) = plotP.calculate_1D_marginal_probs(input_samples,
#                                                         nbins = 10)
# # smooth 1d marginal probs (optional)
# marginals1D = plotP.smooth_marginals_1D(marginals1D, bins,
#                                         sigma=0.2 * (parameter_domain[:, 1] - parameter_domain[:, 0]))
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=[20, 20])
# smooth 2d marginals probs (optional)
marginals2D = plotP.smooth_marginals_2D(marginals2D, bins, sigma=0.5)

# plot 2d marginals probs
plotP.plot_2D_marginal_probs(marginals2D,
                             bins,
                             lam_domain,
                             filename="nonlinearMap",
                             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=[20, 20])
# smooth 1d marginal probs (optional)
marginals1D = plotP.smooth_marginals_1D(marginals1D, bins, sigma=0.5)
# plot 1d marginal probs
plotP.plot_1D_marginal_probs(marginals1D,
                             bins,
                             lam_domain,
                             filename="nonlinearMap")
Ejemplo n.º 16
0
                                                                     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)
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)