florisvb / PyNumDiff

Methods for numerical differentiation of noisy data in python
Other
112 stars 16 forks source link

PyNumDiff

Python methods for numerical differentiation of noisy data, including multi-objective optimization routines for automated parameter selection.

Python for Numerical Differentiation of noisy time series data

Documentation Status PyPI version DOI

Table of contents

Introduction

PyNumDiff is a Python package that implements various methods for computing numerical derivatives of noisy data, which can be a critical step in developing dynamic models or designing control. There are four different families of methods implemented in this repository: smoothing followed by finite difference calculation, local approximation with linear models, Kalman filtering based methods and total variation regularization methods. Most of these methods have multiple parameters involved to tune. We take a principled approach and propose a multi-objective optimization framework for choosing parameters that minimize a loss function to balance the faithfulness and smoothness of the derivative estimate. For more details, refer to this paper.

Structure

PyNumDiff/
  |- README.md
  |- pynumdiff/
     |- __init__.py
     |- __version__.py
     |- finite_difference/
     |- kalman_smooth/
     |- linear_model/
     |- smooth_finite_difference/
     |- total_variation_regularization/
     |- utils/
     |- optimize/
        |- __init__.py
        |- __optimize__.py
        |- finite_difference/
        |- kalman_smooth/
        |- linear_model/
        |- smooth_finite_difference/
        |- total_variation_regularization/
     |- tests/
  |- examples
     |- 1_basic_tutorial.ipynb
     |- 2a_optimizing_parameters_with_dxdt_known.ipynb
     |- 2b_optimizing_parameters_with_dxdt_unknown.ipynb
  |- docs/
     |- Makefile
     |- make.bat
     |- build/
     |- source/
        |- _static
        |- _summaries
        |- conf.py
        |- index.rst
        |- ...
  |- .gitignore
  |- .travis.yml
  |- LICENSE.txt
  |- requirements.txt

Citation

See CITATION.cff file as well as the following references.

PyNumDiff python package:

@article{PyNumDiff2022,
  doi = {10.21105/joss.04078},
  url = {https://doi.org/10.21105/joss.04078},
  year = {2022},
  publisher = {The Open Journal},
  volume = {7},
  number = {71},
  pages = {4078},
  author = {Floris van Breugel and Yuying Liu and Bingni W. Brunton and J. Nathan Kutz},
  title = {PyNumDiff: A Python package for numerical differentiation of noisy time-series data},
  journal = {Journal of Open Source Software}
}

Optimization algorithm:

@article{ParamOptimizationDerivatives2020, 
doi={10.1109/ACCESS.2020.3034077}
author={F. {van Breugel} and J. {Nathan Kutz} and B. W. {Brunton}}, 
journal={IEEE Access}, 
title={Numerical differentiation of noisy data: A unifying multi-objective optimization framework}, 
year={2020}
}

Getting Started

Prerequisite

PyNumDiff requires common packages like numpy, scipy, matplotlib, pytest (for unittests), pylint (for PEP8 style check). For a full list, you can check the file requirements.txt

In addition, it also requires certain additional packages for select functions, though these are not required for a successful install of PyNumDiff:

When using cvxpy, our default solver is set to be MOSEK (highly recommended), you would need to download their free academic license from their website. Otherwise, you can also use other solvers which are listed here.

Installing

The code is compatible with >=Python 3.5. It can be installed using pip or directly from the source code. Basic installation options include:

For additional solvers, run pip install pynumdiff[advanced]. This includes cvxpy, which can be tricky when compiling from source. If an error occurs in installing cvxpy, see cvxpy install documentation, install cvxpy according to those instructions, and try pip install pynumdiff[advanced] again.

Note: If using the optional MOSEK solver for cvxpy you will also need a MOSEK license, free academic license.

Usage

PyNumDiff uses Sphinx for code documentation. So you can see more details about the API usage there.

Basic usages

Notebook examples

We will frequently update simple examples for demo purposes, and here are currently exisiting ones:

Important notes

Running the tests

We are using Travis CI for continuous intergration testing. You can check out the current status here.

To run tests locally, type:

> pytest pynumdiff

License

This project utilizes the MIT LICENSE. 100% open-source, feel free to utilize the code however you like.