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} {output =} xzero (@var{X1}, @var{X2})
23
## @deftypefnx{Function File} {output =} xzero (@var{X1}, @var{X2}, @var{paramName}, @var{paramValue}, @dots{})
25
## Takes two data sets and fits a zeroth order model of data set 1 (@var{X1})
26
## to predict data set 2 (@var{X2}) - cross prediction. It then computes the
27
## error of the model. This is done by searching for all neighbors in @var{X1}
28
## of the points of set @var{X2} which should be forecasted and taking as their
29
## images the average of the images of the neighbors. The obtained forecast
30
## error is normalized to the variance of data set @var{X2}.
34
## Both @var{X1} and @var{X2} must be present. They must be realvectors
35
## of the same length.
37
## @strong{Parameters}
41
## Embedding dimension [default = 3].
43
## Delay for embedding [default = 1].
45
## The number of points for which the error should be calculated
48
## Minimum number of neighbors for the fit [default = 30].
50
## The neighborhood size to start with [default = 1e-3].
52
## Factor by which to increase the neighborhood size if not
53
## enough neighbors were found [default = 1.2].
55
## Steps to be forecast (@code{x2(n+steps) = av(x1(i+steps)}) [default = 1].
60
## Contains value of parameter '@var{s}' lines. Each line represents the
61
## forecast error divided by the standard deviation of the second data set
62
## (@var{X2}). This second data set is the one being forecasted.
64
## @strong{Algorithms}
66
## The algorithms for this functions have been taken from the TISEAN package.
69
## Author: Piotr Held <pjheld@gmail.com>.
70
## This function is based on xzero of TISEAN 3.0.1
71
## https://github.com/heggus/Tisean"
73
function output = xzero (X1, X2, varargin)
75
# Initial input validation
80
if ((isvector (X1) == false) || (isreal(X1) == false))
81
error ('Octave:invalid-input-arg', "X1 must be a realvector");
84
if ((isvector (X2) == false) || (isreal(X2) == false))
85
error ('Octave:invalid-input-arg', "X2 must be a realvector");
88
if (length (X1) != length (X2))
89
error ('Octave:invalid-input-arg', "X1 and X2 must be of same length");
95
clength = length (X1);
103
p.FunctionName = "xzero";
105
isPositiveIntScalar = @(x) isreal(x) && isscalar (x) && ...
106
(x > 0) && (x-round(x) == 0);
107
isPositiveScalar = @(x) isreal(x) && isscalar (x) && (x > 0);
109
p.addParamValue ("m", embdim, isPositiveIntScalar);
110
p.addParamValue ("d", delay, isPositiveIntScalar);
111
p.addParamValue ("n", clength, isPositiveIntScalar);
112
p.addParamValue ("k", minn, isPositiveIntScalar);
113
p.addParamValue ("r", eps0, isPositiveScalar);
114
p.addParamValue ("f", epsf, isPositiveScalar);
115
p.addParamValue ("s", step, isPositiveIntScalar);
117
p.parse (varargin{:});
120
embdim = p.Results.m;
122
clength = p.Results.n;
125
epsset = !ismember ("r", p.UsingDefaults);
129
output = __xzero__ (X1, X2, embdim, delay, clength, minn, eps0, epsset, ...
134
%!fail ("xzero('a')");
137
%! hen = henon(2000)(:,1);
138
%! hen1 = hen(1:1000);
139
%! hen2 = hen(1001:end);
140
%! res_tisean = [1 0.6438699;2 0.9101371;3 0.9752469;4 0.9600329;5 0.9788585;6 0.9937851;7 1.002654;8 0.9973579;9 1.00776;10 1.008823;11 1.016724;12 1.017996;13 1.011284;14 1.005963;15 1.008479;16 1.007647;17 1.009703;18 1.018097;19 1.008374;20 1.006889];
141
%! out = xzero (hen1,hen2,'m',4,'d',6,'s',20);
142
%! assert(out, res_tisean(:,2),-1e-6);