fit parameters of an exponential smoothing model to a time series - Maple Help

Home : Support : Online Help : Statistics : Time Series Analysis Package : TimeSeriesAnalysis/Optimize

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{esm}}{:=}{\mathrm{< an ETS\left(*,*,*\right) model >}}$ (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.5em}{0.0ex}}i\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{to}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathrm{numelems}\left(\mathrm{models}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{do}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathrm{Optimize}\left({\mathrm{models}}_{i},\mathrm{ts},{\mathrm{inits}}_{i}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{end 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)$
 ${\mathrm{colors}}{:=}\left[{⟨}\colorbox[rgb]{0,0.0549019607843137,0.470588235294118}{{RGB : 0 0.0549 0.471}}{⟩}{,}{⟨}\colorbox[rgb]{0.0392156862745098,0.0509803921568627,0.466666666666667}{{RGB : 0.0392 0.0503 0.469}}{⟩}{,}{⟨}\colorbox[rgb]{0.0784313725490196,0.0470588235294118,0.466666666666667}{{RGB : 0.0784 0.0458 0.467}}{⟩}{,}{⟨}\colorbox[rgb]{0.117647058823529,0.0431372549019608,0.466666666666667}{{RGB : 0.118 0.0412 0.465}}{⟩}{,}{⟨}\colorbox[rgb]{0.156862745098039,0.0352941176470588,0.462745098039216}{{RGB : 0.157 0.0366 0.463}}{⟩}{,}{⟨}\colorbox[rgb]{0.196078431372549,0.0313725490196078,0.458823529411765}{{RGB : 0.196 0.032 0.461}}{⟩}{,}{⟨}\colorbox[rgb]{0.235294117647059,0.0274509803921569,0.458823529411765}{{RGB : 0.235 0.0275 0.459}}{⟩}{,}{⟨}\colorbox[rgb]{0.274509803921569,0.0235294117647059,0.458823529411765}{{RGB : 0.275 0.0229 0.457}}{⟩}{,}{⟨}\colorbox[rgb]{0.313725490196078,0.0196078431372549,0.454901960784314}{{RGB : 0.314 0.0183 0.455}}{⟩}{,}{⟨}\colorbox[rgb]{0.352941176470588,0.0156862745098039,0.450980392156863}{{RGB : 0.353 0.0137 0.453}}{⟩}{,}{⟨}\colorbox[rgb]{0.392156862745098,0.00784313725490196,0.450980392156863}{{RGB : 0.392 0.00915 0.451}}{⟩}{,}{⟨}\colorbox[rgb]{0.431372549019608,0.00392156862745098,0.450980392156863}{{RGB : 0.431 0.00458 0.449}}{⟩}{,}{⟨}\colorbox[rgb]{0.470588235294118,0,0.447058823529412}{{RGB : 0.471 0 0.447}}{⟩}\right]$ (7)
 > $\mathrm{TimeSeriesPlot}\left(\mathrm{seq}\left(\left[\mathrm{OneStepForecasts}\left({\mathrm{models}}_{i},\mathrm{ts}\right),\mathrm{color}=\mathrm{ToPlotColor}\left({\mathrm{colors}}_{i}\right),\mathrm{legend}={\mathrm{models}}_{i}\right],i=1..\mathrm{numelems}\left(\mathrm{models}\right)\right),\left[\mathrm{ts},\mathrm{color}="Niagara Green",\mathrm{thickness}=3\right]\right)$

 >