🔄 ReversibleInstanceNorm
🔄 ReversibleInstanceNorm
🟡 Intermediate
✅ Stable
⏱️ Time Series
🎯 Overview
The ReversibleInstanceNorm layer applies reversible instance normalization to time series data, enabling normalization for training and exact denormalization for inference. This is crucial for time series models where you need to restore predictions to the original data scale.
Key features: - Reversible: Exact denormalization preserves interpretability - Optional Affine: Learnable scale and shift parameters - Multiple Modes: Normalize/denormalize in same layer - Training Stability: Improves convergence and generalization
🔍 How It Works
The layer operates in two modes:
Normalization (Training)
- Compute statistics (mean, std) per instance
- Subtract mean and divide by std
- Optionally apply learnable affine transform
- Store statistics for denormalization
Denormalization (Inference)
- Reverse affine transform (if used)
- Multiply by stored std
- Add stored mean
- Restore to original scale
💡 Why Use This Layer?
| Challenge | Without RevIN | With RevIN |
|---|---|---|
| Scale Sensitivity | Model learns different scales poorly | ✨ Normalized training |
| Interpretability | Predictions in model scale | 🎯 Original data scale |
| Stability | Training instability | ⚡ Stable convergence |
| Transfer Learning | Limited generalization | 🔄 Better transfer capability |
📊 Use Cases
- Time Series Forecasting: Normalize input and denormalize output
- Multivariate Scaling: Handle different feature scales
- Domain Adaptation: Transfer models across datasets
- Anomaly Detection: Normalize for training, denormalize for detection
- Data Augmentation: Consistent scaling across augmented samples
🚀 Quick Start
Basic Normalization
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | |
In a Forecasting Pipeline
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | |
🔧 API Reference
1 2 3 4 5 6 7 8 9 | |
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
num_features |
int |
— | Number of features |
eps |
float |
1e-5 | Numerical stability |
affine |
bool |
False | Learnable scale/shift |
subtract_last |
bool |
False | Normalize by last value |
non_norm |
bool |
False | Disable normalization |
name |
str \| None |
None | Layer name |
💡 Best Practices
- Use Before Embedding: Normalize raw data before embeddings
- Affine Transform: Enable for flexible scaling in complex models
- Denormalize Output: Always denormalize final predictions
- Feature Scaling: Ensures all features contribute equally
- Statistical Stability: eps prevents division by zero
⚠️ Common Pitfalls
- ❌ Forgetting denormalization: Loss of interpretability
- ❌ Wrong mode: Using 'norm' when expecting 'denorm'
- ❌ Batch dependency: Ensure consistent batch processing
- ❌ Shared statistics: Don't mix statistics across batches
Last Updated: 2025-11-04 | Keras: 3.0+ | Status: ✅ Production Ready