def test_design_jacobian(self): design = LocalDesign(TestLocalElement.SimulatedObservationStructure(), SphereMeshSPDE(level=1)) numpy.testing.assert_equal( design.design_matrix().todense(), design.design_jacobian(currentstate=None).todense())
def test_design_function(self): # Build design design = LocalDesign(TestLocalElement.SimulatedObservationStructure(), SphereMeshSPDE(level=1)) # Indices from design matrix indicate vertex weights that produce observation locations observation_indices, vertex_indices = design.design_matrix( ).sorted_indices().nonzero() # A vector that is 176.0 # except in location 0 where it is 82.0 # and in location 1 where it is -8.888 statevector = numpy.tile(176.0, (42, 1)) statevector[vertex_indices[0:3]] = 272.0 statevector[vertex_indices[3:6]] = -8.888 # Evaluate this - should get the two numbers back numpy.testing.assert_almost_equal(design.design_function(statevector), [[272.0], [-8.888]])
def test_design_matrix(self): spde = SphereMeshSPDE(level=1) design = LocalDesign(TestLocalElement.SimulatedObservationStructure(), spde) A = design.design_matrix() # Check sparse format self.assertEqual(SPARSEFORMAT, A.getformat()) # Shape should be number of obs x number of vertices (basis functions) self.assertEqual((2, 42), A.shape) # Two triangles means 6 points are non-zero self.assertEqual(6, len(A.nonzero()[0])) # Get and check indices of nonzero design elements observation_indices, vertex_indices = A.sorted_indices().nonzero() numpy.testing.assert_equal(observation_indices, [0, 0, 0, 1, 1, 1]) self.assertEqual((6, ), vertex_indices.shape) # Vertices of observations 0 and 1 # (one row per vertex, one column per coordinate) vertices0 = spde.triangulation.points[vertex_indices[0:3], :] vertices1 = spde.triangulation.points[vertex_indices[3:6], :] # Multiply vertices by the weights from A and sum to get cartesian locations testpoint0 = A[0, vertex_indices[0:3]] * vertices0 testpoint1 = A[1, vertex_indices[3:6]] * vertices1 # Check results correspond to original polar coordinates numpy.testing.assert_almost_equal(cartesian_to_polar2d(testpoint0), [[15.0, -7.0]]) numpy.testing.assert_almost_equal(cartesian_to_polar2d(testpoint1), [[5.0, 100.0]])