Skip to main content

Python implementation of the Scalable Spatiotemporally Varying Coefficient Modelling with Bayesian Kernelized Tensor Regression

Project description

pyBKTR

Intro

This project is a Python implementation of the BKTR algorithm presented by Mengying Lei, Aurélie Labbe & Lijun Sun (2023). The article presenting the algorithm can be found here.

BKTR stands for Scalable Spatiotemporally Varying Coefficient Modelling with Bayesian Kernelized Tensor Regression. It allows to model spatiotemporally varying coefficients using a Bayesian framework. We implemented the algorithm and more in a Python package that uses PyTorch as a tensor operation backend.

For information, an alternative R implementation of the algorithm can be found here. The Python implementation is synchronized with this repository and development is done in parallel.

An article presenting the R package in details is currently in preparation and should be available soon. The documentation for the R package is a work in progress and will be made available in the coming weeks.

Installation

Install from PyPI

The package is available on PyPI and can be installed using pip:

pip install pyBKTR

Install from source

To install the package from source and use the latest release, you can clone the repository and install it using pip and the repository url:

pip install git+https://github.com/julien-hec/pyBKTR.git

Simple Example

To verify that everything is running smooth you can try to run a BKTR regression on the BIXI data presented in the package. (The data is already preloaded in the package in the BixiData class)

The following code will run a BKTR regression using sensible defaults on the BIXI data and print a summary of the results.

library(BKTR)
from pyBKTR.bktr import BKTRRegressor
from pyBKTR.examples import BixiData

bixi_data = BixiData()
bktr_regressor = BKTRRegressor(
    data_df=bixi_data.data_df,
    spatial_positions_df=bixi_data.spatial_positions_df,
    temporal_positions_df=bixi_data.temporal_positions_df
)
bktr_regressor.mcmc_sampling()
print(bktr_regressor.summary)

Contributing

Contributions are welcome. Do not hesitate to open an issue or a pull request if you encounter any problem or have any suggestion.

Dev Notes

Dev environment setup

If you wish to contribute to this project, we strongly recommend you to use the precommit setup created in the project. To get started, simply follow these instructions.

First, install the project locally with the development resources. If you use zsh, you might need to put single quotes around the path '.[dev]'

pip install .[dev]

Then, install the git hook scripts.

pre-commit install

Finally, everything should work fine if when run the pre-commit hooks.

pre-commit run --all-files

Documentation Generation

You should already have the dev environment setup

Pandoc needs to be installed on your local machine, follow the instructions in the following link https://pandoc.org/installing.html

From the docs folder run the following line to regenerate the static doc

sphinx-apidoc -f -o . ../pyBKTR

then

make html

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

pyBKTR-0.1.0.tar.gz (210.6 kB view details)

Uploaded Source

Built Distribution

pyBKTR-0.1.0-py3-none-any.whl (219.3 kB view details)

Uploaded Python 3

File details

Details for the file pyBKTR-0.1.0.tar.gz.

File metadata

  • Download URL: pyBKTR-0.1.0.tar.gz
  • Upload date:
  • Size: 210.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.0

File hashes

Hashes for pyBKTR-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b39d5d83ca965fd7c39ded1ea1bdfaa41003a3f149eacbf3b109dbbceddd2185
MD5 ec2fff0e6e009fa5ae953513bec9b3f2
BLAKE2b-256 c8a951e55ea46029cc2fc2c2cf0d3ce6a4a18c9e8f9cc29bb27c31f726a9b248

See more details on using hashes here.

Provenance

File details

Details for the file pyBKTR-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pyBKTR-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 219.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.0

File hashes

Hashes for pyBKTR-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2d9cf39923ec7edf1f08b3b6c8fabc335615c99f355a8e3ce54b9c1d2773be19
MD5 8dd2d44a12265c075113d65b27ecf168
BLAKE2b-256 55ff7e65159f8b2a5defc224c33789eec8faeb385be24d2fb4b8bd9f19d314ad

See more details on using hashes here.

Provenance

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