Example #1
0
    def check_show_data_domain_2D(self, ref_markers, ref_colors, triangles,
                                  save, filenames):
        """
        Check to see that the
        :meth:`bet.postTools.plotDomains.show_data_domain_2D` ran
        without generating an error.
        """
        Q_ref = self.disc._output_sample_set.get_values()[:, [0, 1]]
        Q_ref = Q_ref[[1, 4], :]

        data_obj_temp = sample.sample_set(2)
        data_obj_temp.set_values(
            self.disc._output_sample_set.get_values()[:, [0, 1]])
        disc_obj_temp = sample.discretization(
            self.disc._input_sample_set, data_obj_temp)

        try:
            plotDomains.show_data_domain_2D(
                disc_obj_temp, Q_ref,
                ref_markers, ref_colors, triangles=triangles, save=save,
                filenames=filenames)
            go = True
        except (RuntimeError, TypeError, NameError):
            go = False

        nptest.assert_equal(go, True)
Example #2
0
 def check_show_data_domain_2D(self, ref_markers, ref_colors, triangles,
         save, filenames):
     """
     Check to see that the
     :meth:`bet.postTools.plotDomains.show_data_domain_2D` ran
     without generating an error.
     """
     Q_ref = self.data[:, [0, 1]]
     Q_ref = Q_ref[[1,4],:]
     print Q_ref.shape
     data = self.data[:, [0, 1]]
     try:
         plotDomains.show_data_domain_2D(self.samples, data, Q_ref,
                 ref_markers, ref_colors, triangles=triangles, save=save,
                 filenames=filenames)
         go = True
     except (RuntimeError, TypeError, NameError):
         go = False
     nptest.assert_equal(go, True) 
Example #3
0
 def check_show_data_domain_2D(self, ref_markers, ref_colors, triangles,
                               save, filenames):
     """
     Check to see that the
     :meth:`bet.postTools.plotDomains.show_data_domain_2D` ran
     without generating an error.
     """
     Q_ref = self.data[:, [0, 1]]
     Q_ref = Q_ref[[1, 4], :]
     print Q_ref.shape
     data = self.data[:, [0, 1]]
     try:
         plotDomains.show_data_domain_2D(self.samples,
                                         data,
                                         Q_ref,
                                         ref_markers,
                                         ref_colors,
                                         triangles=triangles,
                                         save=save,
                                         filenames=filenames)
         go = True
     except (RuntimeError, TypeError, NameError):
         go = False
     nptest.assert_equal(go, True)
Try different reference parameters.
'''
# Define the reference parameter
param_ref = np.array([0.5, 0.5, 0.5])
#param_ref = np.array([0.75, 0.75, 0.5])
#param_ref = np.array([0.75, 0.75, 0.75])
#param_ref = np.array([0.5, 0.5, 0.75])

# Compute the reference QoI
Q_ref =  my_model(param_ref)

# Create some plots of input and output discretizations
plotD.scatter_2D_multi(input_samples, ref_sample= param_ref, showdim = 'all',
                       filename = 'linearMap_ParameterSamples',
                       file_extension = '.eps')
plotD.show_data_domain_2D(my_discretization, Q_ref = Q_ref, file_extension='.eps')

'''
Suggested changes for user:

Try different ways of discretizing the probability measure on D defined as a uniform
probability measure on a rectangle (since D is 2-dimensional) centered at Q_ref whose
size is determined by scaling the circumscribing box of D.
'''
randomDataDiscretization = False
if randomDataDiscretization is False:
    simpleFunP.regular_partition_uniform_distribution_rectangle_scaled(
        data_set=my_discretization, Q_ref=Q_ref, rect_scale=0.25,
        cells_per_dimension = 3)
else:
    simpleFunP.uniform_partition_uniform_distribution_rectangle_scaled(
# Define the reference parameter
param_ref = np.array([5.5, 4.5])
#param_ref = np.array([4.5, 3.0])
#param_ref = np.array([3.5, 1.5])

# Compute the reference QoI
Q_ref = my_model(param_ref)

# Create some plots of input and output discretizations
plotD.scatter_2D(input_samples,
                 ref_sample=param_ref,
                 filename='nonlinearMapParameterSamples',
                 file_extension='.eps')
if Q_ref.size == 2:
    plotD.show_data_domain_2D(my_discretization,
                              Q_ref=Q_ref,
                              file_extension=".eps")
'''
Suggested changes for user:

Try different ways of discretizing the probability measure on D defined
as a uniform probability measure on a rectangle or interval depending
on choice of QoI_num in myModel.py.
'''
randomDataDiscretization = False
if randomDataDiscretization is False:
    simpleFunP.regular_partition_uniform_distribution_rectangle_scaled(
        data_set=my_discretization,
        Q_ref=Q_ref,
        rect_scale=0.25,
        cells_per_dimension=3)
Example #6
0
def rho_D(outputs):
    rho_left = np.repeat([Q_ref - .5 * bin_size], outputs.shape[0], 0)
    rho_right = np.repeat([Q_ref + .5 * bin_size], outputs.shape[0], 0)
    rho_left = np.all(np.greater_equal(outputs, rho_left), axis=1)
    rho_right = np.all(np.less_equal(outputs, rho_right), axis=1)
    inside = np.logical_and(rho_left, rho_right)
    max_values = np.repeat(maximum, outputs.shape[0], 0)
    return inside.astype('float64') * max_values


# Read in points_ref and plot results
p_ref = mdat['points_true']
p_ref = p_ref[5:7, 15]

# Show the samples in the parameter space
pDom.show_param(samples=points.transpose(), data=Q, rho_D=rho_D, p_ref=p_ref)
# Show the corresponding samples in the data space
pDom.show_data(data=Q, rho_D=rho_D, Q_ref=Q_ref)
# Show the data domain that corresponds with the convex hull of samples in the
# parameter space
pDom.show_data_domain_2D(samples=points.transpose(), data=Q, Q_ref=Q_ref)

# Show multiple data domains that correspond with the convex hull of samples in
# the parameter space
pDom.show_data_domain_multi(samples=points.transpose(),
                            data=mdat['Q'],
                            Q_ref=mdat['Q_true'][15],
                            Q_nums=[1, 2, 5],
                            showdim='all')
Example #7
0
kernel_rD = asam.rhoD_kernel(maximum, rho_D)

# Create sampler
chain_length = 125
num_chains = 80
num_samples = chain_length*num_chains
sampler = asam.sampler(num_samples, chain_length, model)

# Set minima and maxima
lam_domain = np.array([[-900, 1500], [.07, .15], [.1, .2]])

# Get samples
inital_sample_type = "lhs"
(my_disc, all_step_ratios) = sampler.generalized_chains(lam_domain,
        transition_set, kernel_rD, sample_save_file, inital_sample_type)

# Read in points_ref and plot results
ref_sample = mdat['points_true']
ref_sample = ref_sample[:, 14]

# Show the samples in the parameter space
pDom.scatter_rhoD(my_disc, rho_D=rho_D, ref_sample=ref_sample, io_flag='input')
# Show the corresponding samples in the data space
pDom.scatter_rhoD(my_disc, rho_D=rho_D, ref_sample=Q_ref, io_flag='output')
# Show the data domain that corresponds with the convex hull of samples in the
# parameter space
pDom.show_data_domain_2D(my_disc, Q_ref=Q_ref)

# Show multiple data domains that correspond with the convex hull of samples in
# the parameter space
pDom.show_data_domain_multi(my_disc, Q_ref=Q_ref, showdim='all')
Example #8
0
# Create sampler
chain_length = 125
num_chains = 80
num_samples = chain_length * num_chains
sampler = asam.sampler(num_samples, chain_length, model)

# Set minima and maxima
lam_domain = np.array([[.07, .15], [.1, .2]])

# Get samples
inital_sample_type = "lhs"
(my_disc,
 all_step_ratios) = sampler.generalized_chains(lam_domain, transition_set,
                                               kernel_rD, sample_save_file,
                                               inital_sample_type)

# Read in points_ref and plot results
ref_sample = mdat['points_true']
ref_sample = ref_sample[5:7, 15]

# Show the samples in the parameter space
pDom.scatter_rhoD(my_disc, rho_D=rho_D, ref_sample=ref_sample, io_flag='input')
# Show the corresponding samples in the data space
pDom.scatter_rhoD(my_disc, rho_D=rho_D, ref_sample=Q_ref, io_flag='output')
# Show the data domain that corresponds with the convex hull of samples in the
# parameter space
pDom.show_data_domain_2D(my_disc, Q_ref=Q_ref)
# Show multiple data domains that correspond with the convex hull of samples in
# the parameter space
pDom.show_data_domain_multi(my_disc, Q_ref=Q_ref, showdim='all')
Suggested changes for user:

Try different reference parameters.
'''
# Define the reference parameter
#param_ref = np.zeros((1,num_KL_terms))
param_ref = np.ones((1,num_KL_terms))

# Compute the reference QoI
Q_ref = my_model(param_ref)

# Create some plots of input and output discretizations
plotD.scatter_2D(input_samples, ref_sample=param_ref[0,:],
                 filename='FEniCS_ParameterSamples.eps')
if Q_ref.size == 2:
    plotD.show_data_domain_2D(my_discretization, Q_ref=Q_ref[0,:],
            file_extension="eps")

'''
Suggested changes for user:

Try different ways of discretizing the probability measure on D defined
as a uniform probability measure on a rectangle or interval depending
on choice of QoI_num in myModel.py.
'''
randomDataDiscretization = False
if randomDataDiscretization is False:
    simpleFunP.regular_partition_uniform_distribution_rectangle_scaled(
        data_set=my_discretization, Q_ref=Q_ref[0,:], rect_scale=0.1,
        cells_per_dimension=3)
else:
    simpleFunP.uniform_partition_uniform_distribution_rectangle_scaled(
Example #10
0
bin_ratio = 0.15
bin_size = (np.max(Q, 0)-np.min(Q, 0))*bin_ratio

# Create kernel
maximum = 1/np.product(bin_size)
def rho_D(outputs):
    rho_left = np.repeat([Q_ref-.5*bin_size], outputs.shape[0], 0)
    rho_right = np.repeat([Q_ref+.5*bin_size], outputs.shape[0], 0)
    rho_left = np.all(np.greater_equal(outputs, rho_left), axis=1)
    rho_right = np.all(np.less_equal(outputs, rho_right), axis=1)
    inside = np.logical_and(rho_left, rho_right)
    max_values = np.repeat(maximum, outputs.shape[0], 0)
    return inside.astype('float64')*max_values

# Read in points_ref and plot results
p_ref = mdat['points_true']
p_ref = p_ref[5:7, 15]

# Show the samples in the parameter space
pDom.show_param(samples=points.transpose(), data=Q, rho_D=rho_D, p_ref=p_ref)
# Show the corresponding samples in the data space
pDom.show_data(data=Q, rho_D=rho_D, Q_ref=Q_ref)
# Show the data domain that corresponds with the convex hull of samples in the
# parameter space
pDom.show_data_domain_2D(samples=points.transpose(), data=Q, Q_ref=Q_ref)

# Show multiple data domains that correspond with the convex hull of samples in
# the parameter space
pDom.show_data_domain_multi(samples=points.transpose(), data=mdat['Q'],
        Q_ref=mdat['Q_true'][15], Q_nums=[1,2,5], showdim='all')