How to use the geomstats.backend.array function in geomstats

To help you get started, we’ve selected a few geomstats examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github geomstats / geomstats / tests / test_kernel_density_estimation_classifier.py View on Github external
def test_predict_hypersphere_distance(self):
        """Test the 'predict' class method using the hypersphere distance."""
        dim = 2
        space = Hypersphere(dim=dim)
        distance = space.metric.dist
        training_dataset = gs.array(
            [[1, 0, 0],
             [3 ** (1 / 2) / 2, 1 / 2, 0],
             [3 ** (1 / 2) / 2, - 1 / 2, 0],
             [0, 0, 1],
             [0, 1 / 2, 3 ** (1 / 2) / 2],
             [0, - 1 / 2, 3 ** (1 / 2) / 2]])
        labels = [0, 0, 0, 1, 1, 1]
        kde = KernelDensityEstimationClassifier(
            distance=distance)
        kde.fit(training_dataset, labels)
        target_dataset = gs.array(
            [[2 ** (1 / 2) / 2, 2 ** (1 / 2) / 2, 0],
             [0, 1 / 2, - 3 ** (1 / 2) / 2],
             [0, - 1 / 2, - 3 ** (1 / 2) / 2],
             [- 3 ** (1 / 2) / 2, 1 / 2, 0],
             [- 3 ** (1 / 2) / 2, - 1 / 2, 0],
github geomstats / geomstats / tests / test_knn.py View on Github external
def test_predict_proba(self):
        """Test the 'predict_proba' class method."""
        training_dataset = gs.array([[0], [1], [2], [3]])
        labels = [0, 0, 1, 1]
        neigh = KNearestNeighborsClassifier(n_neighbors=self.n_neighbors,
                                            distance=self.distance)
        neigh.fit(training_dataset, labels)
        result = neigh.predict_proba([[0.9]])
        expected = gs.array([[2 / 3, 1 / 3]])
        self.assertAllClose(expected, result, atol=TOLERANCE)
github geomstats / geomstats / tests / test_special_orthogonal3.py View on Github external
def test_random_and_belongs_vectorization(self):
        n_samples = self.n_samples
        points = self.group.random_uniform(n_samples=n_samples)
        result = self.group.belongs(points)
        expected = gs.array([True] * n_samples)
        self.assertAllClose(result, expected)
github geomstats / geomstats / tests / test_kalman_filter.py View on Github external
def test_Localization_propagate(self):
        initial_state = gs.array([0.5, 1., 2.])
        time_step = gs.array([0.5])
        linear_vel = gs.array([1., 0.5])
        angular_vel = gs.array([0.])
        increment = gs.concatenate((
            time_step, linear_vel, angular_vel), axis=0)

        angle = initial_state[0]
        rotation = gs.array([[gs.cos(angle), -gs.sin(angle)],
                             [gs.sin(angle), gs.cos(angle)]])
        next_position = initial_state[1:] + time_step * gs.matmul(
            rotation, linear_vel)
        expected = gs.concatenate((gs.array([angle]), next_position), axis=0)
        result = self.nonlinear_model.propagate(initial_state, increment)
        self.assertAllClose(expected, result)
github geomstats / geomstats / tests / test_radial_kernel_functions.py View on Github external
def test_triangular_radial_kernel(self):
        """Test the triangular radial kernel."""
        distance = gs.array([[1], [2]], dtype=float)
        bandwidth = 2
        weight = triangular_radial_kernel(
            distance=distance,
            bandwidth=bandwidth)
        result = weight
        expected = gs.array([[1 / 2], [0]], dtype=float)
        self.assertAllClose(expected, result, atol=TOLERANCE)
github geomstats / geomstats / tests / test_connection.py View on Github external
def test_metric_matrix(self):
        base_point = gs.array([0., 1., 0., 0.])

        result = self.euc_metric.inner_product_matrix(base_point)
        expected = gs.eye(self.dim)

        self.assertAllClose(result, expected)
github geomstats / geomstats / geomstats / visualization.py View on Github external
def __init__(self, points=None):
        self.center = gs.array([0., 0.])
        self.points = []
        if points is not None:
            self.add_points(points)
github geomstats / geomstats / geomstats / special_orthogonal_group.py View on Github external
def get_mask_i_float(i, n):
    first_zeros = gs.array([])
    if i != 0:
        first_zeros = gs.zeros((i - 1,))
    one = gs.ones((1,))
    last_zeros = gs.array([])
    if i != n - 1:
        last_zeros = gs.zeros((n - i,))

    mask_i_float = gs.concatenate(
        [first_zeros, one, last_zeros], axis=0)

    return mask_i_float
github geomstats / geomstats / examples / plot_geodesics_h2.py View on Github external
def main():
    """Plot the geodesics."""
    initial_point = gs.array([np.sqrt(2), 1., 0.])
    end_point = gs.array([1.5, 1.5])
    end_point = H2.from_coordinates(end_point, 'intrinsic')
    initial_tangent_vec = H2.to_tangent(
        vector=gs.array([3.5, 0.6, 0.8]),
        base_point=initial_point)

    ax = plt.gca()
    plot_geodesic_between_two_points(initial_point,
                                     end_point,
                                     ax=ax)
    plot_geodesic_with_initial_tangent_vector(initial_point,
                                              initial_tangent_vec,
                                              ax=ax)
    plt.show()
github geomstats / geomstats / geomstats / geometry / special_orthogonal3.py View on Github external
Parameters
        ----------
        vec : array-like, shape=[n_samples, dim]

        Returns
        -------
        skew_mat : array-like, shape=[n_samples, n, n]
        """
        n_vecs, vec_dim = gs.shape(vec)

        if self.n == 2:
            vec = gs.tile(vec, [1, 2])
            vec = gs.reshape(vec, (n_vecs, 2))

            id_skew = gs.array(
                gs.tile([[[0., 1.], [-1., 0.]]], (n_vecs, 1, 1)))
            skew_mat = gs.einsum(
                '...ij,...i->...ij', gs.cast(id_skew, gs.float32), vec)

        elif self.n == 3:
            levi_civita_symbol = gs.tile([[
                [[0., 0., 0.],
                 [0., 0., 1.],
                 [0., -1., 0.]],
                [[0., 0., -1.],
                 [0., 0., 0.],
                 [1., 0., 0.]],
                [[0., 1., 0.],
                 [-1., 0., 0.],
                 [0., 0., 0.]]
            ]], (n_vecs, 1, 1, 1))