blob: d77f815639f929c9eb8967c428733915e779c988 [file] [log] [blame]
<!-- HTML header for doxygen 1.8.4-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="keywords" content="madlib,postgres,greenplum,machine learning,data mining,deep learning,ensemble methods,data science,market basket analysis,affinity analysis,pca,lda,regression,elastic net,huber white,proportional hazards,k-means,latent dirichlet allocation,bayes,support vector machines,svm"/>
<title>MADlib: ARIMA</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
$(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
$(document).ready(function() { init_search(); });
</script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
jax: ["input/TeX","output/HTML-CSS"],
});
</script><script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js"></script>
<!-- hack in the navigation tree -->
<script type="text/javascript" src="eigen_navtree_hacks.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="madlib_extra.css" rel="stylesheet" type="text/css"/>
<!-- google analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-45382226-1', 'madlib.apache.org');
ga('send', 'pageview');
</script>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectlogo"><a href="http://madlib.apache.org"><img alt="Logo" src="madlib.png" height="50" style="padding-left:0.5em;" border="0"/ ></a></td>
<td style="padding-left: 0.5em;">
<div id="projectname">
<span id="projectnumber">1.18.0</span>
</div>
<div id="projectbrief">User Documentation for Apache MADlib</div>
</td>
<td> <div id="MSearchBox" class="MSearchBoxInactive">
<span class="left">
<img id="MSearchSelect" src="search/mag_sel.png"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
alt=""/>
<input type="text" id="MSearchField" value="Search" accesskey="S"
onfocus="searchBox.OnSearchFieldFocus(true)"
onblur="searchBox.OnSearchFieldFocus(false)"
onkeyup="searchBox.OnSearchFieldChange(event)"/>
</span><span class="right">
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('group__grp__arima.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div class="header">
<div class="headertitle">
<div class="title">ARIMA<div class="ingroups"><a class="el" href="group__grp__tsa.html">Time Series Analysis</a></div></div> </div>
</div><!--header-->
<div class="contents">
<div class="toc"><b>Contents</b> <ul>
<li class="level1">
<a href="#train">Training Function</a> </li>
<li class="level1">
<a href="#forecast">Forecasting Function</a> </li>
<li class="level1">
<a href="#examples">Examples</a> </li>
<li class="level1">
<a href="#background">Technical Background</a> </li>
<li class="level1">
<a href="#literature">Literature</a> </li>
<li class="level1">
<a href="#related">Related Topics</a> </li>
</ul>
</div><p>Given a time series of data X, the Autoregressive Integrated Moving Average (ARIMA) model is a tool for understanding and, perhaps, predicting future values in the series. The model consists of three parts, an autoregressive (AR) part, a moving average (MA) part, and an integrated (I) part where an initial differencing step can be applied to remove any non-stationarity in the signal. The model is generally referred to as an ARIMA(p, d, q) model where parameters p, d, and q are non-negative integers that refer to the order of the autoregressive, integrated, and moving average parts of the model respectively.</p>
<p><a class="anchor" id="train"></a></p><dl class="section user"><dt>Training Function</dt><dd></dd></dl>
<p>The ARIMA training function has the following syntax. </p><pre class="syntax">
arima_train( input_table,
output_table,
timestamp_column,
timeseries_column,
grouping_columns,
include_mean,
non_seasonal_orders,
optimizer_params
)
</pre><p><b>Arguments</b> </p><dl class="arglist">
<dt>input_table </dt>
<dd><p class="startdd">TEXT. The name of the table containing time series data.</p>
<p class="enddd"></p>
</dd>
<dt>output_table </dt>
<dd><p class="startdd">TEXT. The name of the table to store the ARIMA model. Three tables are created, with names based on the value of the <em>output_table</em> argument in the training function:</p>
<ol type="1">
<li><em>output_table</em>: Table containing the ARIMA model. Contains the following columns: <table class="output">
<tr>
<th>mean </th><td>Model mean (only if 'include_mean' is TRUE) </td></tr>
<tr>
<th>mean_std_error </th><td>Standard errors for mean </td></tr>
<tr>
<th>ar_params </th><td>Auto-regressions parameters of the ARIMA model </td></tr>
<tr>
<th>ar_std_errors </th><td>Standard errors for AR parameters </td></tr>
<tr>
<th>ma_params </th><td>Moving average parameters of the ARIMA model </td></tr>
<tr>
<th>ma_std_errors </th><td>Standard errors for MA parameters </td></tr>
</table>
</li>
<li><em>output_table</em>_summary: Table containing descriptive statistics of the ARIMA model. Contains the following columns: <table class="output">
<tr>
<th>input_table </th><td>Table name with the source data </td></tr>
<tr>
<th>timestamp_col </th><td>Column name in the source table that contains the timestamp index to data </td></tr>
<tr>
<th>timeseries_col </th><td>Column name in the source table that contains the data values </td></tr>
<tr>
<th>non_seasonal_orders </th><td>Orders of the non-seasonal ARIMA model </td></tr>
<tr>
<th>include_mean </th><td>TRUE if intercept was included in ARIMA model </td></tr>
<tr>
<th>residual_variance </th><td>Variance of the residuals </td></tr>
<tr>
<th>log_likelihood </th><td>Log likelihood value (when using MLE) </td></tr>
<tr>
<th>iter_num </th><td>The number of iterations executed </td></tr>
<tr>
<th>exec_time </th><td>Total time taken to train the model </td></tr>
</table>
</li>
<li><em>output_table</em>_residual: Table containing the residuals for each data point in 'input_table'. Contains the following columns: <table class="output">
<tr>
<th>timestamp_col </th><td>Same as the 'timestamp_col' parameter (all indices from source table included except the first <em>d</em> elements, where <em>d</em> is the differencing order value from 'non_seasonal_orders') </td></tr>
<tr>
<th>residual </th><td>Residual value for each data point </td></tr>
</table>
</li>
</ol>
<p></p>
<p class="enddd"></p>
</dd>
<dt>timestamp_column </dt>
<dd><p class="startdd">TEXT. The name of the column containing the timestamp (index) data. This could be a serial index (INTEGER) or date/time value (TIMESTAMP).</p>
<p class="enddd"></p>
</dd>
<dt>timeseries_column </dt>
<dd><p class="startdd">TEXT. The name of the column containing the time series data. This data is currently restricted to DOUBLE PRECISION.</p>
<p class="enddd"></p>
</dd>
<dt>grouping_columns (not currently implemented) </dt>
<dd><p class="startdd">TEXT, default: NULL.</p>
<p>A comma-separated list of column names used to group the input dataset into discrete groups, training one ARIMA model per group. It is similar to the SQL <code>GROUP BY</code> clause. When this value is null, no grouping is used and a single result model is generated.</p>
<dl class="section note"><dt>Note</dt><dd>Grouping is not currently implemented for ARIMA, but will be added in the future. Any non-NULL value for this parameter is ignored.</dd></dl>
</dd>
<dt>include_mean (optional) </dt>
<dd><p class="startdd">BOOLEAN, default: FALSE. Mean value of the data series is added in the ARIMA model if this variable is True. </p>
<p class="enddd"></p>
</dd>
<dt>non_seasonal_orders (optional) </dt>
<dd><p class="startdd">INTEGER[], default: 'ARRAY[1,1,1]'. Orders of the ARIMA model. The orders are [p, d, q], where parameters p, d, and q are non-negative integers that refer to the order of the autoregressive, integrated, and moving average parts of the model respectively. </p>
<p class="enddd"></p>
</dd>
<dt>optimizer_params (optional) </dt>
<dd>TEXT. Comma-separated list of optimizer-specific parameters of the form ‘name=value'. The order of the parameters does not matter. The following parameters are recognized:<ul>
<li><b>max_iter:</b> Maximum number of iterations to run learning algorithm (Default = 100)</li>
<li><b>tau:</b> Computes the initial step size for gradient algorithm (Default = 0.001)</li>
<li><b>e1:</b> Algorithm-specific threshold for convergence (Default = 1e-15)</li>
<li><b>e2:</b> Algorithm-specific threshold for convergence (Default = 1e-15)</li>
<li><b>e3:</b> Algorithm-specific threshold for convergence (Default = 1e-15)</li>
<li><b>hessian_delta:</b> Delta parameter to compute a numerical approximation of the Hessian matrix (Default = 1e-6) </li>
</ul>
</dd>
</dl>
<p><a class="anchor" id="forecast"></a></p><dl class="section user"><dt>Forecasting Function</dt><dd></dd></dl>
<p>The ARIMA forecast function has the following syntax. </p><pre class="syntax">
arima_forecast( model_table,
output_table,
steps_ahead
)
</pre><p> <b>Arguments</b> </p><dl class="arglist">
<dt>model_table </dt>
<dd><p class="startdd">TEXT. The name of the table containing the ARIMA model trained on the time series dataset.</p>
<p class="enddd"></p>
</dd>
<dt>output_table </dt>
<dd><p class="startdd">TEXT. The name of the table to store the forecasted values. The output table produced by the forecast function contains the following columns. </p><table class="output">
<tr>
<th>group_by_cols </th><td>Grouping column values (if grouping parameter is provided) </td></tr>
<tr>
<th>step_ahead </th><td>Time step for the forecast </td></tr>
<tr>
<th>forecast_value </th><td>Forecast of the current time step </td></tr>
</table>
<p class="enddd"></p>
</dd>
<dt>steps_ahead </dt>
<dd>INTEGER. The number of steps to forecast at the end of the time series. </dd>
</dl>
<p><a class="anchor" id="examples"></a></p><dl class="section user"><dt>Examples</dt><dd><ol type="1">
<li>View online help for the ARIMA training function. <pre class="example">
SELECT madlib.arima_train();
</pre></li>
<li>Create an input data set. <pre class="example">
DROP TABLE IF EXISTS arima_beer;
CREATE TABLE arima_beer (time_id integer NOT NULL, value double precision NOT NULL );
COPY arima_beer (time_id, value) FROM stdin WITH DELIMITER '|';
1 | 93.2
2 | 96.0
3 | 95.2
4 | 77.0
5 | 70.9
6 | 64.7
7 | 70.0
8 | 77.2
9 | 79.5
10 | 100.5
11 | 100.7
12 | 107.0
13 | 95.9
14 | 82.7
15 | 83.2
16 | 80.0
17 | 80.4
18 | 67.5
19 | 75.7
20 | 71.0
21 | 89.2
22 | 101.0
23 | 105.2
24 | 114.0
25 | 96.2
26 | 84.4
27 | 91.2
28 | 81.9
29 | 80.5
30 | 70.4
31 | 74.7
32 | 75.9
33 | 86.2
34 | 98.7
35 | 100.9
36 | 113.7
37 | 89.7
38 | 84.4
39 | 87.2
40 | 85.5
\.
</pre></li>
<li>Train an ARIMA model. <pre class="example">
-- Train ARIMA model with 'grouping_columns'=NULL, 'include_mean'=TRUE,
-- and 'non_seasonal_orders'=[1,1,1]
SELECT madlib.arima_train( 'arima_beer',
'arima_beer_output',
'time_id',
'value',
NULL,
FALSE,
ARRAY[1, 1, 1]
);
</pre></li>
<li>Examine the ARIMA model. <pre class="example">
\x ON
SELECT * FROM arima_beer_output;
</pre> Result: <pre class="result">
-[ RECORD 1 ]-+------------------
ar_params | {0.221954769696}
ar_std_errors | {0.575367782602}
ma_params | {-0.140623564576}
ma_std_errors | {0.533445214346}
</pre></li>
<li>View the summary statistics table. <pre class="example">
SELECT * FROM arima_beer_output_summary;
</pre> Result: <pre class="result">
-[ RECORD 1 ]-------+---------------
input_table | arima_beer
timestamp_col | time_id
timeseries_col | value
non_seasonal_orders | {1,1,1}
include_mean | f
residual_variance | 100.989970539
log_likelihood | -145.331516396
iter_num | 28
exec_time (s) | 2.75
</pre></li>
<li>View the residuals. <pre class="example">
\x OFF
SELECT * FROM arima_beer_output_residual;
</pre> Result: <pre class="result">
time_id | residual
---------+--------------------
2 | 0
4 | -18.222328834394
6 | -5.49616627282665
...
35 | 1.06298837051437
37 | -25.0886854003757
39 | 3.48401666299571
(40 rows)
</pre></li>
<li>Use the ARIMA forecast function to forecast 10 future values. <pre class="example">
SELECT madlib.arima_forecast( 'arima_beer_output',
'arima_beer_forecast_output',
10
);
SELECT * FROM arima_beer_forecast_output;
</pre> Result: <pre class="result">
steps_ahead | forecast_value
-------------+----------------
1 | 85.3802343659
3 | 85.3477516875
5 | 85.3461514635
7 | 85.3460726302
9 | 85.3460687465
2 | 85.3536518121
4 | 85.3464421267
6 | 85.3460869494
8 | 85.3460694519
10 | 85.34606859
(10 rows)
</pre></li>
</ol>
</dd></dl>
<p><a class="anchor" id="background"></a></p><dl class="section user"><dt>Technical Background</dt><dd>An ARIMA model is an <em>a</em>uto-<em>r</em>egressive <em>i</em>ntegrated <em>m</em>oving <em>a</em>verage model. An ARIMA model is typically expressed in the form <p class="formulaDsp">
\[ (1 - \phi(B)) Y_t = (1 + \theta(B)) Z_t, \]
</p>
</dd></dl>
<p>where \(B\) is the backshift operator. The time \( t \) is from \( 1 \) to \( N \).</p>
<p>ARIMA models involve the following variables:</p><ul>
<li>The values of the time series: \( X_t \).</li>
<li>Parameters of the model: \( p \), \( q \), and \( d \); \( d \) is the differencing order, \( p \) is the order of the AR operator, and \( q \) is the order of the MA operator.</li>
<li>The AR operator: \( \phi(B) \).</li>
<li>The MA operator: \( \theta(B) \).</li>
<li>The lag difference: \( Y_{t} \), where \( Y_{t} = (1-B)^{d}(X_{t} - \mu) \).</li>
<li>The mean value: \( \mu \), which is set to be zero for \( d&gt;0 \) and estimated from the data when d=0.</li>
<li>The error terms: \( Z_t \).</li>
</ul>
<p>The auto regression operator models the prediction for the next observation as some linear combination of the previous observations. More formally, an AR operator of order \( p \) is defined as</p>
<p class="formulaDsp">
\[ \phi(B) Y_t= \phi_1 Y_{t-1} + \dots + \phi_{p} Y_{t-p} \]
</p>
<p>The moving average operator is similar, and it models the prediction for the next observation as a linear combination of the errors in the previous prediction errors. More formally, the MA operator of order \( q \) is defined as</p>
<p class="formulaDsp">
\[ \theta(B) Z_t = \theta_{1} Z_{t-1} + \dots + \theta_{q} Z_{t-q}. \]
</p>
<p>We estimate the parameters using the Levenberg-Marquardt Algorithm. In mathematics and computing, the Levenberg-Marquardt algorithm (LMA), also known as the damped least-squares (DLS) method, provides a numerical solution to the problem of minimizing a function, generally nonlinear, over a space of parameters of the function.</p>
<p>Like other numeric minimization algorithms, LMA is an iterative procedure. To start a minimization, the user has to provide an initial guess for the parameter vector, $p$, as well as some tuning parameters \(\tau, \epsilon_1, \epsilon_2, \epsilon_3,\).</p>
<p><a class="anchor" id="literature"></a></p><dl class="section user"><dt>Literature</dt><dd></dd></dl>
<p>[1] Rob J Hyndman and George Athanasopoulos: Forecasting: principles and practice, <a href="http://otexts.com/fpp/">http://otexts.com/fpp/</a></p>
<p>[2] Robert H. Shumway, David S. Stoffer: Time Series Analysis and Its Applications With R Examples, Third edition Springer Texts in Statistics, 2010</p>
<p>[3] Henri Gavin: The Levenberg-Marquardt method for nonlinear least squares curve-fitting problems, 2011</p>
<p><a class="anchor" id="related"></a></p><dl class="section user"><dt>Related Topics</dt><dd></dd></dl>
<p>File <a class="el" href="arima_8sql__in.html" title="Arima function for forecasting of timeseries data. ">arima.sql_in</a> documenting the ARIMA functions </p>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="footer">Generated on Wed Mar 31 2021 20:45:50 for MADlib by
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.13 </li>
</ul>
</div>
</body>
</html>