Exemple #1
0
    def setUp(self):
        self.Lambda_dim = 2
        self.num_qois_return = 2
        self.num_optsets_return = 5
        self.radius = 0.01
        np.random.seed(0)
        self.num_centers = 10
        self.centers = np.random.random((self.num_centers, self.Lambda_dim))
        self.samples = grad.sample_l1_ball(self.centers, self.Lambda_dim + 1,
                                           self.radius)

        self.num_qois = 28
        coeffs = np.zeros((self.Lambda_dim, 2 * self.Lambda_dim))
        coeffs = np.append(coeffs,
                           np.random.random(
                               (self.Lambda_dim,
                                self.num_qois - 3 * self.Lambda_dim)),
                           axis=1)
        self.coeffs = np.append(coeffs, np.eye(self.Lambda_dim), axis=1)

        self.data = self.samples.dot(self.coeffs)
        self.G = grad.calculate_gradients_rbf(self.samples, self.data,
                                              self.centers)

        self.inner_prod_tol = 0.9
        self.cond_tol = np.inf
Exemple #2
0
        def setUp(self):
            self.input_dim = 2
            self.input_set = sample.sample_set(self.input_dim)
            self.input_set_centers = sample.sample_set(self.input_dim)
            self.output_dim_return = 2
            self.num_optsets_return = 5
            self.radius = 0.01
            np.random.seed(0)
            self.num_centers = 10
            self.centers = np.random.random((self.num_centers, self.input_dim))
            self.input_set_centers.set_values(self.centers)
            self.input_set = grad.sample_l1_ball(self.input_set_centers,
                    self.input_dim + 1, self.radius)
            
            self.output_dim = 28
            self.output_set = sample.sample_set(self.output_dim)
            coeffs = np.zeros((self.input_dim, 2*self.input_dim))
            coeffs = np.append(coeffs, np.random.random((self.input_dim,
                self.output_dim - 3 * self.input_dim)), axis=1)
            self.coeffs = np.append(coeffs, np.eye(self.input_dim), axis=1)

            self.output_set.set_values(self.input_set._values.dot(self.coeffs))
            self.my_disc = sample.discretization(self.input_set,
                    self.output_set)
            self.center_disc = grad.calculate_gradients_rbf(\
                self.my_disc, self.num_centers)
            self.input_set_centers = self.center_disc.get_input_sample_set()

            self.inner_prod_tol = 0.9
            self.measskew_tol = np.inf
Exemple #3
0
    def test_calculate_gradients_rbf(self):
        """
        Test :meth:`bet.sensitivity.gradients.calculate_gradients_rbf`.
        """
        self.output_set = sample.sample_set(self.output_dim)
        self.cluster_set = grad.sample_l1_ball(self.input_set_centers,
                self.num_close, self.rvec)
        num_centers = self.input_set_centers.check_num()
        self.output_set.set_values(self.cluster_set._values.dot(self.coeffs))
        self.cluster_disc = sample.discretization(self.cluster_set,
                self.output_set)

        self.center_disc = grad.calculate_gradients_rbf(self.cluster_disc,
                num_centers)

        # Test the method returns the correct size tensor
        self.jacobians = self.center_disc._input_sample_set._jacobians
        self.assertEqual(self.jacobians.shape, (self.num_centers,
            self.output_dim, self.input_dim))

        # Test that each vector is normalized or a zero vector
        normG = np.linalg.norm(self.jacobians, ord=1, axis=2)

        # If its a zero vectors, make it the unit vector in input_dim
        self.jacobians[normG==0] = 1.0/self.input_dim
        nptest.assert_array_almost_equal(np.linalg.norm(self.jacobians, ord=1,
            axis=2), np.ones((self.jacobians.shape[0],
                self.jacobians.shape[1])))
Exemple #4
0
    def setUp(self):
        self.input_dim = 2
        self.input_set = sample.sample_set(self.input_dim)
        self.input_set_centers = sample.sample_set(self.input_dim)
        self.output_dim_return = 2
        self.num_optsets_return = 5
        self.radius = 0.01
        np.random.seed(0)
        self.num_centers = 10
        self.centers = np.random.random((self.num_centers, self.input_dim))
        self.input_set_centers.set_values(self.centers)
        self.input_set = grad.sample_l1_ball(self.input_set_centers,
                                             self.input_dim + 1, self.radius)

        self.output_dim = 28
        self.output_set = sample.sample_set(self.output_dim)
        coeffs = np.zeros((self.input_dim, 2 * self.input_dim))
        coeffs = np.append(coeffs,
                           np.random.random(
                               (self.input_dim,
                                self.output_dim - 3 * self.input_dim)),
                           axis=1)
        self.coeffs = np.append(coeffs, np.eye(self.input_dim), axis=1)

        self.output_set.set_values(self.input_set._values.dot(self.coeffs))
        self.my_disc = sample.discretization(self.input_set, self.output_set)
        self.center_disc = grad.calculate_gradients_rbf(\
            self.my_disc, self.num_centers)
        self.input_set_centers = self.center_disc.get_input_sample_set()

        self.inner_prod_tol = 0.9
        self.measskew_tol = np.inf
Exemple #5
0
    def test_calculate_gradients_rbf_accuracy(self):
        """
        Test :meth:`bet.sensitivity.gradients.calculate_gradients_rbf`.
        """
        self.G_nonlin = grad.calculate_gradients_rbf(self.samples_rbf,
            self.data_nonlin_rbf, normalize=False)

        nptest.assert_array_almost_equal(self.G_nonlin - self.G_exact, 0, decimal = 2)
Exemple #6
0
    def test_calculate_gradients_rbf_accuracy(self):
        """
        Test :meth:`bet.sensitivity.gradients.calculate_gradients_rbf`.
        """
        self.center_disc = grad.calculate_gradients_rbf(self.cluster_disc_rbf,
                                                        normalize=False)
        self.jacobians = self.center_disc._input_sample_set._jacobians

        nptest.assert_allclose(self.jacobians - self.G_exact, 0, atol=2)
Exemple #7
0
    def test_calculate_gradients_rbf_accuracy(self):
        """
        Test :meth:`bet.sensitivity.gradients.calculate_gradients_rbf`.
        """
        self.center_disc = grad.calculate_gradients_rbf(\
            self.cluster_disc_rbf, normalize=False)
        self.jacobians = self.center_disc._input_sample_set._jacobians

        nptest.assert_allclose(self.jacobians - self.G_exact, 0,
                atol=2)
Exemple #8
0
    def test_calculate_gradients_rbf_accuracy(self):
        """
        Test :meth:`bet.sensitivity.gradients.calculate_gradients_rbf`.
        """
        self.G_nonlin = grad.calculate_gradients_rbf(self.samples_rbf,
                                                     self.data_nonlin_rbf,
                                                     normalize=False)

        nptest.assert_array_almost_equal(self.G_nonlin - self.G_exact,
                                         0,
                                         decimal=2)
Exemple #9
0
    def setUp(self):
        self.Lambda_dim = 4
        self.num_qois_return = 4
        self.num_optsets_return = 5
        self.radius = 0.01
        np.random.seed(0)
        self.num_centers = 10
        self.centers = np.random.random((self.num_centers, self.Lambda_dim))
        self.samples = grad.sample_l1_ball(self.centers, self.Lambda_dim + 1, self.radius)

        self.num_qois = 20
        coeffs = np.random.random((self.Lambda_dim, self.num_qois - self.Lambda_dim))
        self.coeffs = np.append(coeffs, np.eye(self.Lambda_dim), axis=1)

        self.data = self.samples.dot(self.coeffs)
        self.G = grad.calculate_gradients_rbf(self.samples, self.data, self.centers)
Exemple #10
0
    def test_calculate_gradients_rbf(self):
        """
        Test :meth:`bet.sensitivity.gradients.calculate_gradients_rbf`.
        """
        self.samples = grad.sample_l1_ball(self.centers, self.num_close,
            self.rvec)
        self.data = self.samples.dot(self.coeffs)
        self.G = grad.calculate_gradients_rbf(self.samples, self.data,
            self.centers)

        # Test the method returns the correct size tensor
        self.assertEqual(self.G.shape, (self.num_centers, self.num_qois,
            self.Lambda_dim))

        # Test that each vector is normalized or a zero vector
        normG = np.linalg.norm(self.G, axis=2)

        # If its a zero vectors, make it the unit vector in Lambda_dim
        self.G[normG==0] = 1.0/np.sqrt(self.Lambda_dim)
        nptest.assert_array_almost_equal(np.linalg.norm(self.G, axis=2),
            np.ones((self.G.shape[0], self.G.shape[1])))
Exemple #11
0
    def test_calculate_gradients_rbf(self):
        """
        Test :meth:`bet.sensitivity.gradients.calculate_gradients_rbf`.
        """
        self.samples = grad.sample_l1_ball(self.centers, self.num_close,
                                           self.rvec)
        self.data = self.samples.dot(self.coeffs)
        self.G = grad.calculate_gradients_rbf(self.samples, self.data,
                                              self.centers)

        # Test the method returns the correct size tensor
        self.assertEqual(self.G.shape,
                         (self.num_centers, self.num_qois, self.Lambda_dim))

        # Test that each vector is normalized or a zero vector
        normG = np.linalg.norm(self.G, ord=1, axis=2)

        # If its a zero vectors, make it the unit vector in Lambda_dim
        self.G[normG == 0] = 1.0 / self.Lambda_dim
        nptest.assert_array_almost_equal(
            np.linalg.norm(self.G, ord=1, axis=2),
            np.ones((self.G.shape[0], self.G.shape[1])))
Exemple #12
0
        def setUp(self):
            self.Lambda_dim = 2
            self.num_qois_return = 2
            self.num_optsets_return = 5
            self.radius = 0.01
            np.random.seed(0)
            self.num_centers = 10
            self.centers = np.random.random((self.num_centers, self.Lambda_dim))
            self.samples = grad.sample_l1_ball(self.centers,
                self.Lambda_dim + 1, self.radius)
            
            self.num_qois = 28
            coeffs = np.zeros((self.Lambda_dim, 2*self.Lambda_dim))
            coeffs = np.append(coeffs, np.random.random((self.Lambda_dim,
                self.num_qois - 3 * self.Lambda_dim)), axis=1)
            self.coeffs = np.append(coeffs, np.eye(self.Lambda_dim), axis=1)

            self.data = self.samples.dot(self.coeffs)
            self.G = grad.calculate_gradients_rbf(self.samples, self.data,
                self.centers)

            self.inner_prod_tol = 0.9
            self.cond_tol = sys.float_info[0]
Exemple #13
0
import bet.Comm as comm
import scipy.io as sio
import numpy as np

# Import the data from the FEniCS simulation (RBF or FFD or CFD clusters)
matfile = sio.loadmat('heatplate_2d_16clustersRBF_1000qoi.mat')
#matfile = sio.loadmat('heatplate_2d_16clustersFFD_1000qoi.mat')
#matfile = sio.loadmat('heatplate_2d_16clustersCFD_1000qoi.mat')

samples = matfile['samples']
data = matfile['data']
Lambda_dim = samples.shape[1]

# Calculate the gradient vectors at each of the 16 centers for each of the
# QoI maps
G = grad.calculate_gradients_rbf(samples, data)
#G = grad.calculate_gradients_ffd(samples, data)
#G = grad.calculate_gradients_cfd(samples, data)

# With a set of QoIs to consider, we check all possible combinations
# of the QoIs and choose the best sets.
indexstart = 0
indexstop = 20
qoiIndices = range(indexstart, indexstop)
condnum_indices_mat = cQoIs.chooseOptQoIs(G, qoiIndices)
qoi1 = condnum_indices_mat[0, 1]
qoi2 = condnum_indices_mat[0, 2]

if comm.rank == 0:
    print 'The 10 smallest condition numbers are in the first column, the \
corresponding sets of QoIs are in the following columns.'
Exemple #14
0
Data_dim = 10
num_samples = 1E5
num_centers = 10

# Let the map Q be a random matrix of size (Data_dim, Lambda_dim)
np.random.seed(0)
Q = np.random.random([Data_dim, Lambda_dim])

# Choose random samples in parameter space to solve the model
samples = np.random.random([num_samples, Lambda_dim])
data = Q.dot(samples.transpose()).transpose()

# Calculate the gradient vectors at some subset of the samples.  Here the
# *normalize* argument is set to *True* because we are using bin_ratio to
# determine the uncertainty in our data.
G = grad.calculate_gradients_rbf(samples, data, centers=samples[:num_centers, :],
    normalize=True)

# With these gradient vectors, we are now ready to choose an optimal set of
# QoIs to use in the inverse problem, based on optimal skewness properites of
# QoI vectors.  The most robust method for this is
# :meth:~bet.sensitivity.chooseQoIs.chooseOptQoIs_large which returns the
# best set of 2, 3, 4 ... until Lambda_dim.  This method returns a list of
# matrices.  Each matrix has 10 rows, the first column representing the
# average condition number of the Jacobian of Q, and the rest of the columns
# the corresponding QoI indices.
best_sets = cQoI.chooseOptQoIs_large(G, volume=False)

###############################################################################

# At this point we have determined the optimal set of QoIs to use in the inverse
# problem.  Now we compare the support of the inverse solution using
Exemple #15
0
input_samples = sample.sample_set(2)
output_samples = sample.sample_set(1000)

# Set the input sample values from the imported file
input_samples.set_values(matfile['samples'])

# Set the data fromthe imported file
output_samples.set_values(matfile['data'])

# Create the cluster discretization
cluster_discretization = sample.discretization(input_samples, output_samples)

# Calculate the gradient vectors at each of the 16 centers for each of the
# QoI maps
if fd_scheme.upper() in ['RBF']:
    center_discretization = grad.calculate_gradients_rbf(
        cluster_discretization, normalize=False)
elif fd_scheme.upper() in ['FFD']:
    center_discretization = grad.calculate_gradients_ffd(
        cluster_discretization)
else:
    center_discretization = grad.calculate_gradients_cfd(
        cluster_discretization)

input_samples_centers = center_discretization.get_input_sample_set()

# Choose a specific set of QoIs to check the average skewness of
index1 = 0
index2 = 4
(specific_skewness, _) = cqoi.calculate_avg_skewness(input_samples_centers,
                                                     qoi_set=[index1, index2])
if comm.rank == 0:
num_samples = 1E5
num_centers = 10

# Let the map Q be a random matrix of size (Data_dim, Lambda_dim)
np.random.seed(0)
Q = np.random.random([Data_dim, Lambda_dim])

# Choose random samples in parameter space to solve the model
samples = np.random.random([num_samples, Lambda_dim])
data = Q.dot(samples.transpose()).transpose()

# Calculate the gradient vectors at some subset of the samples.  Here the
# *normalize* argument is set to *True* because we are using *bin_ratio* to
# determine the uncertainty in our data.
G = grad.calculate_gradients_rbf(samples,
                                 data,
                                 centers=samples[:num_centers, :],
                                 normalize=True)

# With these gradient vectors, we are now ready to choose an optimal set of
# QoIs to use in the inverse problem, based on minimizing the support of the
# inverse solution (volume).  The most robust method for this is
# :meth:~bet.sensitivity.chooseQoIs.chooseOptQoIs_large which returns the
# best set of 2, 3, 4 ... until Lambda_dim.  This method returns a list of
# matrices.  Each matrix has 10 rows, the first column representing the
# expected inverse volume ratio, and the rest of the columns the corresponding
# QoI indices.
best_sets = cQoI.chooseOptQoIs_large(G, volume=True)

###############################################################################

# At this point we have determined the optimal set of QoIs to use in the inverse
Exemple #17
0
import bet.Comm as comm
import scipy.io as sio
import numpy as np

# Import the data from the FEniCS simulation (RBF or FFD or CFD clusters)
matfile = sio.loadmat('heatplate_2d_16clustersRBF_1000qoi.mat')
#matfile = sio.loadmat('heatplate_2d_16clustersFFD_1000qoi.mat')
#matfile = sio.loadmat('heatplate_2d_16clustersCFD_1000qoi.mat')

samples = matfile['samples']
data = matfile['data']
Lambda_dim = samples.shape[1]

# Calculate the gradient vectors at each of the 16 centers for each of the
# QoI maps
G = grad.calculate_gradients_rbf(samples, data)
#G = grad.calculate_gradients_ffd(samples, data)
#G = grad.calculate_gradients_cfd(samples, data)

# With a set of QoIs to consider, we check all possible combinations
# of the QoIs and choose the best sets.
indexstart = 0
indexstop = 20
qoiIndices = range(indexstart, indexstop)
condnum_indices_mat = cQoIs.chooseOptQoIs(G, qoiIndices)
qoi1 = condnum_indices_mat[0, 1]
qoi2 = condnum_indices_mat[0, 2]

if comm.rank==0:
    print 'The 10 smallest condition numbers are in the first column, the \
corresponding sets of QoIs are in the following columns.'
input_samples.set_values(np.random.uniform(0, 1, [np.int(num_samples), input_dim]))

# Make the MC assumption and compute the volumes of each voronoi cell
input_samples.estimate_volume_mc()


# Compute the output values with the map Q
output_samples.set_values(Q.dot(input_samples.get_values().transpose()).\
        transpose())

# Calculate the gradient vectors at some subset of the samples.  Here the
# *normalize* argument is set to *False* because we are using bin_size to
# determine the uncertainty in our data.
cluster_discretization = sample.discretization(input_samples, output_samples)
# We will approximate the jacobian at each of the centers
center_discretization = grad.calculate_gradients_rbf(cluster_discretization,
        num_centers, normalize=False)

# With these gradient vectors, we are now ready to choose an optimal set of
# QoIs to use in the inverse problem, based on minimizing the support of the
# inverse solution (volume).  The most robust method for this is
# :meth:~bet.sensitivity.chooseQoIs.chooseOptQoIs_large which returns the
# best set of 2, 3, 4 ... until input_dim.  This method returns a list of
# matrices.  Each matrix has 10 rows, the first column representing the
# expected inverse volume ratio, and the rest of the columns the corresponding
# QoI indices.
input_samples_center = center_discretization.get_input_sample_set()
best_sets = cqoi.chooseOptQoIs_large(input_samples_center, max_qois_return=5,
    num_optsets_return=2, inner_prod_tol=0.9, measskew_tol=1E2, measure=True)

'''
We see here the expected volume ratios are small.  This number represents the
Exemple #19
0
    np.random.uniform(0, 1, [np.int(num_samples), input_dim]))

# Make the MC assumption and compute the volumes of each voronoi cell
input_samples.estimate_volume_mc()

# Compute the output values with the map Q
output_samples.set_values(
    Q.dot(input_samples.get_values().transpose()).transpose())

# Calculate the gradient vectors at some subset of the samples.  Here the
# *normalize* argument is set to *True* because we are using bin_ratio to
# determine the uncertainty in our data.
cluster_discretization = sample.discretization(input_samples, output_samples)
# We will approximate the jacobian at each of the centers
center_discretization = grad.calculate_gradients_rbf(cluster_discretization,
                                                     num_centers,
                                                     normalize=True)

# With these gradient vectors, we are now ready to choose an optimal set of
# QoIs to use in the inverse problem, based on optimal skewness properites of
# QoI vectors.  The most robust method for this is
# :meth:~bet.sensitivity.chooseQoIs.chooseOptQoIs_large which returns the
# best set of 2, 3, 4 ... until input_dim.  This method returns a list of
# matrices.  Each matrix has 10 rows, the first column representing the
# average skewness of the Jacobian of Q, and the rest of the columns
# the corresponding QoI indices.
input_samples_center = center_discretization.get_input_sample_set()
best_sets = cqoi.chooseOptQoIs_large(input_samples_center, measure=False)

###############################################################################