示例#1
0
    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)
示例#2
0
 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)
示例#3
0
 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)
示例#4
0
                             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")




示例#5
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")
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,
                             file_extension=".eps")
示例#7
0
########################################
# 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, :],
                             file_extension=".eps")
示例#8
0
                             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)

# 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,
示例#9
0
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")
示例#10
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))

# Propogate the probability measure through a different QoI map
(_, P_pred, _, _ , data_pred)= postTools.sample_highest_prob(top_percentile=percentile, P_samples=P, samples=samples, lam_vol=lam_vol,data = dataf[:,7],sort=True)

# Plot 1D pdf of predicted QoI
# calculate 1d marginal probs
(bins_pred, marginals1D_pred) = plotP.calculate_1D_marginal_probs(P_samples = P_pred, samples = data_pred, lam_domain = np.array([[np.min(data_pred),np.max(data_pred)]]), nbins = 20)
示例#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")





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





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



示例#14
0
    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))

# Propogate the probability measure through a different QoI map
(_, P_pred, _, _, data_pred) = postTools.sample_highest_prob(
    top_percentile=percentile, P_samples=P, samples=samples, lam_vol=lam_vol, data=dataf[:, 7], sort=True
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")
示例#16
0
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)

# 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(my_discretization_highP._input_sample_set.get_volumes()))

# Choose unused QoI as prediction QoI and propagate measure onto predicted QoI data space
QoI_indices_predict = np.array([7])
output_samples_predict = samp.sample_set(QoI_indices_predict.size)