Skip to content

Commit

Permalink
fix pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
jdtuck committed Nov 18, 2023
1 parent 5356d15 commit 6fad888
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 91 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ jobs:

steps:
- uses: actions/checkout@v3
- uses: codecov/codecov-action@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
python -m pip install flake8 pytest pytest-runner
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
Expand All @@ -32,4 +33,4 @@ jobs:
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
python setup.py pytest --addopts "test"
Empty file removed test/__init__.py
Empty file.
179 changes: 90 additions & 89 deletions test/test_all.py
Original file line number Diff line number Diff line change
@@ -1,115 +1,115 @@
import unittest
import numpy as np
import fdasrsf as fs
import fdasrsf as fs

class TestFDASRSF(unittest.TestCase):
# Returns True or False.
def test_reparm(self):

class TestFDASRSF(unittest.TestCase):
# Returns True or False.
def test_reparm(self):
M = 101
q1 = np.sin(np.linspace(0,2*np.pi,M))
timet = np.linspace(0,1,M)
gam = fs.optimum_reparam(q1, timet, q1)
self.assertAlmostEqual(sum(gam-timet),0)
def test_warp_f_gamma(self):
q1 = np.sin(np.linspace(0, 2 * np.pi, M))
timet = np.linspace(0, 1, M)
gam = fs.optimum_reparam(q1, timet, q1)
self.assertAlmostEqual(sum(gam - timet), 0)

def test_warp_f_gamma(self):
M = 101
q1 = np.sin(np.linspace(0,2*np.pi,M))
timet = np.linspace(0,1,M)
gam = fs.optimum_reparam(q1, timet, q1)
q1a = fs.warp_f_gamma(timet, q1, gam)
self.assertAlmostEqual(sum(q1-q1a),0)
def test_warp_q_gamma(self):
q1 = np.sin(np.linspace(0, 2 * np.pi, M))
timet = np.linspace(0, 1, M)
gam = fs.optimum_reparam(q1, timet, q1)
q1a = fs.warp_f_gamma(timet, q1, gam)
self.assertAlmostEqual(sum(q1 - q1a), 0)

def test_warp_q_gamma(self):
M = 101
q1 = np.sin(np.linspace(0,2*np.pi,M))
timet = np.linspace(0,1,M)
gam = fs.optimum_reparam(q1, timet, q1)
q1a = fs.warp_q_gamma(timet, q1, gam)
self.assertAlmostEqual(sum(q1-q1a),0)
def test_reparm1(self):
q1 = np.sin(np.linspace(0, 2 * np.pi, M))
timet = np.linspace(0, 1, M)
gam = fs.optimum_reparam(q1, timet, q1)
q1a = fs.warp_q_gamma(timet, q1, gam)
self.assertAlmostEqual(sum(q1 - q1a), 0)

def test_reparm1(self):
M = 101
q1 = np.sin(np.linspace(0,2*np.pi,M))
timet = np.linspace(0,1,M)
gam = fs.optimum_reparam(q1, timet, q1, method="DP")
self.assertAlmostEqual(sum(gam-timet),0)
q1 = np.sin(np.linspace(0, 2 * np.pi, M))
timet = np.linspace(0, 1, M)
gam = fs.optimum_reparam(q1, timet, q1, method="DP")
self.assertAlmostEqual(sum(gam - timet), 0)

def test_rlbgs(self):
M = 101
q1 = np.sin(np.linspace(0,2*np.pi,M))
timet = np.linspace(0,1,M)
gam = fs.optimum_reparam(q1, timet, q1, method="RBFGS")
self.assertAlmostEqual(sum(gam-timet),0)
q1 = np.sin(np.linspace(0, 2 * np.pi, M))
timet = np.linspace(0, 1, M)
gam = fs.optimum_reparam(q1, timet, q1, method="RBFGS")
self.assertAlmostEqual(sum(gam - timet), 0)

def test_f_to_srvf(self):
M = 101
f1 = np.sin(np.linspace(0,2*np.pi,M))
timet = np.linspace(0,1,M)
q1 = fs.f_to_srsf(f1,timet)
f1a = fs.srsf_to_f(q1,timet)
self.assertAlmostEqual(sum(f1-f1a),0,4)
f1 = np.sin(np.linspace(0, 2 * np.pi, M))
timet = np.linspace(0, 1, M)
q1 = fs.f_to_srsf(f1, timet)
f1a = fs.srsf_to_f(q1, timet)
self.assertAlmostEqual(sum(f1 - f1a), 0, 4)

def test_elastic_distance(self):
M = 101
f1 = np.sin(np.linspace(0,2*np.pi,M))
timet = np.linspace(0,1,M)
f1 = np.sin(np.linspace(0, 2 * np.pi, M))
timet = np.linspace(0, 1, M)
da, dp = fs.elastic_distance(f1, f1, timet)
self.assertLessEqual(da, 1e-10)
self.assertLessEqual(dp, 1e-6)

def test_smooth(self):
M = 101
q1 = np.zeros((M,1))
q1[:,0] = np.sin(np.linspace(0,2*np.pi,M)).T
q1a = fs.smooth_data(q1,1)
q1b = fs.smooth_data(q1,1)
self.assertAlmostEqual(sum(q1a.flatten()-q1b.flatten()),0)
q1 = np.zeros((M, 1))
q1[:, 0] = np.sin(np.linspace(0, 2 * np.pi, M)).T
q1a = fs.smooth_data(q1, 1)
q1b = fs.smooth_data(q1, 1)
self.assertAlmostEqual(sum(q1a.flatten() - q1b.flatten()), 0)

def test_edistance(self):
M = 101
q1 = np.sin(np.linspace(0,2*np.pi,M))
timet = np.linspace(0,1,M)
q1 = np.sin(np.linspace(0, 2 * np.pi, M))
timet = np.linspace(0, 1, M)
dy, dx = fs.elastic_distance(q1, q1, timet)
self.assertAlmostEqual(dy+dx,0)
self.assertAlmostEqual(dy + dx, 0)

def test_invgamma(self):
M = 101
gam = np.linspace(0,1,M)
gam = np.linspace(0, 1, M)
gami = fs.invertGamma(gam)
self.assertAlmostEqual(sum(gam-gami),0)
self.assertAlmostEqual(sum(gam - gami), 0)

def test_invexpmap(self):
M = 101
gam = np.linspace(0,1,M)
gam = np.linspace(0, 1, M)
binsize = np.mean(np.diff(gam))
psi = np.sqrt(np.gradient(gam,binsize))
out, theta = fs.inv_exp_map(psi,psi)
self.assertAlmostEqual(sum(out),0)
psi = np.sqrt(np.gradient(gam, binsize))
out, theta = fs.inv_exp_map(psi, psi)
self.assertAlmostEqual(sum(out), 0)

def test_l2norm(self):
M = 101
gam = np.linspace(0,1,M)
gam = np.linspace(0, 1, M)
binsize = np.mean(np.diff(gam))
psi = np.sqrt(np.gradient(gam,binsize))
out, theta = fs.inv_exp_map(psi,psi)
psi = np.sqrt(np.gradient(gam, binsize))
out, theta = fs.inv_exp_map(psi, psi)
out1 = fs.geometry.L2norm(out)
self.assertAlmostEqual(out1,0)
self.assertAlmostEqual(out1, 0)

def test_expmap(self):
M = 101
gam = np.linspace(0,1,M)
gam = np.linspace(0, 1, M)
binsize = np.mean(np.diff(gam))
psi = np.sqrt(np.gradient(gam,binsize))
out, theta = fs.inv_exp_map(psi,psi)
out1 = fs.exp_map(psi,out)
self.assertAlmostEqual(sum(out1),M)
psi = np.sqrt(np.gradient(gam, binsize))
out, theta = fs.inv_exp_map(psi, psi)
out1 = fs.exp_map(psi, out)
self.assertAlmostEqual(sum(out1), M)

def test_srsf(self):
data = np.load('bin/simu_data.npz')
time = data['arr_1']
f = data['arr_0']
obj = fs.fdawarp(f,time)
data = np.load("bin/simu_data.npz")
time = data["arr_1"]
f = data["arr_0"]
obj = fs.fdawarp(f, time)
obj.srsf_align()
vpca = fs.fdavpca(obj)
vpca.calc_fpca()
Expand All @@ -118,24 +118,25 @@ def test_srsf(self):
vpca = fs.fdahpca(obj)
vpca.calc_fpca()
self.assertAlmostEqual(obj.amp_var, 0.018998691036349585)

def test_srvf(self):
data = np.load('bin/MPEG7.npz',allow_pickle=True)
Xdata = data['Xdata']
curve = Xdata[0,1]
n,M = curve.shape
data = np.load("bin/MPEG7.npz", allow_pickle=True)
Xdata = data["Xdata"]
curve = Xdata[0, 1]
n, M = curve.shape
K = Xdata.shape[1]

beta = np.zeros((n,M,K))
for i in range(0,K):
beta[:,:,i] = Xdata[0,i]
beta = np.zeros((n, M, K))
for i in range(0, K):
beta[:, :, i] = Xdata[0, i]

obj = fs.fdacurve(beta,N=M)
obj = fs.fdacurve(beta, N=M)
obj.karcher_mean()
obj.srvf_align()
obj.karcher_cov()
obj.shape_pca()
self.assertAlmostEqual(obj.E[-1], 0.022668183569717587)

if __name__ == '__main__':
unittest.main()


if __name__ == "__main__":
unittest.main()

0 comments on commit 6fad888

Please sign in to comment.