Exemplo n.º 1
0
    def test_design_jacobian(self):

        J = GrandMeanDesign(number_of_observations=6).design_jacobian(
            currentstate=None)
        self.assertEqual(SPARSEFORMAT, J.getformat())
        numpy.testing.assert_almost_equal(
            J.todense(), [[1.0], [1.0], [1.0], [1.0], [1.0], [1.0]])
Exemplo n.º 2
0
    def test_init(self):

        obs = TestCombinationElement.SimulatedObservationStructure()
        spde = SphereMeshSPDE(0)
        design = CombinationDesign(
            [GrandMeanDesign(2), LocalDesign(obs, spde)])
        self.assertEqual(2, len(design.designlist))
        self.assertTrue(isinstance(design.designlist[0], GrandMeanDesign))
        self.assertTrue(isinstance(design.designlist[1], LocalDesign))
Exemplo n.º 3
0
    def test_element_states(self):

        obs = TestCombinationElement.SimulatedObservationStructure()
        spde = SphereMeshSPDE(0)
        design = CombinationDesign(
            [GrandMeanDesign(obs),
             LocalDesign(obs, spde)])
        states = design.element_states(
            numpy.array([
                270.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0,
                12.0
            ]))
        self.assertTrue(isinstance(states, list))
        self.assertEqual(2, len(states))
        numpy.testing.assert_equal(states[0], [270.0])
        numpy.testing.assert_equal(
            states[1],
            [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0])
Exemplo n.º 4
0
    def test_design_jacobian(self):

        obs = TestCombinationElement.SimulatedObservationStructure()
        spde = SphereMeshSPDE(1)
        design = CombinationDesign(
            [GrandMeanDesign(2), LocalDesign(obs, spde)])

        # Make a state vector full of a test value 561 which should never actually get accessed
        state_vector = numpy.tile(561.0, (47, 1))

        J = design.design_jacobian(state_vector)

        # A-matrix for comparison
        A = spde.build_A(obs.location_polar_coordinates())

        # Should have ones at start for global mean
        J_expected = numpy.hstack([numpy.array([[1.0], [1.0]]), A.todense()])

        # Check as exepcted
        self.assertEqual(SPARSEFORMAT, J.getformat())
        numpy.testing.assert_equal(J_expected, J.todense())
Exemplo n.º 5
0
    def test_design_function(self):

        obs = TestCombinationElement.SimulatedObservationStructure()
        spde = SphereMeshSPDE(1)
        design = CombinationDesign(
            [GrandMeanDesign(2), LocalDesign(obs, spde)])

        A = spde.build_A(obs.location_polar_coordinates())
        observation_indices, vertex_indices = A.sorted_indices().nonzero()

        # Make a state vector full of a test value 561 which should never actually get accessed
        state_vector = numpy.tile(561.0, (47, 1))

        # Set the grand mean to 20.0
        state_vector[0, 0] = 20.0

        # Choose some numbers for observations of interest
        state_vector[(vertex_indices[0:3] + 1), 0] = 43.5
        state_vector[(vertex_indices[3:6] + 1), 0] = -27.0

        # Should end up with (20.0 + 43.5) and (20.0 - 27.0)
        y = design.design_function(state_vector)
        numpy.testing.assert_almost_equal(y, [[63.5], [-7.0]])
Exemplo n.º 6
0
    def test_design_function(self):

        y = GrandMeanDesign(number_of_observations=3).design_function(
            currentstate=numpy.array([[27.9]]))
        numpy.testing.assert_almost_equal(y, [[27.9], [27.9], [27.9]])
Exemplo n.º 7
0
    def test_design_matrix(self):

        A = GrandMeanDesign(number_of_observations=7).design_matrix()
        self.assertEqual(SPARSEFORMAT, A.getformat())
        numpy.testing.assert_almost_equal(
            A.todense(), [[1.0], [1.0], [1.0], [1.0], [1.0], [1.0], [1.0]])
Exemplo n.º 8
0
    def test_isnonlinear(self):

        self.assertFalse(
            GrandMeanDesign(number_of_observations=3).isnonlinear())
Exemplo n.º 9
0
    def test_design_number_of_state_parameters(self):

        self.assertEqual(
            1,
            GrandMeanDesign(
                number_of_observations=3).design_number_of_state_parameters())