N-HiTS › Formula
Machine Learning from ScratchAll chapters N-HiTS › FormulaOne section · Sections in this chapter2 / 8 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
The Challenge: Understanding Time at Multiple Scales
Imagine you're forecasting retail sales. A sudden spike on Tuesday might catch your attention, but is it meaningful? To answer that, you need context: Is this part of a weekly shopping pattern? Does it align with monthly seasonal trends? Or is it just noise? The challenge is that time series contain patterns operating at fundamentally different speeds: daily fluctuations overlay weekly cycles, which nest within monthly seasonality, all embedded in yearly trends.
Traditional forecasting methods often force a choice: focus on fine-grained details and miss the big picture, or smooth everything and lose important short-term signals. But what if we didn't have to choose? What if we could simultaneously understand both the forest and the trees?
NHITS solves this with a simple insight: we should process time series at multiple resolutions, just as we naturally think about time. When you examine a stock chart, you might zoom in to see minute-by-minute volatility, then zoom out to understand the monthly trend. NHITS does exactly this mathematically, creating multiple "views" of the same time series, each optimized for a different temporal scale, then combining these perspectives into a unified forecast.

Building the Foundation: Hierarchical Decomposition
The Core Problem: A single time series contains information at multiple temporal scales, but a single neural network struggles to learn all scales simultaneously. High-frequency noise can overwhelm long-term trends, and trying to capture everything at once leads to mediocre performance across all scales.
The Solution: Create a hierarchy, a pyramid of views where each level focuses on a specific temporal resolution. This changes how we approach the problem. Instead of asking one network to do everything, we ask multiple specialized networks to each handle what they do best.
Why We Need Multiple Scales: The Intuition
Consider what happens when you look at a time series through different "lenses":
-
Fine-grained view: Every point matters
You see daily fluctuations and immediate patterns, along with noise. This detail is important for capturing short-term dynamics, but it's also where noise lives. -
Medium-grained view: Trends emerge
When you average pairs of consecutive points, noise cancels out while trends become clearer. Weekly patterns start to emerge. -
Coarse-grained view: The big picture
Averaging over larger windows reveals long-term trends and seasonal patterns that were invisible in the noisy original data.
The central insight is that each scale reveals different information. Fine scales capture immediate dynamics; coarse scales reveal structural patterns. We need both, but they're best learned separately.
The Mathematical Framework: Downsampling
To create these multiple views, we systematically reduce temporal resolution through downsampling. For a time series with length , we create hierarchical levels, where level has downsampling factor .
The downsampled representation at level is:
where:
- : original time series with time steps
- : hierarchical level index ()
- : downsampling factor for level (e.g., , , )
- : downsampled time series at level
- : time index in the downsampled series
What does downsampling do? The most natural approach averages consecutive values, creating a smoother, lower-resolution version:
where:
- : downsampling factor (window size for averaging)
- : original time series values
- : index in the downsampled series (each corresponds to a window in the original)
- : offset within the averaging window ()
- : original time series value at position
This formula tells us to:
- Partition the time series into consecutive windows of size
- Average all values within each window
- Produce a new time series with the original temporal resolution
Why averaging? Averaging serves two important purposes:
- Noise reduction: High-frequency noise tends to cancel out when averaged, while true patterns persist
- Scale bridging: It creates a natural mathematical connection between different temporal resolutions
The Hierarchy in Action:
- Level 0 (): The original time series , with every detail preserved
- Level 1 (): Each point averages two consecutive originals, reducing noise and making trends clearer
- Level 2 (): Each point averages four originals, allowing long-term patterns to emerge
- Level 3 (): Even coarser, with seasonal and cyclical patterns dominating
This creates a pyramid: the base contains all details, while higher levels reveal increasingly broad patterns. Each level is a different "zoom level" on the same underlying data.



The Core Insight: Specialized Neural Networks for Each Scale
We now have multiple views of our time series, each revealing different temporal patterns. This raises an important question: Should we use one network to learn all scales, or separate networks for each?
The answer lies in understanding what each network needs to learn. Consider the difference between predicting tomorrow's stock price versus next year's trend:
- Fine-scale prediction requires handling rapid fluctuations and immediate market reactions amid noise
- Coarse-scale prediction requires understanding long-term economic cycles, seasonal patterns, and structural trends
These are fundamentally different learning problems. A single network trying to do both faces a conflict: it needs to simultaneously be sensitive to noise (for fine scales) and ignore noise (for coarse scales). This is why specialization matters.
The Prediction Formula
At each hierarchical level , we employ a dedicated neural network that learns patterns specific to that temporal scale. The prediction at level is:
where:
- : hierarchical level index ()
- : neural network specialized for patterns at scale (a function mapping input windows to predictions)
- : input window containing the past time steps at level 's resolution
- : input window size (number of past time steps used for prediction)
- : time indices from to (exclusive of )
- : predicted future value(s) at level 's native resolution
- The hat () indicates this is a predicted value, not an observed value
Why this works: Each network operates in a space optimized for its scale. The fine-scale network sees high-resolution data with all its noise and volatility, exactly what it needs to learn short-term patterns. The coarse-scale network sees smoothed, downsampled data where long-term trends are clear, exactly what it needs to learn seasonal patterns.
The Architecture: Encoder-Processor-Decoder
Each neural network is typically implemented as a multi-layer perceptron (MLP) with three components:
-
Encoder layers: Transform the input window into a rich internal representation that captures relevant patterns at scale
-
Processing layers: Learn complex non-linear relationships specific to the temporal scale. These layers discover how past values at this resolution relate to future values
-
Decoder layers: Generate predictions based on the learned representation
This architecture allows each network to specialize: fine-scale networks learn to predict immediate fluctuations, while coarse-scale networks learn to predict broader movements and seasonal patterns. The separation prevents the learning conflicts that plague single-scale approaches.
Bringing It Together: Hierarchical Reconstruction
We've made predictions at multiple scales, but they exist in different "spaces": Level 0 predictions are at the original resolution, Level 1 predictions are at half resolution, and Level 2 predictions are at quarter resolution. How do we combine these into a single, coherent forecast?
This is the reconstruction problem: we need to bring all predictions to a common resolution, then intelligently merge them. The solution has two parts: upsampling (bringing everything to the same resolution) and weighted combination (merging the multi-scale insights).
Step 1: Upsampling: Bringing Coarse Predictions to Fine Resolution
A coarse-scale prediction like represents a trend over multiple fine-scale time steps. To combine it with fine-scale predictions, we need to expand it back to the original resolution through upsampling:
where:
- : prediction at hierarchical level (at level 's native resolution)
- : downsampling factor for level (determines how many times each value is repeated)
- Returns: upsampled prediction at the original temporal resolution
The simplest and most interpretable approach is repetition: each coarse-scale value is repeated times to fill the higher-resolution timeline:
where:
- : coarse-scale prediction at level
- : upsampling factor (number of repetitions per value, equal to the downsampling factor )
- : each value in is repeated times consecutively
Why repetition? This has a clear interpretation: the coarse-scale network is saying "my best estimate for the trend over these time steps is this value." Repeating it maintains that interpretation while bringing it to the fine resolution needed for combination.
More advanced interpolation methods (linear, cubic) can also be used, but repetition often works well and preserves the semantic meaning of coarse-scale predictions.
Step 2: Weighted Combination: Merging Multi-Scale Insights
With all predictions now at the same resolution, we combine them using learnable weights that determine each scale's contribution:
where:
- : final combined prediction at time (at original temporal resolution)
- : hierarchical level index, ranging from to
- : total number of hierarchical levels
- : learnable combination weight for level (learned during training, typically normalized so )
- : prediction from level (at level 's native resolution)
- : downsampling factor for level (used for upsampling)
- : upsampled prediction from level (at original resolution)
The weights are learned during training and represent the model's confidence in each scale's predictive power. This design is powerful for three reasons:
-
Adaptive weighting: Different time series require different scale balances. For volatile financial data, short-term patterns might dominate (large ). For seasonal sales data, long-term trends might be more important (large ). The model adapts automatically.
-
Automatic scale selection: Rather than manually deciding which scales matter, the model learns this from data. If a particular scale isn't helpful, its weight will be small.
-
Interpretability: By examining learned weights, we understand which temporal scales drive the forecast. This provides insight into the data's structure and the model's reasoning.
The intuition: Think of this as a weighted vote. Each hierarchical level casts a "vote" (its prediction) about the future, and the weights determine how much we trust each vote. The final forecast is a consensus that respects both immediate dynamics and long-term trends.


The Training Objective: Multi-Scale Loss
Training a hierarchical system presents a unique challenge: we have multiple networks, each operating at different resolutions, and we need them to work together coherently. How do we design a loss function that ensures all levels learn meaningful patterns?
The answer is a multi-scale loss that supervises each level at its native resolution:
where:
- : total multi-scale loss (scalar value to be minimized during training)
- : hierarchical level index, ranging from to
- : total number of hierarchical levels
- : loss weight for level (can be set to balance contributions across scales, or set to for equal weighting)
- : mean squared error between observed and predicted values at level
- : observed (ground truth) values at level 's resolution (downsampled from original )
- : predicted values at level 's resolution (output of network )
- Computed as: where is the number of time steps at level (indices range from to )
Why this design works:
-
Direct supervision at native resolution: Each network receives a learning signal at its own temporal scale. The fine-scale network learns from fine-scale targets; the coarse-scale network learns from coarse-scale targets. This prevents the mismatch that occurs when trying to learn coarse patterns from fine-scale data.
-
Balanced learning across scales: The weights can be adjusted to ensure all scales contribute to the prediction. Without this, fine-scale patterns might dominate simply because there are more data points at fine resolutions. The weights ensure each scale gets appropriate attention.
-
Coherent multi-scale predictions: By training all levels jointly, the model learns to make predictions that are consistent across scales. A coarse-scale prediction should align with the smoothed version of fine-scale predictions. This coherence emerges naturally from joint training.
The training process: During each training step, we compute predictions at all hierarchical levels, measure errors at each level's native resolution, and update all networks simultaneously. This ensures that each network specializes in its scale while contributing to a unified forecasting system.
Why This Framework Works: Mathematical Properties
The hierarchical structure of NHITS provides mathematical advantages that explain why it often outperforms single-scale approaches. Let's examine four key properties:
1. Multi-Scale Pattern Capture: The decomposition creates a mathematical guarantee: both high-frequency patterns (fine scales) and low-frequency patterns (coarse scales) have dedicated neural networks optimized for their specific characteristics. This solves a fundamental problem: in single-scale models, high-frequency noise often dominates the loss function, obscuring long-term trends. By separating scales, each network can focus on patterns appropriate to its resolution without interference from other scales.
2. Smooth Interpolation: The upsampling mechanism, combined with learned combination weights, creates mathematically smooth transitions between temporal scales. This prevents the jagged artifacts that arise from naive scale mixing (like simply concatenating features from different scales). The final prediction is temporally coherent because the combination respects the natural structure of multi-scale data.
3. Adaptive Scale Importance: The learnable weights provide automatic scale selection. During training, the model discovers which temporal scales are most predictive for the specific forecasting task. This adaptation eliminates the need for manual scale selection and ensures the model uses the most relevant scales for each time series.
4. Hierarchical Regularization: By processing the same information at multiple resolutions and requiring consistency across scales, the model implicitly regularizes its predictions. Predictions should make sense at both fine and coarse resolutions, which helps prevent overfitting to noise at any single scale. This is a form of multi-scale regularization that's naturally built into the architecture.
How these properties work together: The decomposition enables specialization (Property 1), the upsampling enables smooth combination (Property 2), the learnable weights enable adaptation (Property 3), and the multi-scale structure provides regularization (Property 4). Together, they create a framework that's both powerful and principled, exactly what's needed for complex, multi-scale time series forecasting.