How to Use Fortuna: A Library for Uncertainty Quantification

Apr 14, 2022 | Educational

Understanding predictive uncertainty is essential when making critical decisions based on model outputs. Fortuna is designed to help you quantify uncertainty easily and efficiently. In this article, we’ll guide you through how to get started with Fortuna and troubleshoot common issues.

What is Fortuna?

Fortuna is a library that provides various methods for uncertainty quantification. It allows you to run benchmarks and integrate uncertainty into production systems. The library supports calibration and conformal methods and offers Bayesian inference for deep learning models written in Flax.

Usage Modes

Fortuna provides three primary usage modes:

  • From Uncertainty Estimates: This method is quick and requires minimal compatibility. It uses conformal prediction methods for classification and regression.
  • From Model Outputs: This mode assumes you have model outputs readily available, enabling you to calibrate these outputs and estimate uncertainty.
  • From Flax Models: Here, the focus is on deep learning models written in Flax and allows for more accurate predictive uncertainty quantification using Bayesian inference.

How to Get Started

To install Fortuna, follow these steps:

  • Ensure you have JAX installed in your virtual environment.
  • Run the following command to install Fortuna:
  • pip install aws-fortuna
  • Alternatively, to build the package using Poetry, install Poetry and run:
  • poetry install

Creating Conformal Prediction Intervals

Let’s explore how to create calibrated versions of credible intervals using Fortuna. Imagine you are a chef expecting a perfect cake. Your recipe provides ranges for the ingredients (like flour and sugar) but you want to ensure those quantities yield a delicious cake every time. Just like calibrating your ingredients ensures a perfect cake, calibrating credible intervals ensures accurate predictive results.

In the context of the code example from Fortuna:

from fortuna.conformal import QuantileConformalRegressor

conformal_intervals = QuantileConformalRegressor().conformal_interval(
      val_lower_bounds=val_lower_bounds,
      val_upper_bounds=val_upper_bounds,
      test_lower_bounds=test_lower_bounds,
      test_upper_bounds=test_upper_bounds,
      val_targets=val_targets,
      error=error
)

This code snippet takes various bounds and calibration error to generate refined prediction intervals, akin to adjusting your ingredient amounts to ensure your cake rises perfectly every time.

Troubleshooting

If you encounter issues while using Fortuna, here are some troubleshooting tips:

  • Ensure that JAX is properly installed and the latest version is in use.
  • Check your input arrays; invalid or mismatched dimensions can lead to errors.
  • Ensure that your framework (e.g., Flax) is compatible with the versions recommended in the documentation.
  • If you face deployment problems, consult the configuration YAML file for possible misconfigurations.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Conclusion

Fortuna is a robust library that simplifies the complexities of uncertainty quantification. The various usage modes and intuitive API make it an excellent choice for both experienced developers and newcomers to the field. Don’t forget, the more you practice using Fortuna, the more familiar you’ll become with its capabilities.

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox