Skip to main content

A package to estimate time irreversibility in time series using gradient boosting classification.

Project description

Time Irreversibility Estimator

The TimeIrreversibilityEstimator is a Python package designed to estimate time irreversibility in time series using gradient boosting classification. This package leverages the power of xgboost to classify forward and backward trajectories, providing a measure of time irreversibility.

Key Features

  • Quantification of Irreversibility: Measures the time irreversibility in high-dimensional time series using a model-free, non-linear approach.
  • Interaction Constraints: Allows the specification of interaction constraints to explore the contribution of different feature interactions to irreversibility.
  • Cross-Validation: Implements k-fold and group k-fold cross-validation for a robust and reliable estimation.
  • Trajectory Encoding: Supports any encoding strategy for time series data allowing for ad-hoc hypothesis testing.

Installation

You can install the package via pip:

pip install time_irreversibility_estimator

Concept

The method introduced in the accompanying paper, "Functional Decomposition and Estimation of Irreversibility in Time Series via Machine Learning", leverages gradient boosting to quantify the time irreversibility in high-dimensional time series. The approach rephrases the problem as a binary classification task where the direction of time (forward or backward) is to be determined. The time irreversibility measure is derived from the classifier's performance, specifically from the average log differences of predicted probabilities for forward and backward trajectories.

Usage

Below is an example of how to use the TimeIrreversibilityEstimator:

import time_irreversibility_estimator as ie
import numpy as np

# Example forward trajectories
q_forward = np.random.normal(0.6, 1, size=(10000, 6, 1)).cumsum(axis=1)

# Example of encoding function
encoding_fun = lambda x: np.diff(x, axis=0)

# Example interaction constraints: '[[0, 1], [2, 3, 4]]'
# This means that features 0 and 1 can interact with each other, and features 2, 3, and 4 can interact with each other.
interaction_constraints = '[[0, 1], [2, 3, 4]]'

estimator = ie.TimeIrreversibilityEstimator(interaction_constraints=interaction_constraints, verbose=True, random_state=0)
irreversibility_value = estimator.fit_predict(q_forward=q_forward, encoding_fun=encoding_fun)

print(f"Estimated time irreversibility: {irreversibility_value}")

# Example with GroupKFold
groups = np.random.randint(0, 5, size=q_forward.shape[0])  # Example group indices
estimator = ie.TimeIrreversibilityEstimator(interaction_constraints=interaction_constraints, verbose=True, random_state=0)
irreversibility_value = estimator.fit_predict(q_forward=q_forward, n_splits=5, groups=groups, encoding_fun=encoding_fun)

print(f"Estimated time irreversibility with GroupKFold: {irreversibility_value}")

Class Details

TimeIrreversibilityEstimator

A class to estimate time irreversibility in time series using gradient boosting classification.

Attributes:

  • max_depth (int): Maximum depth of the trees in the gradient boosting model.
  • n_estimators (int): Number of trees in the gradient boosting model.
  • learning_rate (float): Step size shrinkage used in update of the gradient boosting model.
  • early_stopping_rounds (int): Number of rounds for early stopping.
  • verbose (bool): If True, print progress messages.
  • interaction_constraints (str): Constraints on interactions between features.
  • random_state (int or None): Seed for random number generator.
  • store (bool): If True, store the models, the encodings, the indices, the probabilities, and the individual irreversibility values.
  • kwargs (dict): Additional parameters to be passed to the XGBoost classifier

Methods:

  • train(self, x_forward_train, x_backward_train, x_forward_test=None, x_backward_test=None): Trains the model on the training set with optional test set early stopping and returns the trained model.
  • evaluate(self, model, x_forward, x_backward): Evaluates the model on the test set and returns the time irreversibility and individual log differences of the probabilities.
  • fit_predict(self, q_forward=None, x_forward=None, x_backward=None, encoding_fun=None, n_splits=5, groups=None): Performs k-fold or group k-fold cross-validation to estimate time irreversibility.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Contributing

Contributions are welcome! If you would like to contribute to the code or to request a new feature, please contact christian.bongiorno@centralesupelec.fr.

Contact

If you have any questions or feedback, please contact Christian Bongiorno at christian.bongiorno@centralesupelec.fr or Michele Vodret at mvodret@gmail.com.

Acknowledgements

This package uses the following libraries:

  • numpy>=2.0.0
  • scikit-learn>=1.5.0
  • xgboost>=1.5.0

Citation

If you use this package in your research, please cite our paper:

@article{vodret2024functional,
  title={Functional Decomposition and Estimation of Irreversibility in Time Series via Machine Learning},
  author={Vodret, Michele and Pacini, Cristiano and Bongiorno, Christian},
  journal={arXiv preprint arXiv:2407.06063},
  year={2024}
}

Authors and Contributors

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

time_irreversibility_estimator-0.4.2.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file time_irreversibility_estimator-0.4.2.tar.gz.

File metadata

File hashes

Hashes for time_irreversibility_estimator-0.4.2.tar.gz
Algorithm Hash digest
SHA256 f3c7972b4f331f2910b81af32ff7c949b884f0b198592eaeb67589d49fe2cd14
MD5 98959f73367d9a926a08e4e8bc53b509
BLAKE2b-256 80a7a4d1e30d18db9f37018bf40d3aa251d52a5d5653e0522243d0dbb8976f93

See more details on using hashes here.

File details

Details for the file time_irreversibility_estimator-0.4.2-py3-none-any.whl.

File metadata

File hashes

Hashes for time_irreversibility_estimator-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7784cac689ad7017ef4fb7215cba5aefd31d16076e566cda02c41e3146060733
MD5 53ed5c6447ce8884be802eb04720592e
BLAKE2b-256 42d39301f6e77340c9de83ba3182c3404386bd06514956a307e0e9cb03ffd6e6

See more details on using hashes here.

Supported by

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