1
## Copyright (C) 1996-2015 Piotr Held
3
## This file is part of Octave.
5
## Octave is free software; you can redistribute it and/or
6
## modify it under the terms of the GNU General Public
7
## License as published by the Free Software Foundation;
8
## either version 3 of the License, or (at your option) any
11
## Octave is distributed in the hope that it will be useful,
12
## but WITHOUT ANY WARRANTY; without even the implied
13
## warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14
## PURPOSE. See the GNU General Public License for more
17
## You should have received a copy of the GNU General Public
18
## License along with Octave; see the file COPYING. If not,
19
## see <http://www.gnu.org/licenses/>.
22
## @deftypefn{Function File} {@var{output} =} lfo_run (@var{S})
23
## @deftypefnx{Function File} {@var{output} =} lfo_run (@var{S}, @var{paramName}, @var{paramValue}, @dots{})
25
## This function depending on whether switch 'zeroth' is set produces either
26
## a local linear ansatz or a zeroth order ansatz for a possibly multivariate
27
## time series and iterates an artificial trajectory. The initial values for
28
## the trajectory are the last points of the original time series.
29
## Thus it actually forecasts the time series.
35
## This function always assumes that each time series is along the longer
36
## dimension of matrix @var{S}. It also assumes that every dimension
37
## (counting along the shorter dimension) of @var{S} is considered a
38
## component of the time series.
41
## @strong{Parameters}
45
## The embedding dimension used. It is synonymous to the second part
46
## of flag '-m' from TISEAN. The first part of the TISEAN flag is omitted
47
## as all of the available components of @var{S} are analyzed
50
## Delay used for the embedding [default = 1].
52
## Number of iterations into the future, length of prediction [default = 1000].
54
## Minimal number of neighbors for the fit [default = 30].
56
## Neighborhood size to start with [default = 1e-3].
58
## Factor to increase neighborhood size if not enough neighbors were
59
## found [default = 1.2].
66
## Perform a zeroth order fit instead a local linear one. This is synonymous
67
## with flag '-0' from TISEAN.
72
## Components of the forecasted time series.
74
## @seealso{lfo_test, lfo_ar, lzo_run}
76
## @strong{Algorithms}
78
## The algorithms for this functions have been taken from the TISEAN package.
81
## Author: Piotr Held <pjheld@gmail.com>.
82
## This function is based on lfo-run of TISEAN 3.0.1
83
## https://github.com/heggus/Tisean"
85
function output = lfo_run (S, varargin)
91
if ((ismatrix (S) == false) || (isreal(S) == false) || ...
93
error ('Octave:invalid-input-arg', "S must be a realmatrix");
106
p.FunctionName = "lfo_run";
108
isPositiveIntScalar = @(x) isreal(x) && isscalar (x) && ...
109
(x > 0) && (x-round(x) == 0);
110
isNonNegativeIntScalar = @(x) isPositiveIntScalar (x) || (x == 0);
111
isPositiveScalar = @(x) isreal(x) && isscalar (x) && (x > 0);
112
isNonNegativeScalar = @(x) isPositiveScalar (x) || (x == 0);
114
p.addParamValue ("m", embed, isPositiveIntScalar);
115
p.addParamValue ("d", delay, isPositiveIntScalar);
116
p.addParamValue ("l", flength, isPositiveIntScalar);
117
p.addParamValue ("k", minn, isPositiveIntScalar);
118
p.addParamValue ("r", eps0, isPositiveScalar);
119
p.addParamValue ("f", epsf, isPositiveScalar);
120
p.addSwitch ("zeroth");
122
p.parse (varargin{:});
127
flength = p.Results.l;
130
epsset = !ismember ('r', p.UsingDefaults);
132
do_zeroth = p.Results.zeroth;
134
# Correct S to always have more rows than columns
136
if (rows (S) < columns (S))
141
output = __lfo_run__ (S, embed, delay, flength, minn,
142
eps0, epsset, epsf, do_zeroth);
150
%! lfo_run_hen = [0.4178371 0.5916857;0.6124674 0.4178371;0.3080429 0.6124674;0.9938561 0.3080429;-0.3374249 0.9938561;0.7975559 -0.3374249;-0.1623264 0.7975559;0.4382906 -0.1623264;0.4370613 0.4382906;0.9818325 0.4370613;-0.3019938 0.9818325;0.8267984 -0.3019938;-0.2345942 0.8267984;0.5331624 -0.2345942;0.4509924 0.5331624];
151
%! res = lfo_run (henon (1000),'m',4,'d',6,'l',15);
152
%! assert (res, lfo_run_hen, 1e-5);
154
%!error <singular> lfo_run(henon(1000));
155
%!error <forecast failed> lfo_run(1:500,'m',1);
157
%% Check for neverending execution
158
%!error <too large> lfo_run(1:10, 'm',1);