 Optimize - Maple Help

TimeSeriesAnalysis

 Optimize
 fit parameters of an exponential smoothing model to a time series Calling Sequence Optimize(model, ts, init) Parameters

 model - ts - Time series consisting of a single data set init - (optional) table of initial parameter values Description

 • The Optimize command will fit unassigned parameter values of model to maximize the likelihood of obtaining the time series ts.
 • If a parameter was fixed when creating model, its value will not be subject to optimization. For example, if the calling sequence of ExponentialSmoothingModel includes the option alpha = 0.3, then calling Optimize on the resulting model keeps alpha fixed. (This is also true if Optimize is called automatically when ExponentialSmoothingModel gets a Time series as its first argument.)
 • Optimize is only guaranteed to find a local optimum; it calls Optimization[NLPSolve]. It uses the nonlinear simplex method (also known as Nelder-Mead).
 • The optimization process needs to be started with an initial point; this point is given by init. It uses the format returned by Initialize: it is a table with parameter names as indices and parameter values as values. If init is not given, Optimize calls Initialize and uses its output by default. Examples

 > $\mathrm{with}\left(\mathrm{TimeSeriesAnalysis}\right):$

Consider the following time series. It represents international tourist visitor nights in Australia.

 > $\mathrm{ts}≔\mathrm{TimeSeries}\left(⟨41.7,24.0,32.3,37.3,46.2,29.3,36.5,43.0,48.9,31.2,37.7,40.4,51.2,31.9,41.0,43.8,55.6,33.9,42.1,45.6,59.8,35.2,44.3,47.9⟩,\mathrm{startdate}="2005",\mathrm{frequency}=\mathrm{quarterly},\mathrm{header}="Visitor nights"\right)$
 ${\mathrm{ts}}{≔}\left[\begin{array}{c}{\mathrm{Time series}}\\ {\mathrm{Visitor nights}}\\ {\mathrm{24 rows of data:}}\\ {\mathrm{2005-Jan-01 - 2010-Oct-01}}\end{array}\right]$ (1)
 > $\mathrm{esm}≔\mathrm{ExponentialSmoothingModel}\left(\mathrm{seasonal}=\left\{A,M\right\},\mathrm{constraints}=\mathrm{admissible}\right)$
 ${\mathrm{TimeSeriesAnalysis}}{:-}{\mathrm{ExponentialSmoothingModel}}{}\left({\mathrm{errors}}{=}\left\{{"A"}{,}{"M"}\right\}{,}{\mathrm{trend}}{=}\left\{{"A"}{,}{"Ad"}{,}{"M"}{,}{"Md"}{,}{"N"}\right\}{,}{\mathrm{seasonal}}{=}\left\{{"A"}{,}{"M"}\right\}{,}{\mathrm{constraints}}{=}{"admissible"}\right)$ (2)

Transform to a collection of specialized models.

 > $\mathrm{models}≔\mathrm{Specialize}\left(\mathrm{esm},\mathrm{ts}\right)$
 ${\mathrm{models}}{≔}\left[{\mathrm{< an ETS\left(A,A,A\right) model >}}{,}{\mathrm{< an ETS\left(A,Ad,A\right) model >}}{,}{\mathrm{< an ETS\left(A,N,A\right) model >}}{,}{\mathrm{< an ETS\left(M,A,A\right) model >}}{,}{\mathrm{< an ETS\left(M,A,M\right) model >}}{,}{\mathrm{< an ETS\left(M,Ad,A\right) model >}}{,}{\mathrm{< an ETS\left(M,Ad,M\right) model >}}{,}{\mathrm{< an ETS\left(M,M,M\right) model >}}{,}{\mathrm{< an ETS\left(M,Md,M\right) model >}}{,}{\mathrm{< an ETS\left(M,N,A\right) model >}}{,}{\mathrm{< an ETS\left(M,N,M\right) model >}}\right]$ (3)

Find initial points for optimization for all of these.

 > $\mathrm{inits}≔\mathrm{map}\left(\mathrm{Initialize},\mathrm{models},\mathrm{ts}\right):$

Optimize all of them.

 > $\mathbf{for}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}i\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{to}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{numelems}\left(\mathrm{models}\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{do}\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\phantom{\rule[-0.0ex]{2.0em}{0.0ex}}\mathrm{Optimize}\left(\mathrm{models}\left[i\right],\mathrm{ts},\mathrm{inits}\left[i\right]\right)\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\mathbf{end}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{do}:$

Alternatively, we can let Optimize call Initialize for us.

 > $\mathrm{models2}≔\mathrm{Specialize}\left(\mathrm{esm},\mathrm{ts}\right)$
 ${\mathrm{models2}}{≔}\left[{\mathrm{< an ETS\left(A,A,A\right) model >}}{,}{\mathrm{< an ETS\left(A,Ad,A\right) model >}}{,}{\mathrm{< an ETS\left(A,N,A\right) model >}}{,}{\mathrm{< an ETS\left(M,A,A\right) model >}}{,}{\mathrm{< an ETS\left(M,A,M\right) model >}}{,}{\mathrm{< an ETS\left(M,Ad,A\right) model >}}{,}{\mathrm{< an ETS\left(M,Ad,M\right) model >}}{,}{\mathrm{< an ETS\left(M,M,M\right) model >}}{,}{\mathrm{< an ETS\left(M,Md,M\right) model >}}{,}{\mathrm{< an ETS\left(M,N,A\right) model >}}{,}{\mathrm{< an ETS\left(M,N,M\right) model >}}\right]$ (4)
 > $\mathrm{map}\left(\mathrm{Optimize},\mathrm{models2},\mathrm{ts}\right)$
 $\left[{-43.87641045}{,}{-43.30741702}{,}{-47.25550594}{,}{-43.49539348}{,}{-42.02319299}{,}{-42.42526190}{,}{-40.68983138}{,}{-42.92489529}{,}{-40.42353080}{,}{-46.41831579}{,}{-46.75393519}\right]$ (5)

Evaluate the Bayesian information criterion for each model.

 > $\mathrm{map}\left(\mathrm{model}↦\mathrm{print}\left(\mathrm{model},\mathrm{BIC}\left(\mathrm{model},\mathrm{ts}\right)\right),\mathrm{models}\right):$
 ${\mathrm{< an ETS\left(A,A,A\right) model >}}{,}{126.7819508}$
 ${\mathrm{< an ETS\left(A,Ad,A\right) model >}}{,}{126.9258852}$
 ${\mathrm{< an ETS\left(A,N,A\right) model >}}{,}{129.9242821}$
 ${\mathrm{< an ETS\left(M,A,A\right) model >}}{,}{141.6667862}$
 ${\mathrm{< an ETS\left(M,A,M\right) model >}}{,}{109.4702551}$
 ${\mathrm{< an ETS\left(M,Ad,A\right) model >}}{,}{135.7502647}$
 ${\mathrm{< an ETS\left(M,Ad,M\right) model >}}{,}{109.9821406}$
 ${\mathrm{< an ETS\left(M,M,M\right) model >}}{,}{111.2692148}$
 ${\mathrm{< an ETS\left(M,Md,M\right) model >}}{,}{109.4060877}$
 ${\mathrm{< an ETS\left(M,N,A\right) model >}}{,}{140.6230023}$
 ${\mathrm{< an ETS\left(M,N,M\right) model >}}{,}{112.5756460}$ (6)

Compare all models' fits.

 > $\mathrm{colors}≔\mathrm{ColorTools}:-\mathrm{Gradient}\left("Niagara Navy".."Niagara Purple",\mathrm{number}=\mathrm{numelems}\left(\mathrm{models}\right)\right)$
 $\left[{\mathbf{module}}\left({}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{...}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end module}}{,}{\mathbf{module}}\left({}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{...}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end module}}{,}{\mathbf{module}}\left({}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{...}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end module}}{,}{\mathbf{module}}\left({}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{...}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end module}}{,}{\mathbf{module}}\left({}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{...}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end module}}{,}{\mathbf{module}}\left({}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{...}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end module}}{,}{\mathbf{module}}\left({}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{...}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end module}}{,}{\mathbf{module}}\left({}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{...}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end module}}{,}{\mathbf{module}}\left({}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{...}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end module}}{,}{\mathbf{module}}\left({}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{...}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end module}}{,}{\mathbf{module}}\left({}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{...}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end module}}{,}{\mathbf{module}}\left({}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{...}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end module}}{,}{\mathbf{module}}\left({}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{...}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end module}}\right]$ (7)
 > $\mathrm{TimeSeriesPlot}\left(\mathrm{seq}\left(\left[\mathrm{OneStepForecasts}\left(\mathrm{models}\left[i\right],\mathrm{ts}\right),\mathrm{color}=\mathrm{ToPlotColor}\left(\mathrm{colors}\left[i\right]\right),\mathrm{legend}=\mathrm{models}\left[i\right]\right],i=1..\mathrm{numelems}\left(\mathrm{models}\right)\right),\left[\mathrm{ts},\mathrm{color}="Niagara Green",\mathrm{thickness}=3\right]\right)$ > References

 Hyndman, R.J. and Athanasopoulos, G. (2013) Forecasting: principles and practice. http://otexts.org/fpp/. Accessed on 2013-10-09.
 Hyndman, R.J., Koehler, A.B., Ord, J.K., and Snyder, R.D. (2008) Forecasting with Exponential Smoothing: The State Space Approach. Springer Series in Statistics. Springer-Verlag Berlin Heidelberg. Compatibility

 • The TimeSeriesAnalysis[Optimize] command was introduced in Maple 18.