Skip to content

ASAP smoothing doesn't respect time dimension #845

Open
@pedrokost

Description

@pedrokost

Relevant system information:

  • PostgreSQL version (output of SELECT version();): PostgreSQL 16.8 (Ubuntu 16.8-1.pgdg22.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0, 64-bit
  • TimescaleDB Toolkit version: 1.18.0
  • Installation method: apt
  • TimescaleDB version: 2.18.2

Describe the bug
The asap smoothing algorithm messes up the time dimension if points are not equally spaced. This seems to be a bug in the Toolkit implementation, as a Python reference implementation does not have that issue.

To Reproduce

Run this query: https://gist.github.com/pedrokost/19bea6e07a98a8260a96ba104971c703#file-query-sql

Compare with the results of the Python implementation:

# make sure asap.py and data.csv are in the same folder.
uv pip install numpy pandas matplotlib scipy
uv run asap.py

Expected behavior
The asap smoothing line should closely follow the raw data line.

Actual behavior
There is a notable deviation in the asap smoothing line from the raw data line.

Screenshots

See how the green line deviates from the blue line in this TimescaleDB SQL query result:
Image

Comparing with the Python reference implementation:
Image

Additional context
The lttb function does not have this issue.

Please note that the python code for plotting the results of the asap function is based on this, and has been slightly modified to plot the timeseries data appropriately.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions