Giter Club home page Giter Club logo

pycopent's Introduction

PyPI version

copent

Estimating Copula Entropy and Transfer Entropy

Introduction

The nonparametric methods for estimating copula entropy, transfer entropy, and the statistic for multivariate normality test are implemented.

The method for estimating copula entropy composes of two simple steps: estimating empirical copula by rank statistic and estimating copula entropy with the KSG method. Copula Entropy is a mathematical concept for multivariate statistical independence measuring and testing, and proved to be equivalent to mutual information. Different from Pearson Correlation Coefficient, Copula Entropy is defined for non-linear, high-order and multivariate cases, which makes it universally applicable. Estimating copula entropy can be applied to many cases, including but not limited to variable selection and causal discovery (by estimating transfer entropy). Please refer to Ma and Sun (2011) <doi:10.1016/S1007-0214(11)70008-6> for more information.

The nonparametric method for estimating transfer entropy composes of two steps: estimating three copula entropy and calculating transfer entropy from the estimated copula entropies. A function for conditional independence testing is also provided. Please refer to Ma (2019) <arXiv:1910.04375> for more information.

The copula entropy based statistic for multivariate normality test is implemented. Please refer to Ma (2022) <arXiv:2206.05956> for more details.

Functions

  • copent -- estimating copula entropy;
  • construct_empirical_copula -- the first step of the copent function, which estimates empirical copula for data by rank statistics;
  • entknn -- the second step of the copent function, which estimates copula entropy from empirical copula with kNN method;
  • ci -- conditional independence testing based on copula entropy
  • transent -- estimating transfer entropy via copula entropy
  • mvnt -- the copula entropy-based statistic for multivariate normality test

Parameters

  • x: N * d data, N samples, d dimensions;
  • k: kth nearest neighbour, parameter for kNN entropy estimation. default = 3;
  • dtype: distance type, 1 for 'Euclidean', 2/others (default) for 'Maximum distance';
  • lag: time lag. default = 1;
  • mode: running mode, 1(default) for speed/small data, 2 for space/large data.

Installation

The package can be installed from PyPI directly:

pip install copent

The package can be installed from Github:

pip install git+https://github.com/majianthu/pycopent.git

Usage Examples

estimating copula entropy
from numpy.random import multivariate_normal as mnorm
import copent
rho = 0.6
mean1 = [0,0]
cov1 = [ [1,rho],[rho,1] ]
x = mnorm(mean1,cov1,200) # bivariate gaussian 
ce1 = copent.copent(x) # estimated copula entropy
estimating transfer entropy
from copent import transent
from pandas import read_csv
import numpy as np
url = "https://archive.ics.uci.edu/ml/machine-learning-databases/00381/PRSA_data_2010.1.1-2014.12.31.csv"
prsa2010 = read_csv(url)
# index: 5(PM2.5),6(Dew Point),7(Temperature),8(Pressure),10(Cumulative Wind Speed)
data = prsa2010.iloc[2200:2700,[5,8]].values
te = np.zeros(24)
for lag in range(1,25):
	te[lag-1] = transent(data[:,0],data[:,1],lag)
	str = "TE from pressure to PM2.5 at %d hours lag : %f" %(lag,te[lag-1])
	print(str)
multivariate normality test
from numpy.random import multivariate_normal as mnorm
from copent import mvnt
mean1 = [0,0]
cov1 = [[1,0.65],[0.65,1]]
data = mnorm(mean1, cov1, 500) # bivariate gaussian 
stat1 = mvnt(data)

References

  1. Jian Ma and Zengqi Sun. Mutual information is copula entropy. Tsinghua Science & Technology, 2011, 16(1): 51-54. See also arXiv preprint arXiv:0808.0845, 2008.
  2. Jian Ma. Estimating Transfer Entropy via Copula Entropy. arXiv preprint arXiv:1910.04375, 2019.
  3. Jian Ma. Multivariate Normality Test with Copula Entropy. arXiv preprint arXiv:2206.05956, 2022.

pycopent's People

Contributors

majianthu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.