You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Compared to the previous 24-hour forecast, it looks like the uncertainty of the model has decreased, generally. We can also see that the mid-section and even the mid-to-end section have slightly improved. However, it still seems that our finally trajectory is more north than north-east, but is less north than our one-period ahead forecast.
1132
+
Compared to the previous 24-hour forecast, it looks like the uncertainty of the model has decreased, generally. We can also see that the mid-section and even the mid-to-end section have slightly improved. However, it still seems that our finally trajectory is more north than north-east, but is less north than our last one-period ahead forecast.
In the previous section, we tried adding an interaction term between the maximum sustained surface wind speed and the minumum central pressure. However, our estimated parameters were not too far off from zero. In this section we are going to attempt to model the non-linear complexities of the path, particularyly in the mid-section, using cubic B-splines.
1143
+
1144
+
To do this we first need to define what variables we are going to model as a smooth function. In our case, we are going to model the longitude values as a smooth function of the latitude values and vice versa.
1145
+
1146
+
To keep things simple, we are going to define a constant number of knots that are equal in both variables (same #knots for both longitude and latitude) and we are going to place the knots using a quantile function over the variable space. You can see the knots plotted out below for each variable.
1143
1147
1144
1148
```{code-cell} ipython3
1145
1149
num_knots = 15
@@ -1154,7 +1158,7 @@ fig.add_traces(
1154
1158
go.Scatter(
1155
1159
x=fiona_df["longitude"],
1156
1160
y=fiona_df["latitude"],
1157
-
name="actuals",
1161
+
name="Actuals",
1158
1162
mode="lines+markers",
1159
1163
line=dict(color="black"),
1160
1164
hovertemplate=[
@@ -1211,6 +1215,8 @@ fig.update_layout(
1211
1215
fig.show(config={"displayModeBar": False})
1212
1216
```
1213
1217
1218
+
Next we need to create the basis functions over the defined variable space knot locations for each variable
Our new models' structure is going to be similar to our last model that had exogenous variables. However, in this case our data are going to be the basis functions we created earlier. These will be inserted into our design matrix ($Z$) and the beta parameters corresponding to each spline will be added to our state vector ($x_{t}$). Again, these parameters will be constant (non-time varying). We will also have to re-adjust our transition matrix ($T$) and selection matrix ($R$) similar to how we did previously. We will now have:
our design matrix will be: $$ Z' = \begin{bmatrix} Z & X_{basis\_functions} \end{bmatrix} $$ Where $Z$ is our previously defined design matrix and $X_{exogenous}$ are the basis functions we defined earlier.
1243
+
1244
+
Our transition matrix will be $$T' = \begin{bmatrix} T & F \\ 0 & I_{n\_spline\_params} \end{bmatrix} $$
1245
+
1246
+
Where $T$ is the transition matrix defined for the Newtonian kinematics (the top-left 6x6 block in our previous model)
1247
+
and $$ F = \begin{bmatrix} 1&0&1&0&1&0&1&0&1&0&1&0&1&0&1&0&1&0&1&0&1&0&1&0&1&0&1&0&1&0&1&0&1&0 \\ 0&1&0&1&0&1&0&1&0&1&0&1&0&1&0&1&0&1&0&1&0&1&0&1&0&1&0&1&0&1&0&1&0&1 \\ 0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0 \\ 0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0 \\ 0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0 \\ 0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0 \end{bmatrix} $$
1248
+
and the 0 in the matrix above is a matrix of 0s of shape (number of spline parameters by number of spline parameters)
1249
+
1250
+
Finally, we have $$R' = \begin{bmatrix} R \\ 0 \end{bmatrix} $$
1251
+
1252
+
Where R is the selectiom matrix over our endogenous states (identity matrix of shape (number of states))
1253
+
and again the 0 in the matrix is a matrix of 0s with shape (number of spline parameters by number of states)
1254
+
1230
1255
```{code-cell} ipython3
1231
1256
class SplineSSM(PyMCStateSpace):
1232
1257
def __init__(self, k_exog: int = None):
@@ -1522,6 +1547,8 @@ with pm.Model(coords=spline_ssm.coords) as spline_model:
Our one-period ahead forecasts, look better than the ones we generated from the Exogenous covariates model, but worse than the original model that purely follows Newtonian kinematics.
Our 24-hour (4-period) forecasts, look pretty good. So far, this follows the true trajectory during the mid-section the best.
1582
+
1550
1583
```{code-cell} ipython3
1551
1584
# our last i will equal 60 so we need to pad our exogenous data to len 64
1552
1585
exog_data_padded = np.concatenate(
@@ -1572,6 +1605,11 @@ fig = plot_hurricane_path(
1572
1605
fig.show(config={"displayModeBar": False})
1573
1606
```
1574
1607
1608
+
# Closing Remarks
1609
+
In this case study we looked at how we can track a hurricane in two-dimensional space using a state space representation of Newtonian kinematics. We proceeded to expand on the pure Newtonian model and added exogenous variables that may hold information pertintent to the Hurricane's track. We then expanded our model by modeling our variables as smooth functions using cubic B-splines. Throughout, the case study we saw that the pure Newtonian kinematics model's one-period ahead forecast performed the best. However, adding exogenous variables allowed our 24-hour (four-period) ahead forecasts to produce better forecasts compared to the pure Newtonian model. A possible explanation is that for a short period forecast the Newtonian kinematics contain all the information needed to produce the best next forecast. However, for longer periods the Newtonian kinematics are too deterministic whereaas the exogenous variables may act to regularize the output from the Newtonian kinematics. In turn producing better longer period forecasts.
0 commit comments