Skip to content

Conversation

@pavelkomarov
Copy link
Collaborator

added support for irregular steps to splinediff, extended test code to cover this case, and reworked readme to reflect

…o cover this case, and reworked readme to reflect
<img src="https://joss.theoj.org/papers/102257ee4b0142bf49bc18d7c810e9d5/status.svg"></a>
</p>

## Table of contents
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This takes up really valuable real estate at the top of the page, and the readme is short enough that the value of a TOC is unclear to me, so I nixed it.

For more details, refer to [this paper](https://doi.org/10.1109/ACCESS.2020.3034077).
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 seven different families of methods implemented in this repository:

1. convolutional smoothing followed by finite difference calculation
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You only listed 4 families, which was quite out of date.


Most of these methods have multiple parameters, so 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](https://doi.org/10.1109/ACCESS.2020.3034077).

## Installing
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Installation and usage are now prioritized.

x_hat, dxdt_hat = method(x, dt, param1=val1, param2=val2, ...)
```

Or you can find parameter by calling the multi-objective optimization algorithm from the `optimize` module:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I simplified this section somewhat. The second two usage examples were slightly repetitive.

tt = np.linspace(0, 3) # full domain, for visualizing denser plots
np.random.seed(7) # for repeatability of the test, so we don't get random failures
noise = 0.05*np.random.randn(*t.shape)
t_irreg = t + np.random.uniform(-dt/3, dt/3, *t.shape) # add jostle
Copy link
Collaborator Author

@pavelkomarov pavelkomarov Aug 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking through how to test the irregular step case took more thought than actually extending splinediff to do it.

(splinediff, {'degree':5, 's':2}), (splinediff, [5, 2]),
(spline_irreg_step, {'degree':5, 's':2}),
(polydiff, {'degree':2, 'window_size':3}), (polydiff, [2, 3]),
(savgoldiff, {'degree':2, 'window_size':5, 'smoothing_win':5}), (savgoldiff, [2, 5, 5]),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reordered these a bit. They have a canonical ordering in my mind now, and I'm slowly getting all the listings of them to agree.

(jerk_sliding, {'gamma':1, 'window_size':15}), (jerk_sliding, [1], {'window_size':15})
(jerk_sliding, {'gamma':1, 'window_size':15}), (jerk_sliding, [1], {'window_size':15}),
(spectraldiff, {'high_freq_cutoff':0.2}), (spectraldiff, [0.2]),
(lineardiff, {'order':3, 'gamma':5, 'window_size':11, 'solver':'CLARABEL'}), (lineardiff, [3, 5, 11], {'solver':'CLARABEL'})
Copy link
Collaborator Author

@pavelkomarov pavelkomarov Aug 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Funny that it works with OSQP locally (Mac) but doesn't in the cloud (Linux). I was having trouble with OSQP on my Linux machine at home too.

if diff_method in [spline_irreg_step]: # list that can handle variable dt
x = f(t_irreg)
dxdt = df(t_irreg)
_t = t_irreg
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somewhat annoyingly, you can't reassign t or dt, or it breaks the binding with the global variable for all tests, so I have to create alternatively-named temp variables.

@pavelkomarov pavelkomarov merged commit 18437b2 into master Aug 19, 2025
1 check passed
@pavelkomarov pavelkomarov deleted the splines-irregular-steps branch August 24, 2025 00:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant