Skip to content

Commit f17919c

Browse files
committed
fixed zenodo link in readme, added test of import warnings for modules that depend on cvxpy
1 parent 2fc24a2 commit f17919c

7 files changed

Lines changed: 26 additions & 15 deletions

File tree

.github/workflows/test.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ jobs:
1717
- name: tests and coverage
1818
run: |
1919
pip install -e .[advanced,dev] coveralls
20-
coverage run --source=pynumdiff --omit='pynumdiff/_version.py,pynumdiff/tests/*,pynumdiff/utils/old_pi_cruise_control.py' -m pytest -s
20+
coverage run --source=pynumdiff --omit="pynumdiff/_version.py,pynumdiff/tests/*,pynumdiff/utils/old_pi_cruise_control.py" -m pytest -s
21+
pip uninstall -y cvxpy
22+
coverage run -a --source=pynumdiff -m pytest tests/test_imports.py
2123
coverage xml
2224
- uses: coverallsapp/github-action@v2
2325
with:

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ Python methods for numerical differentiation of noisy data, including multi-obje
1616
<img src='https://coveralls.io/repos/github/florisvb/PyNumDiff/badge.svg?branch=master' alt='Coverage Status' /></a>
1717
<a href="https://badge.fury.io/py/pynumdiff">
1818
<img src="https://badge.fury.io/py/pynumdiff.svg" alt="PyPI"></a>
19-
<a href="https://zenodo.org/badge/latestdoi/159711175">
20-
<img src="https://zenodo.org/badge/159711175.svg" alt="DOI"></a>
19+
<a href="https://doi.org/10.5281/zenodo.6374098">
20+
<img src="https://zenodo.org/badge/DOI/10.5281/zenodo.6374098.svg" alt="DOI"></a>
2121
<a href="https://joss.theoj.org/papers/102257ee4b0142bf49bc18d7c810e9d5">
2222
<img src="https://joss.theoj.org/papers/102257ee4b0142bf49bc18d7c810e9d5/status.svg"></a>
2323
</p>

pynumdiff/kalman_smooth/_kalman_smooth.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -260,16 +260,16 @@ def constant_jerk(x, dt, params=None, options=None, r=None, q=None, forwardbackw
260260

261261
def robustdiff(x, dt, order, log_q, log_r, proc_huberM=6, meas_huberM=0):
262262
"""Perform outlier-robust differentiation by solving the Maximum A Priori optimization problem:
263-
:math:`\\argmin_{\\{x_n\\}} \\sum_{n=0}^{N-1} V(R^{-1/2}(y_n - C x_n)) + \\sum_{n=1}^{N-1} J(Q^{-1/2}(x_n - A x_{n-1}))`,
263+
:math:`\\text{argmin}_{\\{x_n\\}} \\sum_{n=0}^{N-1} V(R^{-1/2}(y_n - C x_n)) + \\sum_{n=1}^{N-1} J(Q^{-1/2}(x_n - A x_{n-1}))`,
264264
where :math:`A,Q,C,R` come from an assumed constant derivative model and :math:`V,J` are the :math:`\\ell_1` norm or Huber
265265
loss rather than the :math:`\\ell_2` norm optimized by RTS smoothing. This problem is convex, so this method calls
266-
:code:`convex_smooth`.
266+
:code:`convex_smooth`, which in turn forms a sparse CVXPY problem and invokes CLARABEL.
267267
268268
Note that for Huber losses, :code:`M` is the radius where the Huber loss function turns from quadratic to linear. Because
269-
all inputs to Huber are normalized by noise level, :math:`q^{1/2}` or :math:`r^{1/2}`, :code:`M` is in units of standard
270-
deviation. In other words, this choice affects which portion of inputs are treated as outliers. For example, assuming
271-
Gaussian inliers, the portion beyond :math:`M\\sigma` is :code:`outlier_portion = 2*(1 - scipy.stats.norm.cdf(M))`. The
272-
inverse of this is :code:`M = scipy.stats.norm.ppf(1 - outlier_portion/2)`. As :math:`M \\to \\infty`, Huber becomes the
269+
all loss function inputs are normalized by noise level, :math:`q^{1/2}` or :math:`r^{1/2}`, :code:`M` is in units of inlier
270+
standard deviation. In other words, this choice affects which portion of inliers might be treated as outliers. For example,
271+
assuming Gaussian inliers, the portion beyond :math:`M\\sigma` is :code:`outlier_portion = 2*(1 - scipy.stats.norm.cdf(M))`.
272+
The inverse of this is :code:`M = scipy.stats.norm.ppf(1 - outlier_portion/2)`. As :math:`M \\to \\infty`, Huber becomes the
273273
1/2-sum-of-squares case, :math:`\\frac{1}{2}\\|\\cdot\\|_2^2`, because the normalization constant of the Huber loss (See
274274
:math:`c_2` in `section 6 of this paper <https://jmlr.org/papers/volume14/aravkin13a/aravkin13a.pdf>`_, missing a
275275
:math:`\\sqrt{\\cdot}` term there, see p2700) approaches 1 as :math:`M` increases. Similarly, as :code:`M` approaches 0,

pynumdiff/tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Pytest configuration for pynumdiff tests"""
1+
"""Pytest configuration for pynumdiff tests. This is what enables the --plot and --bounds flags to work."""
22
import pytest
33
from matplotlib import pyplot
44
from collections import defaultdict

pynumdiff/tests/test_diff_methods.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def spline_irreg_step(*args, **kwargs): return splinediff(*args, **kwargs)
134134
[(0, 0), (1, 1), (0, -1), (1, 1)],
135135
[(0, 0), (3, 3), (0, 0), (3, 3)]],
136136
savgoldiff: [[(-7, -7), (-13, -14), (0, -1), (0, 0)],
137-
[(-7, -7), (-13, -13), (0, -1), (0, 0)],
137+
[(-7, -8), (-13, -13), (0, -1), (0, 0)],
138138
[(-2, -2), (-1, -1), (0, -1), (0, 0)],
139139
[(0, -1), (0, 0), (0, 0), (1, 0)],
140140
[(1, 1), (2, 2), (1, 1), (2, 2)],

pynumdiff/tests/test_imports.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
import pytest
3+
import importlib
4+
5+
cvxpy_dependent_modules = ["", ".total_variation_regularization", ".kalman_smooth",
6+
".linear_model", ".optimize"]
7+
8+
@pytest.mark.skipif(importlib.util.find_spec("cvxpy"), reason="cvxpy installed")
9+
@pytest.mark.parametrize("module", cvxpy_dependent_modules)
10+
def test_import_without_cvxpy_warns(module):
11+
with pytest.warns(UserWarning):
12+
importlib.import_module("pynumdiff" + module)

pynumdiff/tests/test_utils.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
"""
2-
Unit tests for utility functions
3-
"""
1+
"""Unit tests for utility functions"""
42
# pylint: skip-file
5-
63
import numpy as np
74
from pynumdiff.utils import utility, evaluate
85
from pynumdiff.utils.simulate import sine, triangle, pop_dyn, linear_autonomous, pi_cruise_control, lorenz_x

0 commit comments

Comments
 (0)