Understanding Recurrent Neural Networks and Long Short-Term Memory
EU-Philippines CoPhil Programme
Duration: 1.5 hours (90 minutes) Type: Theory Session Goal: Master LSTM networks for time series forecasting
You will learn:
Prerequisites:
Materials:
Earth observation data is inherently temporal - we observe the same locations repeatedly over time.
Static Analysis (Single Date):
Time Series Analysis (Multi-Date):
Spatial + Temporal Analysis
While CNNs excel at extracting spatial patterns from individual satellite images, LSTMs excel at extracting temporal patterns from sequences of observations.
Together, they form powerful tools for spatiotemporal analysis.
Vegetation Indices:
SAR Backscatter:
Biophysical Parameters:
Climate Impacts:
Agricultural Context
Provinces: Bukidnon and South Cotabato
Major Crops:
2015-2016 El Niño Impact:
1. Drought Forecasting
2. Crop Yield Prediction
3. Flood Risk Assessment
4. Land Cover Change Detection
5. Phenology Monitoring
Feedforward Networks (including CNNs) assume inputs are independent.
Problem with Sequential Data:
Example: Predicting next month’s vegetation health
Solution: Networks with memory of previous inputs
Key Idea: Add feedback loop to remember previous inputs
At each time step t:
x_t (e.g., current month’s NDVI)h_{t-1} (memory)h_ty_th_t to next time stepMathematical Formulation:
\[h_t = \text{tanh}(W_{hh} \cdot h_{t-1} + W_{xh} \cdot x_t + b_h)\]
\[y_t = W_{hy} \cdot h_t + b_y\]
Critical Flaw of Standard RNNs:
When training on long sequences (e.g., 24 months), gradients become extremely small during backpropagation.
Why This Happens:
Gradients multiply repeatedly:
\[\frac{\partial L}{\partial h_1} = \frac{\partial L}{\partial h_T} \cdot \frac{\partial h_T}{\partial h_{T-1}} \cdot \ldots \cdot \frac{\partial h_2}{\partial h_1}\]
If each derivative < 1, product shrinks exponentially
Impact:
EO Application Impact:
Predicting August drought based on:
But January-March dry season conditions are critical for August prediction!
Calculate Gradient Decay
Task: How many time steps for gradient of 0.9 to shrink below 0.01?
Formula: \(0.9^n < 0.01\)
Answer: \(n = \frac{\log(0.01)}{\log(0.9)} \approx 44\) steps
Meaning:
This is why LSTMs are essential!
Long Short-Term Memory networks solve the vanishing gradient problem
Key Innovation:
Replace simple hidden state with a memory cell controlled by learnable gates
LSTM Advantages:
Components:
1. Forget Gate
\[f_t = \sigma(W_f \cdot [h_{t-1}, x_t] + b_f)\]
Output: 0 (forget) to 1 (keep)
2. Input Gate
\[i_t = \sigma(W_i \cdot [h_{t-1}, x_t] + b_i)\]
\[\tilde{C}_t = \text{tanh}(W_C \cdot [h_{t-1}, x_t] + b_C)\]
i_t: How much to add (0 to 1)C_tilde_t: Candidate values3. Output Gate
\[o_t = \sigma(W_o \cdot [h_{t-1}, x_t] + b_o)\]
\[h_t = o_t \cdot \text{tanh}(C_t)\]
Step 1: Forget old information
\[C_t = f_t \cdot C_{t-1}\]
Step 2: Add new information
\[C_t = C_t + i_t \cdot \tilde{C}_t\]
Combined:
\[C_t = f_t \cdot C_{t-1} + i_t \cdot \tilde{C}_t\]
Key Insight: Cell state acts as gradient highway
Standard RNN:
LSTM:
Result:
Drought Monitoring Example
Question: What might the gates do for Mindanao drought?
Forget Gate:
Input Gate:
Reflection: How would gates behave differently for:
Components:
Sequence Creation (Sliding Window):
Given monthly NDVI 2015-2021, create training sequences:
Lookback: 12 months Forecast: 1 month ahead
Example:
Result: Hundreds/thousands of training sequences from multi-year data
LSTMs use multiple features per time step:
Input Shape: (samples, time_steps, features)
Example: (5000, 12, 4) = 5000 sequences, 12 months, 4 features
1. Data Splitting:
Important: Temporal splits (not random) to avoid leakage
2. Normalization:
3. Model Compilation:
4. Training:
5. Evaluation:
| Parameter | Description | Typical Range |
|---|---|---|
| LSTM units | Hidden state size | 32-256 per layer |
| Layers | LSTM stack depth | 1-3 |
| Lookback | Time steps to use | 6-24 months |
| Dropout | Regularization | 0.1-0.3 |
| Learning rate | Optimization step | 0.0001-0.01 |
| Batch size | Samples per update | 32-128 |
Objective: Predict drought 1-3 months ahead for Bukidnon & South Cotabato
Data Sources:
Model Setup:
Training:
Performance:
Operational:
Session 2 Hands-On Lab (Today)
Session 2 (2.5 hours) implements full workflow:
1. Rice Yield Forecasting (Luzon)
2. Typhoon Impact Prediction (Visayas)
3. Coral Bleaching (Palawan)
4. Urban Growth (Metro Manila)
Step 1: Data Preparation
Step 2: Understand Gradients
Step 3: Build and Train
Step 4: Evaluate
📓 Open Student Notebook to begin!
Important
Time Series in EO:
Important
RNNs and Limitations:
Important
LSTM Architecture:
Important
LSTM for EO:
Philippine Context:
Session 2: Hands-On Lab (Today)
Session 2 implements full LSTM drought monitoring for Mindanao with real Sentinel-2 data!
To Prepare:
Software: Python 3.8+, TensorFlow 2.x, GEE account
Think About:
Contact: skotsopoulos@neuralio.ai
Questions?
See you in Session 2 for the hands-on lab!
Day 4: Time Series Analysis, Emerging Trends, and Sustainable Learning - CoPhil 4-Day Advanced Training on AI/ML for Earth Observation, funded by the European Union under the Global Gateway initiative.

DAY 4 - Session 1 | LSTMs for EO Time Series