Exemplo n.º 1
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])))
Exemplo n.º 2
0
    def setUp(self):
        # Define the parameter space (Lambda)
        self.input_dim = 2
        self.input_set_rbf = sample.sample_set(self.input_dim)
        self.input_set_ffd = sample.sample_set(self.input_dim)
        self.input_set_cfd = sample.sample_set(self.input_dim)

        self.input_set_centers = sample.sample_set(self.input_dim)

        self.output_dim = 2
        self.output_set_rbf = sample.sample_set(self.output_dim)
        self.output_set_ffd = sample.sample_set(self.output_dim)
        self.output_set_cfd = sample.sample_set(self.output_dim)

        self.lam_domain = np.zeros((self.input_dim, 2))
        self.lam_domain[:, 0] = np.zeros(self.input_dim)
        self.lam_domain[:, 1] = np.ones(self.input_dim)

        self.input_set_rbf.set_domain(self.lam_domain)
        self.input_set_ffd.set_domain(self.lam_domain)
        self.input_set_cfd.set_domain(self.lam_domain)

        # Choose random centers to cluster points around
        self.num_centers = 100
        np.random.seed(0)
        self.centers = (self.lam_domain[:, 1] - self.lam_domain[:, 0]) * \
            np.random.random((self.num_centers, self.input_dim)) + \
            self.lam_domain[:, 0]
        self.input_set_centers.set_values(self.centers)
        self.num_close = self.input_dim + 1
        self.rvec = 0.01 * np.ones(self.input_dim)

        self.input_set_rbf = grad.sample_l1_ball(self.input_set_centers,
                                                 self.num_close, self.rvec)
        self.input_set_ffd = grad.pick_ffd_points(self.input_set_centers,
                                                  self.rvec)
        self.input_set_cfd = grad.pick_cfd_points(self.input_set_centers,
                                                  self.rvec)

        # Define a vector valued function f : [0,1]x[0,1] -> [x^2, y^2]
        def f(x):
            f = np.zeros(x.shape)
            f[:, 0] = x[:, 0]**2
            f[:, 1] = x[:, 1]**2
            return f

        self.output_set_rbf.set_values(f(self.input_set_rbf.get_values()))
        self.output_set_ffd.set_values(f(self.input_set_ffd.get_values()))
        self.output_set_cfd.set_values(f(self.input_set_cfd.get_values()))
        self.cluster_disc_rbf = sample.discretization(self.input_set_rbf,
                                                      self.output_set_rbf)
        self.cluster_disc_ffd = sample.discretization(self.input_set_ffd,
                                                      self.output_set_ffd)
        self.cluster_disc_cfd = sample.discretization(self.input_set_cfd,
                                                      self.output_set_cfd)

        self.G_exact = np.zeros(
            [self.num_centers, self.output_dim, self.input_dim])
        self.G_exact[:, 0, 0] = 2 * self.centers[:, 0]
        self.G_exact[:, 1, 1] = 2 * self.centers[:, 1]
Exemplo n.º 3
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
Exemplo n.º 4
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
Exemplo n.º 5
0
    def setUp(self):
        # Define the parameter space (Lambda)
        self.input_dim = 2
        self.input_set_rbf = sample.sample_set(self.input_dim)
        self.input_set_ffd = sample.sample_set(self.input_dim)
        self.input_set_cfd = sample.sample_set(self.input_dim)

        self.input_set_centers = sample.sample_set(self.input_dim)

        self.output_dim = 2
        self.output_set_rbf = sample.sample_set(self.output_dim)
        self.output_set_ffd = sample.sample_set(self.output_dim)
        self.output_set_cfd = sample.sample_set(self.output_dim)

        self.lam_domain = np.zeros((self.input_dim, 2))
        self.lam_domain[:, 0] = np.zeros(self.input_dim)
        self.lam_domain[:, 1] = np.ones(self.input_dim)

        self.input_set_rbf.set_domain(self.lam_domain)
        self.input_set_ffd.set_domain(self.lam_domain)
        self.input_set_cfd.set_domain(self.lam_domain)

        # Choose random centers to cluster points around
        self.num_centers = 100
        np.random.seed(0)
        self.centers = (self.lam_domain[:, 1] - self.lam_domain[:, 0]) * \
            np.random.random((self.num_centers, self.input_dim)) + \
            self.lam_domain[:, 0]
        self.input_set_centers.set_values(self.centers)
        self.num_close = self.input_dim + 1
        self.rvec = 0.01 * np.ones(self.input_dim)

        self.input_set_rbf = grad.sample_l1_ball(self.input_set_centers,
                                                 self.num_close, self.rvec)
        self.input_set_ffd = grad.pick_ffd_points(self.input_set_centers,
                                                  self.rvec)
        self.input_set_cfd = grad.pick_cfd_points(self.input_set_centers,
                                                  self.rvec)

        # Define a vector valued function f : [0,1]x[0,1] -> [x^2, y^2]
        def f(x):
            f = np.zeros(x.shape)
            f[:, 0] = x[:, 0]**2
            f[:, 1] = x[:, 1]**2
            return f

        self.output_set_rbf.set_values(f(self.input_set_rbf.get_values()))
        self.output_set_ffd.set_values(f(self.input_set_ffd.get_values()))
        self.output_set_cfd.set_values(f(self.input_set_cfd.get_values()))
        self.cluster_disc_rbf = sample.discretization(
            self.input_set_rbf, self.output_set_rbf)
        self.cluster_disc_ffd = sample.discretization(
            self.input_set_ffd, self.output_set_ffd)
        self.cluster_disc_cfd = sample.discretization(
            self.input_set_cfd, self.output_set_cfd)

        self.G_exact = np.zeros([self.num_centers, self.output_dim,
                                 self.input_dim])
        self.G_exact[:, 0, 0] = 2 * self.centers[:, 0]
        self.G_exact[:, 1, 1] = 2 * self.centers[:, 1]
Exemplo n.º 6
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
Exemplo n.º 7
0
    def test_sample_l1_ball(self):
        """
        Test :meth:`bet.sensitivity.gradients.sample_l1_ball`.
        """
        self.samples = grad.sample_l1_ball(self.centers, self.num_close,
                                           self.rvec)

        # Test that the samples are within max(rvec) of center (l1 dist)
        self.repeat = np.repeat(self.centers, self.num_close, axis=0)
        nptest.assert_array_less(np.linalg.norm(self.samples[self.num_centers:]\
            - self.repeat, 1, axis=1), np.max(self.rvec))

        # Test the method returns the correct dimensions
        self.assertEqual(self.samples.shape, ((self.num_close+1) * \
            self.num_centers, self.Lambda_dim))
Exemplo n.º 8
0
    def test_sample_l1_ball(self):
        """
        Test :meth:`bet.sensitivity.gradients.sample_l1_ball`.
        """
        self.samples = grad.sample_l1_ball(self.centers, self.num_close,
            self.rvec)

        # Test that the samples are within max(rvec) of center (l1 dist)
        self.repeat = np.repeat(self.centers, self.num_close, axis=0)
        nptest.assert_array_less(np.linalg.norm(self.samples[self.num_centers:]\
            - self.repeat, 1, axis=1), np.max(self.rvec))

        # Test the method returns the correct dimensions
        self.assertEqual(self.samples.shape, ((self.num_close+1) * \
            self.num_centers, self.Lambda_dim))
Exemplo n.º 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)
Exemplo n.º 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])))
Exemplo n.º 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])))
Exemplo n.º 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]
Exemplo n.º 13
0
    def setUp(self):
        # Define the parameter space (Lambda)
        self.Lambda_dim = 2
        self.num_qois = 2
        self.lam_domain = np.zeros((self.Lambda_dim, 2))
        self.lam_domain[:, 0] = np.zeros(self.Lambda_dim)
        self.lam_domain[:, 1] = np.ones(self.Lambda_dim)

        # Choose random centers to cluster points around
        self.num_centers = 100
        np.random.seed(0)
        self.centers = (self.lam_domain[:,1] - self.lam_domain[:,0]) * \
            np.random.random((self.num_centers,self.Lambda_dim)) + \
            self.lam_domain[:,0]
        self.num_close = self.Lambda_dim + 1
        self.rvec = 0.01 * np.ones(self.Lambda_dim)

        self.samples_rbf = grad.sample_l1_ball(self.centers, self.num_close,
                                               self.rvec)
        self.samples_ffd = grad.pick_ffd_points(self.centers, self.rvec)
        self.samples_cfd = grad.pick_cfd_points(self.centers, self.rvec)

        # Define a vector valued function f : [0,1]x[0,1] -> [x^2, y^2]
        def f(x):
            f = np.zeros(x.shape)
            f[:, 0] = x[:, 0]**2
            f[:, 1] = x[:, 1]**2
            return f

        self.data_nonlin_rbf = f(self.samples_rbf)
        self.data_nonlin_ffd = f(self.samples_ffd)
        self.data_nonlin_cfd = f(self.samples_cfd)

        self.G_exact = np.zeros(
            [self.num_centers, self.num_qois, self.Lambda_dim])
        self.G_exact[:, 0, 0] = 2 * self.centers[:, 0]
        self.G_exact[:, 1, 1] = 2 * self.centers[:, 1]
Exemplo n.º 14
0
    def setUp(self):
        # Define the parameter space (Lambda)
        self.Lambda_dim = 2
        self.num_qois = 2
        self.lam_domain = np.zeros((self.Lambda_dim, 2))
        self.lam_domain[:,0] = np.zeros(self.Lambda_dim)
        self.lam_domain[:,1] = np.ones(self.Lambda_dim)

        # Choose random centers to cluster points around
        self.num_centers = 100
        np.random.seed(0)
        self.centers = (self.lam_domain[:,1] - self.lam_domain[:,0]) * \
            np.random.random((self.num_centers,self.Lambda_dim)) + \
            self.lam_domain[:,0]
        self.num_close = self.Lambda_dim + 1
        self.rvec = 0.01 * np.ones(self.Lambda_dim)

        self.samples_rbf = grad.sample_l1_ball(self.centers, self.num_close,
            self.rvec)
        self.samples_ffd = grad.pick_ffd_points(self.centers, self.rvec)
        self.samples_cfd = grad.pick_cfd_points(self.centers, self.rvec)

        # Define a vector valued function f : [0,1]x[0,1] -> [x^2, y^2]
        def f(x):
            f = np.zeros(x.shape)
            f[:, 0] = x[:, 0]**2
            f[:, 1] = x[:, 1]**2
            return f

        self.data_nonlin_rbf = f(self.samples_rbf)
        self.data_nonlin_ffd = f(self.samples_ffd)
        self.data_nonlin_cfd = f(self.samples_cfd)

        self.G_exact = np.zeros([self.num_centers, self.num_qois,
            self.Lambda_dim])
        self.G_exact[:, 0, 0] = 2 * self.centers[:, 0]
        self.G_exact[:, 1, 1] = 2 * self.centers[:, 1]