The definitive entropy toolkit for time series data
Project description
entroscope
The definitive entropy toolkit for time series data. Seven entropy measures, one consistent interface, working directly on pandas Series and numpy arrays.
It started in NextOnMenu: a falling Shannon entropy of a food's regional search interest turned out to be an early signal that it was about to trend. Computing it meant re-writing the same histogram-and-log boilerplate every time. entroscope is that code, written once.
pip install entroscope
Quick start
import pandas as pd
from entroscope import shannon
s = pd.Series([10, 20, 15, 80, 90, 85, 88, 92])
shannon.compute(s) # 0.73 (a single entropy value)
shannon.rolling(s, window=20) # rolling entropy over time (a Series)
shannon.delta(s, window=20) # rate of change of entropy
shannon.normalized(s) # entropy scaled to [0, 1]
shannon.plot(s, window=20) # a matplotlib Figure
Every method accepts a pd.Series or a np.ndarray. Pass a Series and you
get a Series back with its index preserved; pass an array and you get an array.
Headless environments (Docker, CI)
entroscope does not change your matplotlib backend on import, so interactive
plotting in notebooks keeps working. In a headless environment (a Docker
container or CI runner) where you want a guaranteed non-interactive backend, set
the standard environment variable:
export MPLBACKEND=Agg # or, in a Dockerfile: ENV MPLBACKEND=Agg
The seven measures
| Measure | Import | Captures |
|---|---|---|
| Shannon | entroscope.shannon |
Uncertainty in a binned distribution |
| Permutation | entroscope.permutation |
Ordinal-pattern complexity (robust to noise) |
| Sample | entroscope.sample |
Regularity / predictability |
| Approximate | entroscope.approximate |
Regularity (less noise-sensitive, faster) |
| Spectral | entroscope.spectral |
Spread of the power spectrum (frequency domain) |
| Differential | entroscope.differential |
Continuous entropy via a fitted distribution |
| Multiscale | entroscope.multiscale |
Sample entropy across coarse-grained time scales |
One consistent API
Every measure exposes the same methods, so switching measures is a one-word change:
| Method | Input | Returns |
|---|---|---|
compute(x, **params) |
Series or ndarray | float |
rolling(x, window, **params) |
Series or ndarray | Series/ndarray, same length (NaN warm-up) |
delta(x, window, **params) |
Series or ndarray | Series/ndarray (first difference) |
normalized(x, **params) |
Series or ndarray | float in [0, 1] (shannon/permutation/spectral only) |
plot(x, window, **params) |
Series or ndarray | matplotlib.figure.Figure |
Shannon additionally provides geographic(df, col=...) for spatial distributions
(e.g. search interest by region). Multiscale provides compute and plot.
Visualization
from entroscope import plot
# overlay several measures on one axis
plot.compare(s, measures=["shannon", "permutation", "spectral"], window=20)
# a grid of every measure at once
plot.dashboard(s, window=20)
# highlight where entropy drops sharply (trend / regime-change detection)
plot.drop_events(s, measure="shannon", window=20, threshold=0.4)
All plot functions return a matplotlib.figure.Figure and never call
plt.show(), so they're safe in scripts, notebooks, and CI alike.
Real-world examples
Runnable scripts live in examples/; worked write-ups are in
docs/examples/:
- Food trends: detect when search interest stops being random (the original NextOnMenu use case).
- Finance: market uncertainty via permutation and spectral entropy.
- Medical: HRV, EEG seizure onset, respiration, and continuous glucose.
- Business: sales demand, web-traffic anomalies, price volatility, and manufacturing QC.
# food-trend analysis: entropy drops before a trend goes mainstream
import pandas as pd
from entroscope import shannon
matcha = pd.read_csv("matcha_trends.csv")["interest"]
shannon.plot(matcha, window=20, title="Matcha entropy over time")
A sustained drop in rolling entropy means a signal is becoming structured rather than noisy, an early indicator of a forming pattern.
Requirements
Python 3.9+, with numpy, pandas, scipy, and matplotlib (installed automatically).
Contributing
Contributions are welcome. See CONTRIBUTING.md for setup, the test/lint commands, and how to add a new entropy measure.
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file entroscope-0.2.0.tar.gz.
File metadata
- Download URL: entroscope-0.2.0.tar.gz
- Upload date:
- Size: 27.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b7eb2a291bbeea4e2ff6c4a55e0d7c6171a7c3eb4bce0fee080b270e513716d
|
|
| MD5 |
4e94fbb9053af9511a0b2fa2c62e167c
|
|
| BLAKE2b-256 |
60ac648bc0cd0889213ba18232c6852aa24ae7e2bf3418b4bafaedbbc5db2a9b
|
File details
Details for the file entroscope-0.2.0-py3-none-any.whl.
File metadata
- Download URL: entroscope-0.2.0-py3-none-any.whl
- Upload date:
- Size: 19.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d1d154e4705ed58f406253054073eb2e32ad9d2a3c0fce2cd80ac2cc2e1915a2
|
|
| MD5 |
7616b346161346113d7cf9ef603a70d8
|
|
| BLAKE2b-256 |
ea4deb1253021d9ea4a37fa79fae1e02665f8c72fb52c740d4cce6b39ab312d6
|