예제 #1
0
    def test_derivative(self):
        """Check that numerical and analytical derivatives of Q match."""

        full_resolution_level = 4
        neighbourhood_level = 2

        full_spde = SphereMeshSPDE(level=full_resolution_level)

        active_triangles = full_spde.neighbours_at_level(
            neighbourhood_level, 0)

        spde = SphereMeshView(full_resolution_level, active_triangles)

        Q = spde.build_Q_stationary(numpy.log(1.0), numpy.log(1.0), 2)

        epsilon = 0.000001

        expected_dQ0 = \
            ((spde.build_Q_stationary(numpy.log(1.0)+epsilon, numpy.log(1.0), 2) -
              spde.build_Q_stationary(numpy.log(1.0)-epsilon, numpy.log(1.0), 2)) / (2.0 * epsilon)).todense()

        expected_dQ1 = \
            ((spde.build_Q_stationary(numpy.log(1.0), numpy.log(1.0)+epsilon, 2) -
              spde.build_Q_stationary(numpy.log(1.0), numpy.log(1.0)-epsilon, 2)) / (2.0 * epsilon)).todense()

        dQ0 = spde.build_dQdp_stationary(numpy.log(1.0), numpy.log(1.0), 2,
                                         0).todense()
        dQ1 = spde.build_dQdp_stationary(numpy.log(1.0), numpy.log(1.0), 2,
                                         1).todense()

        # print numpy.abs(dQ0 - expected_dQ0).ravel().max() / numpy.abs(expected_dQ0).ravel().max()
        # print numpy.abs(dQ1 - expected_dQ1).ravel().max() / numpy.abs(expected_dQ1).ravel().max()

        numpy.testing.assert_almost_equal(dQ0, expected_dQ0, decimal=7)
        numpy.testing.assert_almost_equal(dQ1, expected_dQ1, decimal=7)
예제 #2
0
def mesh_neighbour_demo():

    import advanced_standard.stats.spde.convex
    import matplotlib.pyplot as plt

    spde_level = 3
    neighbour_level = 1
    region_centre_index = 0

    my_spde = SphereMeshSPDE(level=spde_level, project_onto_sphere=True)
    in_indices = my_spde.neighbours_at_level(neighbour_level,
                                             region_centre_index)
    vertex_indices = np.unique(my_spde.triangulation.triangles[in_indices,
                                                               1:].ravel())

    convex_mesh_triangulation = advanced_standard.stats.spde.convex.ConvexMeshSPDE(
        my_spde.triangulation.vertices[vertex_indices, :])
    convex_mesh_triangulation.plot_triangles(linewidths=0.5)

    #my_spde.plot_triangles()

    my_spde = SphereMeshSPDE(level=neighbour_level, project_onto_sphere=True)
    in_indices = my_spde.neighbours_at_level(neighbour_level,
                                             region_centre_index)
    vertex_indices = np.unique(my_spde.triangulation.triangles[in_indices,
                                                               1:].ravel())

    ax = plt.gca()
    convex_mesh_triangulation = advanced_standard.stats.spde.convex.ConvexMeshSPDE(
        my_spde.triangulation.vertices[vertex_indices, :])
    convex_mesh_triangulation.plot_triangles(colors='r', ax=ax, linewidths=1.0)

    centre_vertex_indices = np.unique(
        my_spde.triangulation.triangles[region_centre_index, 1:].ravel())
    centre_vertex_triangulation = advanced_standard.stats.spde.convex.ConvexMeshSPDE(
        my_spde.triangulation.vertices[centre_vertex_indices, :])
    centre_vertex_triangulation.plot_triangles(colors='b',
                                               ax=ax,
                                               linewidths=1.5)
    plt.show()
예제 #3
0
    def __init__(self,
                 level,
                 neighbourhood_level,
                 centre_index_at_level,
                 sparse_format='csr'):

        full_sphere = SphereMeshSPDE(level)

        active_triangle_indices = full_sphere.neighbours_at_level(
            neighbourhood_level=neighbourhood_level,
            centre_index_at_level=centre_index_at_level)

        super(SphereMeshViewLocal, self).__init__(level,
                                                  active_triangle_indices,
                                                  sparse_format=sparse_format)