Skip to main content

A Python package for data analysis with permutation entropy and ordinal networks methods.

Project description

https://img.shields.io/pypi/v/ordpy?style=plastic:alt:PyPI https://img.shields.io/github/license/arthurpessa/ordpy?style=plastic:alt:GitHub

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.

ordpy implements the following data analysis methods:

  • 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].

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://github.com/arthurpessa/ordpy/blob/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://github.com/arthurpessa/ordpy/blob/master/examples/figs/sample_net.png

References

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ordpy-1.0.0.tar.gz (20.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ordpy-1.0.0-py3-none-any.whl (19.9 kB view details)

Uploaded Python 3

File details

Details for the file ordpy-1.0.0.tar.gz.

File metadata

  • Download URL: ordpy-1.0.0.tar.gz
  • Upload date:
  • Size: 20.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1.post20200622 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.7

File hashes

Hashes for ordpy-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c09049d30fcc6cc35b76b41f476bd847ced0f294ee14f05e4e58a97d32f91010
MD5 c6c0a988c8700e36f06003856471f163
BLAKE2b-256 ea833a06460e20f2c30b79363b4c0292c1857033a2584b56977ff26f9756577e

See more details on using hashes here.

File details

Details for the file ordpy-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: ordpy-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 19.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1.post20200622 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.7

File hashes

Hashes for ordpy-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8b9828b782e2645f4639a29f5a7c00650e7546276b39fdb90393393d9b3ac83e
MD5 ad788a4408501907a856986c7b32dc5b
BLAKE2b-256 46a64ffd597ec04abcda6affd86798fd42499d66a02661b598499d7a84a454e2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page