A robust package for extrapolation control in neural networks
Project description
XtrapNet - Extrapolation-Aware Neural Networks
XtrapNet is a cutting-edge deep learning framework designed to handle out-of-distribution (OOD) extrapolation in neural networks. Unlike traditional models that fail when encountering unseen data, XtrapNet:
- ✅ Detects OOD inputs and allows custom fallback behaviors
- ✅ Supports ensemble uncertainty quantification
- ✅ Offers multiple extrapolation control mechanisms
- ✅ Works with PyTorch and integrates seamlessly with any model
Installation
To install XtrapNet:
pip install xtrapnet
Usage Example
import numpy as np
from xtrapnet import XtrapNet, XtrapTrainer, XtrapController
# Generate dummy training data
features = np.random.uniform(-3.14, 3.14, (100, 2)).astype(np.float32) labels = np.sin(features[:, 0]) * np.cos(features[:, 1]).reshape(-1, 1)
# Train the model
net = XtrapNet(input_dim=2) trainer = XtrapTrainer(net) trainer.train(labels, features)
# Define an extrapolation-aware controller
controller = XtrapController( trained_model=net, train_features=features, train_labels=labels, mode='warn' )
# Test prediction with OOD handling
test_input = np.array([[5.0, -3.5]]) # OOD point prediction = controller.predict(test_input) print("Prediction:", prediction)
Extrapolation Handling Modes
XtrapNet allows you to control how the model reacts to out-of-distribution (OOD) inputs:
| Mode | Behavior |
|---|---|
| clip | Restricts predictions within known value ranges |
| zero | Returns 0 for OOD inputs |
| nearest_data | Uses the closest training point's prediction |
| symmetry | Uses symmetry-based assumptions to infer values |
| warn | Prints a warning but still predicts |
| error | Raises an error when encountering OOD data |
| highest_confidence | Selects the lowest-variance prediction |
| backup | Uses a secondary model when uncertainty is high |
Visualizing Extrapolation Behavior
import matplotlib.pyplot as plt
x_test = np.linspace(-5, 5, 100).reshape(-1, 1)
mean_pred, var_pred = controller.predict(x_test, return_variance=True)
plt.plot(x_test, mean_pred, label='Ensemble Mean', color='blue')
plt.fill_between(x_test.flatten(), mean_pred - var_pred, mean_pred + var_pred, color='blue', alpha=0.2, label='Uncertainty (Variance)')
plt.legend()
plt.show()
This generates an extrapolation-aware prediction plot with uncertainty bands! 🔥
Future Roadmap
We are actively developing new features:
- ✅ Bayesian Neural Network support
- ✅ Physics-Informed Neural Networks
- ✅ Integration with Large Language Models (LLMs)
- 🚀 Adaptive learning for OOD generalization
- 🚀 Built-in anomaly detection for real-world data
Contributing
Want to improve XtrapNet? Feel free to submit a pull request! Contributions are welcome.
🔗 GitHub: https://github.com/cykurd/xtrapnet
License
This project is licensed under the MIT License.
Support
If you have any questions, feel free to open an issue on GitHub or reach out via cykurd@gmail.com. 🚀
🔥 Why Use XtrapNet?
Traditional neural networks struggle with out-of-distribution (OOD) data.
🔥 XtrapNet is the first open-source library designed to intelligently control extrapolation!
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file xtrapnet-0.1.2.tar.gz.
File metadata
- Download URL: xtrapnet-0.1.2.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
50cebe1bb7d1a569d30f64f6f0dbd6cb1a81206f817ae4dc2047b1885e1827f5
|
|
| MD5 |
5140eb519d8c52a205839289ccdb0b5d
|
|
| BLAKE2b-256 |
1c2eaf9ae77b7fa2ae9ff3905e3c76db36893587043cf151c6721d36377b8f9d
|
File details
Details for the file xtrapnet-0.1.2-py3-none-any.whl.
File metadata
- Download URL: xtrapnet-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7a8eda99b63adc7c341babfa57c1bd4b01119c8090910bebe1311e9fd9355fd2
|
|
| MD5 |
86ec7e494be1c50c593decc727ad0bd8
|
|
| BLAKE2b-256 |
2cbf05d878e9521e40eccd46253a575948d1b8dad49e2036820590d1ddf5d800
|