Пример #1
0
    def test_get_rbf_matrix(self):
        """Test basic properties of the RBF matrix (e.g. symmetry, size).

        Verify that the RBF matrix is symmetric and it has the correct
        size for all types of RBF.
        """
        settings = RbfoptSettings()
        for i in range(50):
            dim = random.randint(1, 20)
            num_points = random.randint(10, 50)
            node_pos = np.array(
                [[random.uniform(-100, 100) for j in range(dim)]
                 for k in range(num_points)])
            # Possible shapes of the matrix
            for rbf_type in self.rbf_types:
                settings.rbf = rbf_type
                mat = ru.get_rbf_matrix(settings, dim, num_points, node_pos)
                self.assertIsInstance(mat, np.matrix)
                self.assertAlmostEqual(np.max(mat - mat.transpose()),
                                       0.0,
                                       msg='RBF matrix is not symmetric')
                size = num_points + 1
                if (ru.get_degree_polynomial(settings) > 0):
                    size += dim**ru.get_degree_polynomial(settings)
                self.assertEqual(mat.shape, (size, size))
        # Check that exception is raised for unknown RBF types
        settings.rbf = 'unknown'
        self.assertRaises(ValueError, ru.get_rbf_matrix, settings, dim,
                          num_points, node_pos)
Пример #2
0
 def test_get_degree_polynomial(self):
     """Verify that the degree is always between 0 and 1."""
     settings = RbfoptSettings()
     for rbf_type in self.rbf_types:
         settings.rbf = rbf_type
         degree = ru.get_degree_polynomial(settings)
         self.assertTrue(degree == 0 or degree == 1)
Пример #3
0
 def test_get_size_P_matrix(self):
     """Verify that the size is always between 0 and n+1."""
     settings = RbfoptSettings()
     for rbf_type in self.rbf_types:
         settings.rbf = rbf_type
         for n in range(20):
             size = ru.get_size_P_matrix(settings, n)
             self.assertTrue(0 <= size <= n + 1)
Пример #4
0
 def test_get_rbf_function(self):
     """Check that all RBFs are properly computed at 0 and at 1."""
     settings = RbfoptSettings()
     # Set up values of the RBF at 0 and at 1
     rbf_values = dict()
     rbf_values['linear'] = (0.0, 1.0)
     rbf_values['multiquadric'] = (1.0, math.sqrt(1 + 1.0))
     rbf_values['cubic'] = (0.0, 1.0)
     rbf_values['thin_plate_spline'] = (0.0, 0.0)
     for rbf_type in self.rbf_types:
         settings.rbf = rbf_type
         rbf = ru.get_rbf_function(settings)
         rbf_at_0, rbf_at_1 = rbf_values[rbf_type]
         msg = 'RBF {:s} is not {:f} at 0'.format(rbf_type, rbf_at_0)
         self.assertEqual(rbf_at_0, rbf(0.0), msg=msg)
         msg = 'RBF {:s} is not {:f} at 1'.format(rbf_type, rbf_at_1)
         self.assertEqual(rbf_at_1, rbf(1.0), msg=msg)