Skip to main content

PyPI GitHub PyPI - Downloads PyPI - Total of downloads Documentation Status

ordpy: A Python Package for Data Analysis with Permutation Entropy and Ordinal Network Methods

ordpy is a pure Python module [1] that implements data analysis methods based on Bandt and Pompe’s [2] symbolic encoding scheme.

If you have used ordpy in a scientific publication, we would appreciate citations to the following reference [1]:

@article{pessa2021ordpy,
 title         = {ordpy: A Python package for data analysis with permutation entropy and ordinal network methods},
 author        = {Arthur A. B. Pessa and Haroldo V. Ribeiro},
 journal       = {Chaos: An Interdisciplinary Journal of Nonlinear Science},
 volume        = {31},
 number        = {6},
 pages         = {063110},
 year          = {2021},
 doi           = {10.1063/5.0049901},
}

ordpy implements the following data analysis methods:

Released on version 1.0 (February 2021):

  • Permutation entropy for time series [2] and images [3];

  • Complexity-entropy plane for time series [4], [5] and images [3];

  • Multiscale complexity-entropy plane for time series [6] and images [7];

  • Tsallis [8] and Rényi [9] generalized complexity-entropy curves for time series and images;

  • Ordinal networks for time series [10], [11] and images [12];

  • Global node entropy of ordinal networks for time series [13], [11] and images [12].

  • Missing ordinal patterns [14] and missing transitions between ordinal patterns [11] for time series and images.

Released on version 1.1.0 (January 2023):

  • Weighted permutation entropy for time series [15] and images;

  • Fisher-Shannon plane for time series [16] and images;

  • Permutation Jensen-Shannon distance for time series [17] and images;

  • Four pattern permutation contrasts (up-down balance, persistence, rotational-asymmetry, and up-down scaling.) for time series [18];

  • Smoothness-structure plane for images [19].

Released on version 1.2.0 (April 2025):

  • Two-by-two ordinal patterns for images [20].

For more detailed information about the methods implemented in ordpy, please consult its documentation.

Installing

Ordpy can be installed via the command line using

pip install ordpy

or you can directly clone its git repository:

git clone https://github.com/arthurpessa/ordpy.git
cd ordpy
pip install -e .

Basic usage

We provide a notebook illustrating how to use ordpy. This notebook reproduces all figures of our article [1]. The code below shows simple applications of ordpy.

#Complexity-entropy plane for logistic map and Gaussian noise.

import numpy as np
import ordpy
from matplotlib import pylab as plt

def logistic(a=4, n=100000, x0=0.4):
    x = np.zeros(n)
    x[0] = x0
    for i in range(n-1):
        x[i+1] = a*x[i]*(1-x[i])
    return(x)

time_series = [logistic(a) for a in [3.05, 3.55, 4]]
time_series += [np.random.normal(size=100000)]

HC = [ordpy.complexity_entropy(series, dx=4) for series in time_series]


f, ax = plt.subplots(figsize=(8.19, 6.3))

for HC_, label_ in zip(HC, ['Period-2 (a=3.05)',
                            'Period-8 (a=3.55)',
                            'Chaotic (a=4)',
                            'Gaussian noise']):
    ax.scatter(*HC_, label=label_, s=100)

ax.set_xlabel('Permutation entropy, $H$')
ax.set_ylabel('Statistical complexity, $C$')

ax.legend()
https://raw.githubusercontent.com/arthurpessa/ordpy/master/examples/figs/sample_fig.png
#Ordinal networks for logistic map and Gaussian noise.

import numpy as np
import igraph
import ordpy
from matplotlib import pylab as plt
from IPython.core.display import display, SVG

def logistic(a=4, n=100000, x0=0.4):
    x = np.zeros(n)
    x[0] = x0
    for i in range(n-1):
        x[i+1] = a*x[i]*(1-x[i])
    return(x)

time_series = [logistic(a=4), np.random.normal(size=100000)]

vertex_list, edge_list, edge_weight_list = list(), list(), list()
for series in time_series:
    v_, e_, w_   = ordpy.ordinal_network(series, dx=4)
    vertex_list += [v_]
    edge_list   += [e_]
    edge_weight_list += [w_]

def create_ig_graph(vertex_list, edge_list, edge_weight):

    G = igraph.Graph(directed=True)

    for v_ in vertex_list:
        G.add_vertex(v_)

    for [in_, out_], weight_ in zip(edge_list, edge_weight):
        G.add_edge(in_, out_, weight=weight_)

    return G

graphs = []

for v_, e_, w_ in zip(vertex_list, edge_list, edge_weight_list):
    graphs += [create_ig_graph(v_, e_, w_)]

def igplot(g):
    f = igraph.plot(g,
                    layout=g.layout_circle(),
                    bbox=(500,500),
                    margin=(40, 40, 40, 40),
                    vertex_label = [s.replace('|','') for s in g.vs['name']],
                    vertex_label_color='#202020',
                    vertex_color='#969696',
                    vertex_size=20,
                    vertex_font_size=6,
                    edge_width=(1 + 8*np.asarray(g.es['weight'])).tolist(),
                   )
    return f

for graph_, label_ in zip(graphs, ['Chaotic (a=4)',
                                   'Gaussian noise']):
    print(label_)
    display(SVG(igplot(graph_)._repr_svg_()))
https://raw.githubusercontent.com/arthurpessa/ordpy/master/examples/figs/sample_net.png

Contributing

Pull requests addressing errors or adding new functionalities are always welcome.

References

Release files for ordpy 1.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ordpy 1.2.3
File Size Uploaded
ordpy-1.2.3.tar.gz 27.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ordpy 1.2.3
File Interpreter ABI Platform
ordpy-1.2.3-py3-none-any.whl Python 3 none any Details

Total release size: 54.9 kB

Release files / ordpy-1.2.3.tar.gz

Download URL ordpy-1.2.3.tar.gz
Size 27.9 kB
Tags Source
SHA-256 checksum
How to use checksums
fefbe506dea4c82b9c161058fc0bc5acf40246bee8013838d30b249006bad209
BLAKE2b-256 checksum
How to use checksums
614e395719a65872f383d5e1b6f4f3bab52562ac83b8a145a2c2bd1483c9f55f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / ordpy-1.2.3-py3-none-any.whl

Download URL ordpy-1.2.3-py3-none-any.whl
Size 27.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
29424d707f724447ddd6cdcdf4ed29eee0310ee7851a63af2f61cb3e5792a060
BLAKE2b-256 checksum
How to use checksums
6cfe75aedd2eb14fa61d92ad353b0599e683eab4ea012f541932b954aefb6a1f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release history Release notifications | RSS feed

This release

1.2.3 This release

2 release files

1.2.2

2 release files

1.2.0

2 release files

1.1.5

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page