This repository is a community-maintained fork of the original Natural Posterior Network (NatPN) and Natural Posterior Ensemble (NatPE) implementation.
It updates the original codebase to modern libraries, removes deprecated dependencies, and ensures compatibility with current PyTorch tooling — while fully preserving the original algorithm and authorship.
This work builds on the paper:
Natural Posterior Network: Deep Bayesian Predictive Uncertainty for Exponential Family Distributions
Bertrand Charpentier*, Oliver Borchert*, Daniel Zügner, Simon Geisler, Stephan Günnemann
International Conference on Learning Representations (ICLR), 2022
This fork introduces several improvements so the project runs on modern frameworks:
Reimplemented required LightKit utilities locally inside the repository.
- Updated metrics to the new TorchMetrics API (AUROC, AUPRC, Accuracy…)
- Removed deprecated PyTorch Lightning arguments (
compute_on_step, etc.) - Fixed dataset loaders
- Ensured compatibility with Python 3.9 and 3.10
- Added missing utilities so the project runs end-to-end again
All improvements were made with respect for the original structure and logic.
The implementation of NatPN provides:
- High-level estimator interface (Scikit-learn style)
- Simple bash script to train and evaluate NatPN
- Ready-to-use PyTorch Lightning data modules
for 8 of the 9 datasets used in the original paper* - Pretrained model hosting on Weights & Biases
- Example notebooks for inference and experiments
*The Kin8nm dataset is excluded since it is no longer available in the UCI repository.
Clone the repository:
git clone https://github.com/<your-username>/natural-posterior-network.git
cd natural-posterior-networkInstall dependencies with Poetry:
poetry install(Optional) EC2 setup helper:
sudo bash bin/setup-ec2.shTrain NatPN on the Sensorless Drive dataset:
poetry run train --dataset sensorless-driveTrack metrics + save models using Weights & Biases:
poetry run train --dataset sensorless-drive --experiment first-stepsSee available options:
poetry run train --helpUse NatPN as a scikit-learn-like model:
from natpn import NaturalPosteriorNetwork
model = NaturalPosteriorNetwork()
model.fit(X_train, y_train)
pred = model.predict(X_test)See examples/estimator.ipynb for details.
For advanced customization:
from natpn.nn import NaturalPosteriorNetworkModelTraining, evaluation, and fine-tuning can be done using the Lightning modules in natpn.model.
Use the sweep scripts:
poetry run python sweeps/<file>.pySet a Weights & Biases project:
export WANDB_PROJECT=natural-posterior-networkIf you use NatPN or this implementation, please cite the original authors:
@inproceedings{natpn,
title={{Natural} {Posterior} {Network}: {Deep} {Bayesian} {Predictive} {Uncertainty} for {Exponential} {Family} {Distributions}},
author={Charpentier, Bertrand and Borchert, Oliver and Z\"{u}gner, Daniel and Geisler, Simon and G\"{u}nnemann, Stephan},
booktitle={International Conference on Learning Representations},
year={2022}
}For questions about the original research:
Doctoral Researcher
Technische Universität München (TUM)
This repository is actively maintained and modernized as part of my doctoral research at TUM.
Supervision:
- Prof. Dr.-Ing. André Borrmann
Chair of Computing in Civil and Building Engineering - Prof. Dr.-Ing. habil. Alois Christian Knoll
Chair of Robotics, AI and Real-time Systems
Chair of Computing in Civil and Building Engineering (CCBE)
TUM School of Engineering and Design
https://www.cee.ed.tum.de/ccbe/home/
Research focus includes computational methods for the lifecycle of built facilities, digital twinning, robotic construction, and AI-driven modeling.
Chair of Robotics, AI and Real-time Systems
TUM School of Computation, Information and Technology
https://www.ce.cit.tum.de/air/home/
Research areas include cognitive robotics, machine learning, human-robot interaction, and real-time AI systems.
For repository-related questions, please open an issue.
This project remains under the original MIT License.
