Skip to main content

Scalable spatiotemporal prediction with Bayesian neural fields

Project description

Bayesian Neural Fields for Spatiotemporal Prediction

Unittests PyPI version

This is not an officially supported Google product.

Spatially referenced time series (i.e., spatiotemporal) datasets are ubiquitous in scientific, engineering, and business-intelligence applications. This repository contains an implementation of the Bayesian Neural Field (BayesNF) a novel spatiotemporal modeling method that integrates hierarchical probabilistic modeling for accurate uncertainty estimation with deep neural networks for high-capacity function approximation.

Bayesian Neural Fields infer joint probability distributions over field values at arbitrary points in time and space, which makes the model suitable for many data-analysis tasks including spatial interpolation, temporal forecasting, and variography. Posterior inference is conducted using variationally learned surrogates trained via mini-batch stochastic gradient descent for handling large-scale data.

Installation

bayesnf can be installed from the Python Package Index (PyPI) using:

python -m pip install bayesnf

The typical install time is 1 minute. This software is tested on Python 3.9 with a standard Debian GNU/Linux setup. The large-scale experiments in scripts/ were run using TPU v3-8 accelerators. For running BayesNF locally on medium to large-scale data, a GPU is required at minimum.

Documentation and Tutorials

Please visit https://google.github.io/bayesnf

Quick start

# Load a dataframe with "long" format spatiotemporal data.
df_train = pd.read_csv('chickenpox.5.train.csv',
  index_col=0, parse_dates=['datetime'])

# Build a BayesianNeuralFieldEstimator
model = BayesianNeuralFieldMAP(
  width=256,
  depth=2,
  freq='W',
  seasonality_periods=['M', 'Y'],
  num_seasonal_harmonics=[2, 10],
  feature_cols=['datetime', 'latitude', 'longitude'],
  target_col='chickenpox',
  observation_model='NORMAL',
  timetype='index',
  standardize=['latitude', 'longitude'],
  interactions=[(0, 1), (0, 2), (1, 2)])

# Fit the model.
model = model.fit(
  df_train,
  seed=jax.random.PRNGKey(0),
  ensemble_size=ensemble_size,
  num_epochs=num_epochs)

# Make predictions of means and quantiles on test data.
df_test = pd.read_csv('chickenpox.5.test.csv',
  index_col=0, parse_dates=['datetime'])

yhat, yhat_quantiles = model.predict(df_test, quantiles=(0.025, 0.5, 0.975))

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

bayesnf-0.1.2.tar.gz (23.1 kB view details)

Uploaded Source

Built Distribution

bayesnf-0.1.2-py3-none-any.whl (24.7 kB view details)

Uploaded Python 3

File details

Details for the file bayesnf-0.1.2.tar.gz.

File metadata

  • Download URL: bayesnf-0.1.2.tar.gz
  • Upload date:
  • Size: 23.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.13

File hashes

Hashes for bayesnf-0.1.2.tar.gz
Algorithm Hash digest
SHA256 71ae3efb849db017d40ad18110e210f54ef068ba7b00f216d518d5d92c5f9f3e
MD5 f594b3f8f2f3fce38d837a33f1170348
BLAKE2b-256 8e3a02bf7d33d70d51527dd6704d18e1986daecb540b5bdded9b0e225f8727e0

See more details on using hashes here.

File details

Details for the file bayesnf-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: bayesnf-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 24.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.13

File hashes

Hashes for bayesnf-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 540a18b37c20f221f1e72fe453601e47398b4f660ac0948bfccd67783f7dc7d7
MD5 07b5662af80e853e3f597879f2eb26fb
BLAKE2b-256 59da8a7c8c1eb2874892658a7b936f6be53f28aee18a8a42efcab9565a0c2a04

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