#!/usr/bin/env python3
"``naginterface.library.tsa.multi_inputmod`` Python Example."
# NAG Copyright 2017-2019.
# pylint: disable=invalid-name
from naginterfaces.library import tsa
[docs]def main():
"""
Example for :func:`naginterfaces.library.tsa.multi_inputmod_estim` and
:func:`naginterfaces.library.tsa.multi_inputmod_forecast_state`.
Multivariate time series: estimation of multi-input model and forecasting.
>>> main()
naginterfaces.library.tsa.multi_inputmod Python Example Results.
Multivariate time series: estimate and forecast.
Begin estimation.
Begin forecasting.
The forecast values and their standard errors:
No. Value Std error
1 97.306 4.788
2 101.785 6.328
3 103.812 7.145
4 102.073 7.360
Forecast components z(t):
Series No.: 1:
[175.413, 177.712, 179.373, 178.372]
Output noise n(t):
[-78.10695358 -75.92741605 -75.56034026 -76.29929963]
"""
print('naginterfaces.library.tsa.multi_inputmod Python Example Results.')
print('Multivariate time series: estimate and forecast.')
print('Begin estimation.')
# Orders vector of the ARIMA model for the output noise component:
mr = [1, 0, 0, 0, 0, 1, 4]
# There is one input series. Here are the transfer function model orders:
mt = [
[1, 0],
[0, 0],
[1, 0],
[3, 0],
]
# Multi-input model parameters:
para = [0., 0., 2., 0.5, 0.]
# Original undifferenced series:
xxy = [
[8.075, 105.],
[7.819, 119.],
[7.366, 119.],
[8.113, 109.],
[7.380, 117.],
[7.134, 135.],
[7.222, 126.],
[7.768, 112.],
[7.386, 116.],
[6.965, 122.],
[6.478, 115.],
[8.105, 115.],
[8.060, 122.],
[7.684, 138.],
[7.580, 135.],
[7.093, 125.],
[6.129, 115.],
[6.026, 108.],
[6.679, 100.],
[7.414, 96.],
[7.112, 107.],
[7.762, 115.],
[7.645, 123.],
[8.639, 122.],
[7.667, 128.],
[8.080, 136.],
[6.678, 140.],
[6.739, 122.],
[5.569, 102.],
[5.049, 103.],
[5.642, 89.],
[6.808, 77.],
[6.636, 89.],
[8.241, 94.],
[7.968, 104.],
[8.044, 108.],
[7.791, 119.],
[7.024, 126.],
[6.102, 119.],
[6.053, 103.],
]
# Marginal likelihood:
kef = 3
# Maximum required iterations:
nit = 20
mim_estim = tsa.multi_inputmod_estim(
mr, mt, para, xxy,
kef=kef, nit=nit,
)
print('Begin forecasting.')
# Input series for the forecast:
xxyn = [
[6.923, 0.],
[6.939, 0.],
[6.705, 0.],
[6.914, 0.],
]
# Orders for the input series:
mrx = [
[2, 0],
[0, 0],
[2, 0],
[0, 0],
[1, 0],
[1, 0],
[4, 0],
]
# Parameters for the input series:
parx = [
[1.6743, 0.],
[-0.9505, 0.],
[1.4605, 0.],
[-0.4862, 0.],
[0.8993, 0.],
]
# Estimated residual variances:
rmsxy = [0.1720, 22.9256]
mim_f = tsa.multi_inputmod_forecast_state(
mim_estim.sttf, mr, mt, mim_estim.para, xxyn, mrx, parx, rmsxy, kzef=1,
)
print('The forecast values and their standard errors:')
print('No. Value Std error')
for i, v in enumerate(mim_f.fva):
print('{:3d} {:7.3f} {:7.3f}'.format(i+1, v, mim_f.fsd[i]))
print('Forecast components z(t):')
for i in range(mim_f.xxyn.shape[1] - 1):
print('Series No.: {:d}:'.format(i + 1))
print(
'[' +
', '.join(
['{:7.3f}']*mim_f.xxyn.shape[0]
).format(*mim_f.xxyn[:, i]) +
']'
)
print('Output noise n(t):')
print(mim_f.xxyn[:, -1])
if __name__ == '__main__':
import doctest
import sys
sys.exit(
doctest.testmod(
None, verbose=True, report=False,
optionflags=doctest.REPORT_NDIFF,
).failed
)