The official package to compute the Triangulated Maximally Filtered Graph (TMFG).
Project description
Fast-TMFG
Fast_TMFG is an ultra-fast implementation of the Triangulated Maximally Fileterd Graph (TMFG). It is based on the work by Guido Previde Massara and is fully implemented by Antonio Briola and Tong Zheng.
The interface is fully scikit-learn compatible. Consequently, it has three main methods:
fit(weights, cov, output)
: Fits the model to the input matrixweights
(e.g. a squared correlation matrix) and input matrixcov
(e.g. covariance matrix). This method computes the Triangulated Maximal Filtered Graph (TMFG) based on the input weight matrix. Theoutput
parameter specifies what is the nature of the desired output:- sparse inverse covariance matrix (
output = 'logo'
) - sparse unweighted weights matrix (
output = 'unweighted_sparse_W_matrix'
) - sparse weighted weights matrix (
output = 'weighted_sparse_W_matrix'
)
- sparse inverse covariance matrix (
transform()
: Returns the computed cliques and separators set of the model. The method also returns the TMFG adjacency matrix.fit_transform(weights, cov, output)
: Fits the model to the input matrixweights
(e.g. a squared correlation matrix) and input matrixcov
(e.g. covariance matrix), and returns the computed cliques and separators set and the TMFG adjacency matrix over the covariance matrix input. Theoutput
parameter specifies what is the nature of the desired output:- sparse inverse covariance matrix (
output = 'logo'
) - sparse unweighted weights matrix (
output = 'unweighted_sparse_W_matrix'
) - sparse weighted weights matrix (
output = 'weighted_sparse_W_matrix'
)
- sparse inverse covariance matrix (
We provide a detailed explanation of each function/method. Such an explanation is entirely generated through ChatGPT.
For a full understanding of the TMFG, we refer the interested reader to the following papers:
- Parsimonious modelling with information filtering networks
- Network filtering for big data: Triangulated maximally filtered graph
- Dependency structures in cryptocurrency market from high to low frequency
Installation
Install the latest version of the package using PyPI:
pip3 install fast-tmfg
Usage Example
import numpy as np
import pandas as pd
from fast_tmfg import *
def generate_random_df(num_rows, num_columns):
data = np.random.randint(0, 100, size=(num_rows, num_columns))
df = pd.DataFrame(data, columns=['col_{}'.format(i) for i in range(num_columns)])
return df
df = generate_random_df(100, 50)
corr = np.square(df.corr())
cov = df.cov()
model = TMFG()
cliques, seps, adj_matrix = model.fit_transform(corr, cov, output='unweighted_sparse_W_matrix')
How to cite us
If you use TMFG in a scientific publication, we would appreciate citations to the following paper:
@article{briola2022dependency,
title={Dependency structures in cryptocurrency market from high to low frequency},
author={Briola, Antonio and Aste, Tomaso},
journal={arXiv preprint arXiv:2206.03386},
year={2022}
}
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
Hashes for fast_tmfg-0.0.10-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb1c44e37bef022933f00833efcc4071d884d61011e813c33a63f0730844194d |
|
MD5 | 64f94b23d1a2aa38557bca27da38c34e |
|
BLAKE2b-256 | cb2ea428686867c76cfb2eeb95fa18b773d55a5489ac47e083b45fe15445a763 |