|
1 | | -PyNumDiff |
2 | | -========= |
3 | | - |
4 | | -Python methods for numerical differentiation of noisy data, including |
5 | | -multi-objective optimization routines for automated parameter selection. |
6 | | - |
7 | | -Table of contents |
8 | | ------------------ |
9 | | - |
10 | | -- `Introduction <#introduction>`__ |
11 | | -- `Structure <#structure>`__ |
12 | | -- `Getting Started <#getting-started>`__ |
13 | | - |
14 | | - - `Prerequisite <#prerequisite>`__ |
15 | | - - `Installing <#installing>`__ |
16 | | - |
17 | | -- `Usage <#usage>`__ |
18 | | - |
19 | | - - `Basic usages <#basic-usages>`__ |
20 | | - - `Notebook examples <#notebook-examples>`__ |
21 | | - - `Important notes <#important-notes>`__ |
22 | | - - `Running the tests <#running-the-tests>`__ |
23 | | - |
24 | | -- `Citation <#citation>`__ |
25 | | -- `License <#license>`__ |
26 | | - |
27 | | -Introduction |
28 | | ------------- |
29 | | - |
30 | | -PyNumDiff is a Python package that implements various methods for |
31 | | -computing numerical derivatives of noisy data, which can be a critical |
32 | | -step in developing dynamic models or designing control. There are four |
33 | | -different families of methods implemented in this repository: smoothing |
34 | | -followed by finite difference calculation, local approximation with |
35 | | -linear models, Kalman filtering based methods and total variation |
36 | | -regularization methods. Most of these methods have multiple parameters |
37 | | -involved to tune. We take a principled approach and propose a |
38 | | -multi-objective optimization framework for choosing parameters that |
39 | | -minimize a loss function to balance the faithfulness and smoothness of |
40 | | -the derivative estimate. For more details, refer to `this |
41 | | -paper <https://doi.org/10.1109/ACCESS.2020.3034077>`__. |
42 | | - |
43 | | -Structure |
44 | | ---------- |
45 | | - |
46 | | -:: |
47 | | - |
48 | | - PyNumDiff/ |
49 | | - |- README.md |
50 | | - |- pynumdiff/ |
51 | | - |- __init__.py |
52 | | - |- __version__.py |
53 | | - |- finite_difference/ |
54 | | - |- kalman_smooth/ |
55 | | - |- linear_model/ |
56 | | - |- smooth_finite_difference/ |
57 | | - |- total_variation_regularization/ |
58 | | - |- utils/ |
59 | | - |- optimize/ |
60 | | - |- __init__.py |
61 | | - |- __optimize__.py |
62 | | - |- finite_difference/ |
63 | | - |- kalman_smooth/ |
64 | | - |- linear_model/ |
65 | | - |- smooth_finite_difference/ |
66 | | - |- total_variation_regularization/ |
67 | | - |- tests/ |
68 | | - |- examples |
69 | | - |- 1_basic_tutorial.ipynb |
70 | | - |- 2a_optimizing_parameters_with_dxdt_known.ipynb |
71 | | - |- 2b_optimizing_parameters_with_dxdt_unknown.ipynb |
72 | | - |- docs/ |
73 | | - |- Makefile |
74 | | - |- make.bat |
75 | | - |- build/ |
76 | | - |- source/ |
77 | | - |- _static |
78 | | - |- _summaries |
79 | | - |- conf.py |
80 | | - |- index.rst |
81 | | - |- ... |
82 | | - |- setup.py |
83 | | - |- .gitignore |
84 | | - |- LICENSE.txt |
85 | | - |- pyproject.toml |
86 | | - |
87 | | -Getting Started |
88 | | ---------------- |
89 | | - |
90 | | -Prerequisite |
91 | | -~~~~~~~~~~~~ |
92 | | - |
93 | | -PyNumDiff requires common packages like ``numpy``, ``scipy``, |
94 | | -``matplotlib``, ``pytest`` (for unittests), ``pylint`` (for PEP8 style |
95 | | -check). For a full list, you can check the file |
96 | | -`pyproject.toml <https://github.com/florisvb/PyNumDiff/blob/master/pyproject.toml>`__ |
97 | | - |
98 | | -In addition, it also requires certain additional packages for select |
99 | | -functions, though these are not required for a successful install of |
100 | | -PyNumDiff: |
101 | | - |
102 | | -- Total Variation Regularization methods: `cvxpy <http://www.cvxpy.org/install/index.html>`__ |
103 | | - |
104 | | -When using ``cvxpy``, our default solver is set to be ``MOSEK`` (highly |
105 | | -recommended), you would need to download their free academic license |
106 | | -from their |
107 | | -`website <https://www.mosek.com/products/academic-licenses/>`__. |
108 | | -Otherwise, you can also use other solvers which are listed |
109 | | -`here <https://www.cvxpy.org/tutorial/advanced/index.html>`__. |
110 | | - |
111 | | -Installing |
112 | | -~~~~~~~~~~ |
113 | | - |
114 | | -The code is compatible with >=Python 3.5. It can be installed using pip |
115 | | -or directly from the source code. Basic installation options include: |
116 | | - |
117 | | -- From PyPI using pip: ``pip install pynumdiff``. |
118 | | -- From source using pip git+: |
119 | | - ``pip install git+https://github.com/florisvb/PyNumDiff`` |
120 | | -- From local source code: Run ``pip install .`` from inside this directory. |
121 | | - |
122 | | -For additional solvers, run ``pip install pynumdiff[advanced]``. This includes ``cvxpy``, |
123 | | -which can be tricky when compiling from source. If an error occurs in installing |
124 | | -``cvxpy``, see `cvxpy install documentation <https://www.cvxpy.org/install/>`__, install |
125 | | -``cvxpy`` according to those instructions, and try ``pip install pynumdiff[advanced]`` |
126 | | -again. |
127 | | - |
128 | | - |
129 | | -Note: If using the optional MOSEK solver for cvxpy you will also need a |
130 | | -`MOSEK license <https://www.mosek.com/products/academic-licenses/>`__, |
131 | | -free academic license. |
132 | | - |
133 | | -Usage |
134 | | ------ |
135 | | - |
136 | | -Basic usages |
137 | | -~~~~~~~~~~~~ |
138 | | - |
139 | | -- Basic Usage: you provide the parameters |
140 | | - |
141 | | - .. code:: bash |
142 | | -
|
143 | | - x_hat, dxdt_hat = pynumdiff.sub_module.method(x, dt, params, options) |
144 | | -
|
145 | | -- Advanced usage: automated parameter selection through multi-objective |
146 | | - optimization |
147 | | - |
148 | | - .. code:: bash |
149 | | -
|
150 | | - params, val = pynumdiff.optimize.sub_module.method(x, dt, params=None, |
151 | | - tvgamma=tvgamma, # hyperparameter |
152 | | - dxdt_truth=None, # no ground truth data |
153 | | - options={}) |
154 | | - print('Optimal parameters: ', params) |
155 | | - x_hat, dxdt_hat = pynumdiff.sub_module.method(x, dt, params, options={'smooth': True})` |
156 | | -
|
157 | | -Notebook examples |
158 | | -~~~~~~~~~~~~~~~~~ |
159 | | -
|
160 | | -- Differentiation with different methods: `1\_basic\_tutorial.ipynb <https://github.com/florisvb/PyNumDiff/tree/master/examples/1_basic_tutorial.ipynb>`__ |
161 | | -- Parameter Optimization with known ground truth (only for demonstration purpose): `2a\_optimizing\_parameters\_with\_dxdt\_known.ipynb <https://github.com/florisvb/PyNumDiff/tree/master/examples/2a_optimizing_parameters_with_dxdt_known.ipynb>`__ |
162 | | -- Parameter Optimization with unknown ground truth: `2b\_optimizing\_parameters\_with\_dxdt\_unknown.ipynb <https://github.com/florisvb/PyNumDiff/tree/master/examples/2b_optimizing_parameters_with_dxdt_unknown.ipynb>`__ |
163 | | -
|
164 | | -
|
165 | | -Important notes |
166 | | -~~~~~~~~~~~~~~~ |
167 | | -
|
168 | | -- Larger values of ``tvgamma`` produce smoother derivatives |
169 | | -- The value of ``tvgamma`` is largely universal across methods, making |
170 | | - it easy to compare method results |
171 | | -- The optimization is not fast. Run it on subsets of your data if you |
172 | | - have a lot of data. It will also be much faster with faster |
173 | | - differentiation methods, like savgoldiff and butterdiff, and probably |
174 | | - too slow for sliding methods like sliding DMD and sliding LTI fit. |
175 | | -- The following heuristic works well for choosing ``tvgamma``, where |
176 | | - ``cutoff_frequency`` is the highest frequency content of the signal |
177 | | - in your data, and ``dt`` is the timestep: |
178 | | - ``tvgamma=np.exp(-1.6*np.log(cutoff_frequency)-0.71*np.log(dt)-5.1)`` |
179 | | -
|
180 | | -Running the tests |
181 | | -~~~~~~~~~~~~~~~~~ |
182 | | -
|
183 | | -To run tests locally, type: |
184 | | -
|
185 | | -.. code:: bash |
186 | | -
|
187 | | - > pytest pynumdiff |
188 | | -
|
189 | | -Citation |
190 | | --------- |
191 | | -
|
192 | | -@ARTICLE{9241009, author={F. {van Breugel} and J. {Nathan Kutz} and B. |
193 | | -W. {Brunton}}, journal={IEEE Access}, title={Numerical differentiation |
194 | | -of noisy data: A unifying multi-objective optimization framework}, |
195 | | -year={2020}, volume={}, number={}, pages={1-1}, |
196 | | -doi={10.1109/ACCESS.2020.3034077}} |
197 | | -
|
198 | | -Developer's Guide |
199 | | ------------------ |
| 1 | +.. include:: ../../README.md |
| 2 | + :parser: myst_parser.sphinx_ |
200 | 3 |
|
201 | 4 | .. toctree:: |
202 | 5 | :maxdepth: 1 |
|
0 commit comments