8000 clean test_spd_matrices with parametrization by SaitejaUtpala · Pull Request #1263 · geomstats/geomstats · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

clean test_spd_matrices with parametrization #1263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 80 commits into from
Jan 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
451ced6
cleaning spd
SaitejaUtpala Dec 30, 2021
256dfed
fix bugs
SaitejaUtpala Dec 30, 2021
ea31151
blacken
SaitejaUtpala Dec 30, 2021
95c3e25
add numerical test cases for SPDAffine log,exp
SaitejaUtpala Dec 30, 2021
fda53a1
fix bug in test_diff_cf
SaitejaUtpala Dec 30, 2021
e250ca0
make tests pass
SaitejaUtpala Dec 30, 2021
f445b41
make tests pass
SaitejaUtpala Dec 30, 2021
49ec5bd
make tests pass
SaitejaUtpala Dec 30, 2021
6cd3720
add numerical tests for BW metric
SaitejaUtpala Dec 30, 2021
63ae457
add more numerical tests
SaitejaUtpala Dec 30, 2021
d5c86ca
add more numerical tests
SaitejaUtpala Dec 31, 2021
cdf8acd
add more numerical tests
SaitejaUtpala Dec 31, 2021
094dc50
BW squared dist
SaitejaUtpala Dec 31, 2021
02a3d31
composition
SaitejaUtpala Dec 31, 2021
89bc9c9
composition
SaitejaUtpala Dec 31, 2021
6e222c7
checkpoint
SaitejaUtpala Jan 2, 2022
9af13e5
add pytest.ini
SaitejaUtpala Jan 2, 2022
c9f067b
blacken
SaitejaUtpala Jan 3, 2022
2bc9bc4
commit matrices
SaitejaUtpala Jan 3, 2022
6638513
add
SaitejaUtpala Jan 3, 2022
7a81f2d
fix it
SaitejaUtpala Jan 4, 2022
83adfef
complete log_exp_composition
SaitejaUtpala Jan 4, 2022
0e442d9
configure
SaitejaUtpala Jan 4, 2022
94c0c47
configure
SaitejaUtpala Jan 4, 2022
3c86c83
remove matrices stuff
SaitejaUtpala Jan 4, 2022
73a7c19
reduce n
SaitejaUtpala Jan 4, 2022
89f59e6
add documentation
SaitejaUtpala Jan 5, 2022
4328d8c
stash
SaitejaUtpala Jan 7, 2022
b4e5e5c
blacken
SaitejaUtpala Jan 8, 2022
5704e80
add
SaitejaUtpala Jan 8, 2022
4b08d80
add more tests
SaitejaUtpala Jan 9, 2022
833920a
add LT
SaitejaUtpala Jan 9, 2022
92d169a
add PLT
SaitejaUtpala Jan 9, 2022
218668e
add MatsV1
SaitejaUtpala Jan 11, 2022
ff6e9fa
add frm
SaitejaUtpala Jan 11, 2022
c03c443
add Euclidean
SaitejaUtpala Jan 11, 2022
d4c1245
Merge branch 'master' of https://github.com/geomstats/geomstats into …
SaitejaUtpala Jan 13, 2022
038813e
add tests in mats
SaitejaUtpala Jan 13, 2022
6b2f9f3
add more tests in mats
SaitejaUtpala Jan 13, 2022
caaa197
Test Matrices Metric
SaitejaUtpala Jan 13, 2022
dadc1e0
more tests
SaitejaUtpala Jan 13, 2022
970a713
add flatten
SaitejaUtpala Jan 14, 2022
30ec418
add randomized tets
SaitejaUtpala Jan 14, 2022
08cde33
remove _test.matrices.py
SaitejaUtpala Jan 14, 2022
bab804f
add more tests
SaitejaUtpala Jan 14, 2022
b7abb6c
make matrices work
SaitejaUtpala Jan 17, 2022
68b70f9
remove euclidean
SaitejaUtpala Jan 17, 2022
94c7903
fix frm and ltm
SaitejaUtpala Jan 17, 2022
f3cb690
remove errors in PLT
SaitejaUtpala Jan 19, 2022
a16f4ea
make PLT tests pass
SaitejaUtpala Jan 19, 2022
69dd367
test
SaitejaUtpala Jan 19, 2022
e60bf75
add more tests
SaitejaUtpala Jan 19, 2022
bbb09f5
add
SaitejaUtpala Jan 19, 2022
5127db4
test_spd
SaitejaUtpala Jan 19, 2022
94e92c8
make pytorch tests pas
SaitejaUtpala Jan 19, 2022
e931bd2
reduce precision
SaitejaUtpala Jan 19, 2022
b4d0f9a
further reduce precision
SaitejaUtpala Jan 19, 2022
acbe8fd
reduce values
SaitejaUtpala Jan 19, 2022
0e830f4
reduce precision
SaitejaUtpala Jan 20, 2022
92e469c
test_spd
SaitejaUtpala Jan 20, 2022
f9c65de
parallel testing
SaitejaUtpala Jan 20, 2022
3f128dc
revert
SaitejaUtpala Jan 20, 2022
8000 bd15739
testing
SaitejaUtpala Jan 20, 2022
31bb95a
clean
SaitejaUtpala Jan 20, 2022
9e11817
blacken
SaitejaUtpala Jan 21, 2022
daee562
add more tests
SaitejaUtpala Jan 21, 2022
4876467
stash
SaitejaUtpala Jan 21, 2022
983ec6d
add more tests
SaitejaUtpala Jan 21, 2022
8c41f0a
add gs array
SaitejaUtpala Jan 21, 2022
e1b5b97
reduce size
SaitejaUtpala Jan 21, 2022
6b31bfa
add more tests
SaitejaUtpala Jan 21, 2022
8210442
add more tests
SaitejaUtpala Jan 22, 2022
af2703b
correct error
SaitejaUtpala Jan 22, 2022
4a4892f
addr comments
SaitejaUtpala Jan 23, 2022
228ec91
remove code comments
SaitejaUtpala Jan 23, 2022
5f7cf16
add data
SaitejaUtpala Jan 23, 2022
52650e0
renaming
SaitejaUtpala Jan 23, 2022
29d2792
add missing batch data
SaitejaUtpala Jan 23, 2022
0b3a8ce
reduce size of tets
SaitejaUtpala Jan 23, 2022
11cba63
reduce size
SaitejaUtpala Jan 23, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion geomstats/geometry/positive_lower_triangular_matrices.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def differential_gram(tangent_vec, base_point):
----------
tangent_vec : array_like, shape=[..., n, n]
Tangent vector at base point.
Symmetric Matrix.
base_point : array_like, shape=[..., n, n]
Base point.

Expand All @@ -151,7 +152,7 @@ def inverse_differential_gram(tangent_vec, base_point):
----------
tangent_vec : array_like, shape=[..., n, n]
tanget vector at gram(base_point)
Symmetric Matrix
Symmetric Matrix.
base_point : array_like, shape=[..., n, n]
Base point.

Expand Down
4 changes: 4 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[pytest]
markers =
smoke: simple and basic numerical tests.
random: tests that use randomized data.
144 changes: 135 additions & 9 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
"""Pytest utility classes, functions and fixtures."""

import inspect
import itertools
import os
import random
import types

import numpy as np
import pytest

import geomstats.backend as gs

smoke = pytest.mark.smoke
random = pytest.mark.random


def autograd_backend():
"""Check if autograd is set as backend."""
Expand Down Expand Up @@ -119,11 +118,136 @@ def generate_tests(self, smoke_test_data, random_test_data=[]):
_: list
Tests.
"""
smoke_tests = [
pytest.param(*data.values(), marks=smoke) for data in smoke_test_data
]
random_tests = [pytest.param(*data, marks=random) for data in random_test_data]
return smoke_tests + random_tests
tests = []
if smoke_test_data:
smoke_tests = [
pytest.param(*data.values(), marks=pytest.mark.smoke)
for data in smoke_test_data
]
tests += smoke_tests
if random_test_data:
random_tests = [
pytest.param(*data.values(), marks=pytest.mark.random)
if isinstance(data, dict)
else pytest.param(*data, marks=pytest.mark.random)
for data in random_test_data
]
tests += random_tests
return tests

def _log_exp_composition_data(
self, space, n_samples=100, max_n=10, n_n=5, **kwargs
):
"""Generate Data that checks for log and exp are inverse. Specifically

:math: `Exp_{base_point}(Log_{base_point}(point)) = point`


Parameters
----------
space : cls
Manifold class on which metric is present.
max_n : int
Maximum value when generating 'n'.
Optional, default: 20
n_n : int
Number of 'n' to be generated.
Optional, default: 5
n_samples : int
Optional, default: 100

Returns
-------
_ : list
Test Data.
"""
random_n = random.sample(range(1, max_n), n_n)
random_data = []
for n in random_n:
for prod in itertools.product(*kwargs.values()):
space_n = space(n)
base_point = space_n.random_point(n_samples)
point = space_n.random_point(n_samples)
random_data.append((n,) + prod + (point, base_point))
return self.generate_tests([], random_data)

def _geodesic_belongs_data(
self, space, max_n=10, n_n=5, n_geodesics=10, n_t=10, **kwargs
):
"""Generate Data that checks for points on geodesic belongs to data.

Parameters
----------
space : cls
Manifold class on which metric is present.
max_n : int
Maximum value when generating 'n'.
Optional, default: 10
n_n : int
Maximum value when generating 'n'.
Optional, default: 5
n_geodesics : int
Number of geodesics to be generated.
Optional, d 5D39 efault: 10
n_t : int
Number of points to be sampled on each geodesic.
Optional, default: 10
Returns
-------
_ : list
Test Data.
"""
random_n = random.sample(range(2, max_n), n_n)
random_data = []
for n in random_n:
for prod in itertools.product(*kwargs.values()):
space_n = space(n)
initial_point = space_n.random_point()
initial_tangent_points = space_n.random_tangent_vec(
n_geodesics, base_point=initial_point
)
random_t = gs.linspace(start=-1.0, stop=1.0, num=n_t)
for initial_tangent_point, t in itertools.product(
initial_tangent_points, random_t
):
random_data.append(
(n,) + prod + (initial_point, initial_tangent_point, t)
)
return self.generate_tests([], random_data)

def _squared_dist_is_symmetric_data(
self, space, max_n=5, n_n=3, n_samples=10, **kwargs
):
"""Generate Data that checks squared_dist is symmetric.

Parameters
----------
space : cls
Manifold class on which metric is present.
max_n : int
Range of 'n' to generated.
Optional, default: 10
n_n : int
Maximum value when generating 'n'.
Optional, default: 3
n_samples : int
Number of points to be generated.
Optional, default: 10
Returns
-------
_ : list
Test Data.
"""
random_n = random.sample(range(2, max_n), n_n)
random_data = []
for n in random_n:
for prod in itertools.product(*kwargs.values()):
space_n = space(n)
points_a = space_n.random_point(n_samples)
points_b = space_n.random_point(n_samples)
for point_a, point_b in itertools.product(points_a, points_b):
random_data.append((n,) + prod + (point_a, point_b))
return self.generate_tests([], random_data)


class Parametrizer(type):
Expand All @@ -133,7 +257,9 @@ class Parametrizer(type):
(except class methods and static methods). Two conventions need to be respected:

1.There should be a TestData object named 'testing_data'.
2.Every test function should have its corresponding data function inside TestData object.
2.Every test function should have its corresponding data function inside
TestData object.

Ex. test_exp() should have method called exp_data() inside 'testing_data'."""

def __new__(cls, name, bases, attrs):
Expand Down
96 changes: 54 additions & 42 deletions tests/tests_geomstats/test_full_rank_matrices.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,63 @@
"""Unit tests for full rank matrices."""

import warnings

import geomstats.backend as gs
import geomstats.tests
import tests.helper as helper
from geomstats.geometry.full_rank_matrices import FullRankMatrices
from tests.conftest import Parametrizer, TestCase, TestData


class TestFullRankMatrices(TestCase, metaclass=Parametrizer):

cls = FullRankMatrices

class TestDataFullRankMatrices(TestData):
def belongs_data(self):
smoke_data = [
dict(
m=3,
n=2,
mat=[
[-1.6473486, -1.18240309],
[0.1944016, 0.18169231],
[-1.13933855, -0.64971248],
],
expected=True,
),
dict(
m=3, n=2, mat=[[1.0, -1.0], [1.0, -1.0], [0.0, 0.0]], expected=False
),
]
return self.generate_tests(smoke_data)

def random_and_belongs_data(self):
smoke_data = [
dict(m=1, n=1, n_points=1),
dict(m=1, n=1, n_points=1000),
dict(m=2, n=2, n_points=1),
dict(m=2, n=2, n_points=100),
dict(m=10, n=5, n_points=100),
]
return self.generate_tests(smoke_data)

def projection_and_belongs_data(self):
shapes = [(1, 1), (1, 1), (1, 10), (2, 2), (10, 5), (15, 15)]
sizes = [1, 10, 1, 1, 100, 10]
random_data = [
dict(m=m, n=n, mats=gs.random.normal(size=(size, m, n)))
for (m, n), size in zip(shapes, sizes)
]

return self.generate_tests([], random_data)

class TestFullRankMatrices(geomstats.tests.TestCase):
"""Test of Full Rank Matrices methods."""

def setup_method(self):
"""Set up the test."""
warnings.simplefilter("ignore", category=ImportWarning)

gs.random.seed(1234)
testing_data = TestDataFullRankMatrices()

self.m = 3
self.n = 2
self.space = FullRankMatrices(self.m, self.n)
def test_belongs(self, m, n, mat, expected):
self.assertAllClose(self.cls(m, n).belongs(gs.array(mat)), gs.array(expected))

def test_belongs(self):
"""Test of belongs method."""
fr = self.space
mat_fr = gs.array(
[
[-1.6473486, -1.18240309],
[0.1944016, 0.18169231],
[-1.13933855, -0.64971248],
]
def test_random_and_belongs(self, m, n, n_points):
cls = self.cls(m, n)
self.assertAllClose(
gs.all(cls.belongs(cls.random_point(n_points))), gs.array(True)
)
mat_not_fr = gs.array([[1.0, -1.0], [1.0, -1.0], [0.0, 0.0]])
result = fr.belongs(mat_fr)
self.assertTrue(result)
result = fr.belongs(mat_not_fr)
self.assertFalse(result)

def test_projection_and_belongs(self):
"""Test of projection method."""
shape = (2, self.m, self.n)
result = helper.test_projection_and_belongs(self.space, shape, atol=gs.atol)
for res in result:
self.assertTrue(res)

def test_random_and_belongs(self):
"""Test of random point sampling method."""
mat = self.space.random_point(5)
result = self.space.belongs(mat)
self.assertTrue(gs.all(result))

def test_projection_and_belongs(self, m, n, mat):
self.assertAllClose(gs.all(self.cls(m, n).belongs(mat)), True)
Loading
0