Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Commit

Permalink
Automated ci tests (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbalatsko committed Sep 19, 2023
2 parents 43d8181 + d509886 commit e3e7be6
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 47 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/run-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Run CI

on: [pull_request]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
make install
- name: Run tests
run: |
make test
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
install:
pip install -e .[all]

upgrade:
pip install --upgrade -e .[all]

test:
python -m pytest
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ pip install pykalman-bardo
Alternatively, you can setup from source:

```bash
# pip
pip install -e .

# poetry
poetry pyproject.toml
pip install .
```

## Usage
Expand Down
6 changes: 2 additions & 4 deletions pykalman/sqrt/tests/test_unscented.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from numpy.testing import assert_array_almost_equal
from scipy import linalg

from nose.tools import assert_true

from pykalman.sqrt import AdditiveUnscentedKalmanFilter
from pykalman.sqrt.unscented import cholupdate, qr

Expand Down Expand Up @@ -46,8 +44,8 @@ def test_additive_sample():
kf = build_unscented_filter(AdditiveUnscentedKalmanFilter)
(x, z) = kf.sample(100)

assert_true(x.shape == (100, 2))
assert_true(z.shape == (100, 1))
assert x.shape == (100, 2)
assert z.shape == (100, 1)


def test_additive_filter():
Expand Down
27 changes: 12 additions & 15 deletions pykalman/tests/test_standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import numpy as np
from numpy.testing import assert_array_almost_equal
from scipy import linalg
from nose.tools import assert_true

from pykalman import KalmanFilter
from pykalman.datasets import load_robot
Expand All @@ -29,8 +28,8 @@ def test_kalman_sampling(self):
self.data.initial_state_covariance)

(x, z) = kf.sample(100)
assert_true(x.shape == (100, self.data.transition_matrix.shape[0]))
assert_true(z.shape == (100, self.data.observation_matrix.shape[0]))
assert x.shape == (100, self.data.transition_matrix.shape[0])
assert z.shape == (100, self.data.observation_matrix.shape[0])

def test_kalman_filter_update(self):
kf = self.KF(
Expand Down Expand Up @@ -128,7 +127,7 @@ def test_kalman_fit(self):
loglikelihoods[i] = kf.loglikelihood(self.data.observations)
kf.em(X=self.data.observations, n_iter=1)

assert_true(np.allclose(loglikelihoods, self.data.loglikelihoods[:5]))
assert (np.allclose(loglikelihoods, self.data.loglikelihoods[:5])).all()

# check that EM for all parameters is working
kf.em_vars = 'all'
Expand All @@ -137,7 +136,7 @@ def test_kalman_fit(self):
kf.em(X=self.data.observations[0:n_timesteps], n_iter=1)
loglikelihoods[i] = kf.loglikelihood(self.data.observations[0:n_timesteps])
for i in range(len(loglikelihoods) - 1):
assert_true(loglikelihoods[i] < loglikelihoods[i + 1])
assert (loglikelihoods[i] < loglikelihoods[i + 1]).all()

def test_kalman_initialize_parameters(self):
self.check_dims(5, 1, {'transition_matrices': np.eye(5)})
Expand All @@ -154,16 +153,14 @@ def check_dims(self, n_dim_state, n_dim_obs, kwargs):
initial_state_mean, initial_state_covariance) = (
kf._initialize_parameters()
)
assert_true(transition_matrices.shape == (n_dim_state, n_dim_state))
assert_true(transition_offsets.shape == (n_dim_state,))
assert_true(transition_covariance.shape == (n_dim_state, n_dim_state))
assert_true(observation_matrices.shape == (n_dim_obs, n_dim_state))
assert_true(observation_offsets.shape == (n_dim_obs,))
assert_true(observation_covariance.shape == (n_dim_obs, n_dim_obs))
assert_true(initial_state_mean.shape == (n_dim_state,))
assert_true(
initial_state_covariance.shape == (n_dim_state, n_dim_state)
)
assert transition_matrices.shape == (n_dim_state, n_dim_state)
assert transition_offsets.shape == (n_dim_state,)
assert transition_covariance.shape == (n_dim_state, n_dim_state)
assert observation_matrices.shape == (n_dim_obs, n_dim_state)
assert observation_offsets.shape == (n_dim_obs,)
assert observation_covariance.shape == (n_dim_obs, n_dim_obs)
assert initial_state_mean.shape == (n_dim_state,)
assert initial_state_covariance.shape == (n_dim_state, n_dim_state)

def test_kalman_pickle(self):
kf = self.KF(
Expand Down
32 changes: 12 additions & 20 deletions pykalman/tests/test_unscented.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
from numpy import ma
from numpy.testing import assert_array_almost_equal

from nose.tools import assert_true

from pykalman import AdditiveUnscentedKalmanFilter, UnscentedKalmanFilter
from pykalman.datasets import load_robot

Expand Down Expand Up @@ -56,38 +54,32 @@ def check_dims(n_dim_state, n_dim_obs, n_func_args, kf_cls, kwargs):
kf._initialize_parameters()
)

assert_true(
assert (
transition_functions.shape == (1,)
if not 'transition_functions' in kwargs
else (len(kwargs['transition_functions']),)
)
assert_true(
all([len(inspect.getargspec(f).args) == n_func_args
assert all([len(inspect.getargspec(f).args) == n_func_args
for f in transition_functions])
)
assert_true(transition_covariance.shape == (n_dim_state, n_dim_state))
assert_true(
assert transition_covariance.shape == (n_dim_state, n_dim_state)
assert (
observation_functions.shape == (1,)
if not 'observation_functions' in kwargs
else (len(kwargs['observation_functions']),)
)
assert_true(
all([len(inspect.getargspec(f).args) == n_func_args
assert all([len(inspect.getargspec(f).args) == n_func_args
for f in observation_functions])
)
assert_true(observation_covariance.shape == (n_dim_obs, n_dim_obs))
assert_true(initial_state_mean.shape == (n_dim_state,))
assert_true(
initial_state_covariance.shape == (n_dim_state, n_dim_state)
)
assert observation_covariance.shape == (n_dim_obs, n_dim_obs)
assert initial_state_mean.shape == (n_dim_state,)
assert initial_state_covariance.shape == (n_dim_state, n_dim_state)


def test_unscented_sample():
kf = build_unscented_filter(UnscentedKalmanFilter)
(x, z) = kf.sample(100)

assert_true(x.shape == (100, 2))
assert_true(z.shape == (100, 1))
assert x.shape == (100, 2)
assert z.shape == (100, 1)


def test_unscented_filter():
Expand Down Expand Up @@ -157,8 +149,8 @@ def test_additive_sample():
kf = build_unscented_filter(AdditiveUnscentedKalmanFilter)
(x, z) = kf.sample(100)

assert_true(x.shape == (100, 2))
assert_true(z.shape == (100, 1))
assert x.shape == (100, 2)
assert z.shape == (100, 1)


def test_additive_filter():
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies = [
[project.optional-dependencies]

tests = [
"nose"
"pytest"
]

docs = [
Expand All @@ -38,7 +38,7 @@ docs = [
]

all = [
"nose",
"pytest",
"Sphinx",
"numpydoc"
]
Expand All @@ -52,7 +52,7 @@ Documentation = "https://pykalman.github.io/"
file = "COPYING"

[build-system]
requires = ["setuptools", "wheel", "toml", "build"]
requires = ["setuptools", "wheel", "build"]
build-backend = "setuptools.build_meta"

[tool.setuptools]
Expand Down

0 comments on commit e3e7be6

Please sign in to comment.