fracmem
Fractional-order derivatives as a fixed-size recursive filter: constant compute and memory per sample, so they run on a microcontroller.
An exact fractional derivative needs the entire signal history. fracmem fits a small filter once in Python, then deploys it as plain C.
Install
pip install fracmem
Requires numpy and scipy. Deploying needs only a C compiler.
Usage
import numpy as np
from fracmem import CompressedFractionalFilter
train = [np.random.randn(3000).cumsum() * 0.01 for _ in range(8)]
f = CompressedFractionalFilter(alpha=0.5, h=0.01, L=32, p=16)
f.fit(train, j_max=10_000) # once, offline
y = f.predict(signal) # batch
f.reset_stream()
y_k = f.step(x_k) # or one sample at a time
definition="rl" (default, same as Grünwald–Letnikov) or "caputo".
How it works
The derivative is a weighted sum over all past samples, with power-law weights w_j ~ j^(-alpha-1).
- The latest
Lsamples are computed exactly. - Older samples (the tail) are replaced by
pexponential modes, each updated with one multiply-add per sample. Decay rates come from a Gamma-function integral identity, not from data. - A few training signals fit the readout weights by cross-validated ridge regression.
Cost is O(L+p) compute and O(p) memory per sample.
Embedded C
from fracmem.embedded import export_c
export_c(f, "device_filter.c")
#include "fracmemfilter.h"
filtSetup();
float y = fracmemStep(&filt, x_k);
No heap allocation. See examples/ for the full fit, export, compile and verify round trip.
Background
Builds on the sum-of-exponentials construction of Jiang, Zhang, Zhang and Zhang, and related work by Lubich and Schädle, and by Baffet and Hesthaven.
License
MIT
Metadata
Release files for fracmem 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| fracmem-0.2.0.tar.gz | 19.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fracmem-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 35.3 kB
Release files / fracmem-0.2.0.tar.gz
| Download URL | fracmem-0.2.0.tar.gz |
|---|---|
| Size | 19.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
40eb133d52bae70866e967cb6ae1311b3d7df5dc3db9ac5c8e46e903d416e97f
|
|
BLAKE2b-256 checksum How to use checksums |
509ec5043423743af122323f379b02df5a41f3dfa4d698892b8c7b32094dbaec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Release files / fracmem-0.2.0-py3-none-any.whl
| Download URL | fracmem-0.2.0-py3-none-any.whl |
|---|---|
| Size | 16.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
917da7d4fc35dc716cd665eb072fcc24b4b8e92358eb833f297b5b48280d3753
|
|
BLAKE2b-256 checksum How to use checksums |
e602a230d42a3a401ffad2c972ee54e9e5882c28c91c68a2463e535ab55457ea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|