Skip to content

Commit

Permalink
a pass of hmc docs and comments (#60)
Browse files Browse the repository at this point in the history
* separate hmc utils

* temporary save

* revise docs

* update docs for remaining utils

* change returns to return

* add missing dot
  • Loading branch information
fehiepsi committed May 30, 2019
1 parent 0262a16 commit 7684f0d
Show file tree
Hide file tree
Showing 4 changed files with 223 additions and 80 deletions.
22 changes: 12 additions & 10 deletions notebooks/time_series_forecasting.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -118,27 +118,29 @@
"source": [
"The model we are going to use is called **Seasonal, Global Trend**, which when tested on 3003 time series of the [M-3 competition](https://forecasters.org/resources/time-series-data/m3-competition/), has been known to outperform other models originally participating in the competition:\n",
"\n",
"$$\n",
"\\begin{equation*}\n",
"\\begin{gathered}\n",
"\\text{exp_val}_{t} = \\text{level}_{t-1} + \\text{coef_trend} \\times \\text{level}_{t-1}^{\\text{pow_trend}}\n",
"+ \\text{s}_t \\times \\text{level}_{t-1}^{\\text{pow_season}}, \\\\\n",
"\\sigma_{t} = \\sigma \\times \\text{exp_val}_{t}^{\\text{powx}} + \\text{offset}, \\\\\n",
"y_{t} \\sim \\text{StudentT}(\\nu, \\text{exp_val}_{t}, \\sigma_{t}), \\\\\n",
"y_{t} \\sim \\text{StudentT}(\\nu, \\text{exp_val}_{t}, \\sigma_{t}),\n",
"\\end{gathered}\n",
"\\end{equation*}\n",
"$$\n",
"\n",
"where `level` and `s` follows the following recursion rules:\n",
"$$\n",
"\n",
"\\begin{equation*}\n",
"\\begin{gathered}\n",
"\\text{level_p} =\n",
" \\begin{cases}\n",
" y_t - \\text{s}_t \\times \\text{level}_{t-1}^{\\text{pow_season}} & \\text{if } t \\le \\text{seasonality}, \\\\ \n",
" \\text{Average} \\left[y(t - \\text{seasonality} + 1), \\ldots, y(t)\\right] & \\text{otherwise},\n",
" \\end{cases} \\\\\n",
"\\text{level}_{t} = \\text{level_sm} \\times \\text{level_p} + (1 - \\text{level_sm}) \\times \\text{level}_{t-1}, \\\\\n",
"\\text{s}_{t + \\text{seasonality}} = \\text{s_sm} \\times \\frac{y_{t} - \\text{level}_{t}}{\\text{level}_{t-1}^{\\text{pow_trend}}}\n",
"+ (1 - \\text{s_sm}) \\times \\text{s}_{t}. \\\\\n",
"\\end{equation*}\n",
"$$"
"+ (1 - \\text{s_sm}) \\times \\text{s}_{t}.\n",
"\\end{gathered}\n",
"\\end{equation*}"
]
},
{
Expand Down Expand Up @@ -389,8 +391,8 @@
"metadata": {},
"source": [
"Given `samples` from `mcmc`, we want to do forecasting for the testing dataset `y_test`. First, we will make some utilities to do forecasting given a sample. Note that to retrieve the last `level` and last `s` value, we substitute a sample to the model:\n",
"```\n",
"... level, s = substitute(sgt, asample)(y, seasonality)`.\n",
"```python\n",
"... level, s = substitute(sgt, asample)(y, seasonality)\n",
"```"
]
},
Expand Down Expand Up @@ -531,7 +533,7 @@
"source": [
"## References\n",
"\n",
"[1] `Rlgt: Bayesian Exponential Smoothing Models with Trend Modifications`,</br>&nbsp;&nbsp;&nbsp;&nbsp;\n",
"[1] `Rlgt: Bayesian Exponential Smoothing Models with Trend Modifications`,<br>&nbsp;&nbsp;&nbsp;&nbsp;\n",
"Slawek Smyl, Christoph Bergmeir, Erwin Wibowo, To Wang Ng, Trustees of Columbia University"
]
}
Expand Down
2 changes: 1 addition & 1 deletion numpyro/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def autocorrelation(x, axis=0):
"""
Computes the autocorrelation of samples at dimension ``axis``.
:param numpy.array x: the input array.
:param numpy.ndarray x: the input array.
:param int axis: the dimension to calculate autocorrelation.
:return: autocorrelation of ``x``.
:rtype: numpy.ndarray
Expand Down

0 comments on commit 7684f0d

Please sign in to comment.