How to use the geomstats.backend.zeros 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.

geomstats / geomstats / tests / test_hypersphere.py View on Github
``````def test_replace_values(self):
points = gs.ones((3, 5))
new_points = gs.zeros((2, 5))
indcs = [True, False, True]
update = self.space._replace_values(points, new_points, indcs)
self.assertAllClose(update, gs.stack(
[gs.zeros(5), gs.ones(5), gs.zeros(5)]))``````
geomstats / geomstats / geomstats / visualization.py View on Github
``````- the trihedron's base point is the translation of the origin
of R^3 by the translation part of point,
- the trihedron's orientation is the rotation of the canonical basis
of R^3 by the rotation part of point.
"""
point = gs.to_ndarray(point, to_ndim=2)
n_points, _ = point.shape

dim_rotations = SO3_GROUP.dim

if space == 'SE3_GROUP':
rot_vec = point[:, :dim_rotations]
translation = point[:, dim_rotations:]
elif space == 'SO3_GROUP':
rot_vec = point
translation = gs.zeros((n_points, 3))
else:
raise NotImplementedError(
'Trihedrons are only implemented for SO(3) and SE(3).')

rot_mat = SO3_GROUP.matrix_from_rotation_vector(rot_vec)
rot_mat = SO3_GROUP.projection(rot_mat)
basis_vec_1 = gs.array([1., 0., 0.])
basis_vec_2 = gs.array([0., 1., 0.])
basis_vec_3 = gs.array([0., 0., 1.])

trihedrons = []
for i in range(n_points):
trihedron_vec_1 = gs.dot(rot_mat[i], basis_vec_1)
trihedron_vec_2 = gs.dot(rot_mat[i], basis_vec_2)
trihedron_vec_3 = gs.dot(rot_mat[i], basis_vec_3)
trihedron = Trihedron(translation[i],``````
geomstats / geomstats / geomstats / product_riemannian_metric.py View on Github
``````def inner_product_matrix(self, base_point=None):
"""
Matrix of the inner product defined by the Riemmanian metric
at point base_point of the manifold.
"""
matrix = gs.zeros([self.dimension, self.dimension])
b = self.dimensions[0]
matrix[:b, :b] = self.metrics.inner_product_matrix(base_point[0])
dim_current = 0

for i in range(self.n_metrics-1):
dim_current += self.dimensions[i]
dim_next = self.dimensions[i+1]
a = dim_current
b = dim_current + dim_next
matrix_next = self.metrics.inner_product_matrix(base_point[i+1])
matrix[a:b, a:b] = matrix_next

return matrix``````
geomstats / geomstats / geomstats / geometry / special_euclidean.py View on Github
``````Returns
-------
samples : array-like, shape=[..., n + 1, n + 1]
Sample in SE(n).
"""
random_translation = self.translations.random_uniform(n_samples)
random_rotation = self.rotations.random_uniform(n_samples)
random_rotation = gs.to_ndarray(random_rotation, to_ndim=3)

random_translation = gs.to_ndarray(random_translation, to_ndim=2)
random_translation = gs.transpose(gs.to_ndarray(
random_translation, to_ndim=3, axis=1), (0, 2, 1))

random_point = gs.concatenate(
(random_rotation, random_translation), axis=2)
last_line = gs.zeros((n_samples, 1, self.n + 1))
random_point = gs.concatenate(
(random_point, last_line), axis=1)
random_point = gs.assignment(random_point, 1, (-1, -1), axis=0)
if gs.shape(random_point)[0] == 1:
random_point = gs.squeeze(random_point, axis=0)
return random_point
``````
geomstats / geomstats / geomstats / learning / kalman_filter.py View on Github
``````def __init__(self, model):
self.model = model
self.state = model.group.get_identity()
self.covariance = gs.zeros((self.model.dim, self.model.dim))
self.process_noise = gs.zeros(
(self.model.dim_noise, self.model.dim_noise))
self.measurement_noise = gs.zeros(
(self.model.dim_obs, self.model.dim_obs))``````
geomstats / geomstats / geomstats / geometry / beta_distributions.py View on Github
``````def initialize(end_point, start_point):
a0, b0 = start_point
a1, b1 = end_point
lin_init = gs.zeros([2 * self.dim, n_steps])
lin_init[0, :] = gs.linspace(a0, a1, n_steps)
lin_init[1, :] = gs.linspace(b0, b1, n_steps)
lin_init[2, :-1] = (lin_init[0, 1:] - lin_init[0, :-1]) * n_steps
lin_init[3, :-1] = (lin_init[1, 1:] - lin_init[1, :-1]) * n_steps
lin_init[2, -1] = lin_init[2, -2]
lin_init[3, -1] = lin_init[3, -2]
return lin_init``````
geomstats / geomstats / geomstats / special_orthogonal_group.py View on Github
``````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,))

[first_zeros, one, last_zeros], axis=0)

geomstats / geomstats / geomstats / geometry / discrete_curves.py View on Github
``````base_curve_velocity,
base_point[:, :-1, :])
coef_1 = gs.sqrt(base_curve_velocity_norm)
coef_2 = 1 / base_curve_velocity_norm**(3 / 2) * inner_prod

term_1 = gs.einsum('ij,ijk->ijk', coef_1, curve_srv - base_curve_srv)
term_2 = gs.einsum('ij,ijk->ijk', coef_2, base_curve_velocity)
log_derivative = term_1 + term_2

log_starting_points = self.ambient_metric.log(
point=point[:, 0, :], base_point=base_point[:, 0, :])
log_starting_points = gs.transpose(
gs.tile(log_starting_points, (1, 1, 1)), (1, 0, 2))

log_cumsum = gs.hstack(
[gs.zeros((n_curves, 1, n_coords)),
gs.cumsum(log_derivative, -2)])
log = log_starting_points + 1 / (n_sampling_points - 1) * log_cumsum

return log``````
geomstats / geomstats / geomstats / geometry / special_orthogonal.py View on Github
``````Returns
-------
jacobian : array-like, shape=[..., 3, 3]
Jacobian.
"""
geomstats.errors.check_parameter_accepted_values(
left_or_right, 'left_or_right', ['left', 'right'])

point = self.regularize(point)
point = gs.to_ndarray(point, to_ndim=2)
n_points, _ = point.shape

angle = gs.linalg.norm(point, axis=-1)
angle = gs.expand_dims(angle, axis=-1)

coef_1 = gs.zeros([n_points, 1])
coef_2 = gs.zeros([n_points, 1])

# This avoids dividing by 0.

TAYLOR_COEFFS_1_AT_0[0]
+ TAYLOR_COEFFS_1_AT_0[2] * angle ** 2
+ TAYLOR_COEFFS_1_AT_0[4] * angle ** 4
+ TAYLOR_COEFFS_1_AT_0[6] * angle ** 6)

TAYLOR_COEFFS_2_AT_0[0]
+ TAYLOR_COEFFS_2_AT_0[2] * angle ** 2
+ TAYLOR_COEFFS_2_AT_0[4] * angle ** 4``````

geomstats

Geometric statistics on manifolds

MIT