Skip to content

Latest commit

 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Natural Posterior Network (Updated Fork – PyTorch 2.x)

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

Paper | Video

Model Overview


🚀 Updates in This Fork

This fork introduces several improvements so the project runs on modern frameworks:

✅ PyTorch 2.x Support

✅ PyTorch Lightning 2.x API compatibility

✅ TorchMetrics 1.x compatibility

❌ Removed LightKit dependency

Reimplemented required LightKit utilities locally inside the repository.

🛠 Additional Fixes

  • 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.


Features (Original Project)

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.


Installation

Clone the repository:

git clone https://github.com/<your-username>/natural-posterior-network.git
cd natural-posterior-network

Install dependencies with Poetry:

poetry install

(Optional) EC2 setup helper:

sudo bash bin/setup-ec2.sh

Quickstart

Shell Script

Train NatPN on the Sensorless Drive dataset:

poetry run train --dataset sensorless-drive

Track metrics + save models using Weights & Biases:

poetry run train --dataset sensorless-drive --experiment first-steps

See available options:

poetry run train --help

Estimator Usage

Use 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.


Module API

For advanced customization:

from natpn.nn import NaturalPosteriorNetworkModel

Training, evaluation, and fine-tuning can be done using the Lightning modules in natpn.model.


Running Hyperparameter Searches

Use the sweep scripts:

poetry run python sweeps/<file>.py

Set a Weights & Biases project:

export WANDB_PROJECT=natural-posterior-network

Citation

If 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}
}

Contact (Original Authors)

For questions about the original research:

borchero@in.tum.de


👤 Maintainer

Panagiotis Petropoulakis

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

🏛 Academic Affiliation

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.


License

This project remains under the original MIT License.

About

Updated fork of Natural Posterior Network with support for PyTorch 2.x. Removed the LightKit dependency and integrated essential components locally to ensure full compatibility and standalone operation.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages