%
% Purpose:
% Show prediction error vs forecast horizon for two differenced time series
% The first is generated as the sum of two tent maps, the second
% is a sinusoid with added noise.
%
% The demonstration is similar to that given in "Nonlinear forecasting as
% a way of distinguishing chaos from measurement error in time
% series" by George Sugihara & Robert M. May.
% Nature 344, 734 - 741 (19 April 1990).
%
% Input
%
% Effects:
% Graph
%
% (c) 2011 Paul Moore - moorep@maths.ox.ac.uk
%
% This software is provided 'as is' with no warranty or other guarantee of
% fitness for the user's purpose. Please let the author know of any bugs
% or potential improvements.
npreds = 12;
x = maketent(10000);
xp = x(1:1001) + x(5000:6000);
dx = diff(xp);
z(:,1) = dx(1:500);
z(:,2) = dx(501:1000);
tentout = tis('xzero',['-m3 -d1 -k2 -V1 -s',num2str(npreds)],z);
r = 0:2*pi/5:2000*pi/5;
r = r';
y = sin(r) + rand(length(r),1) + 1;
dy = diff(y);
a(:,1) = dy(1:500);
a(:,2) = dy(501:1000);
sinout = tis('xzero',['-m3 -d1 -k2 -V1 -s',num2str(npreds)],a);
rn = 1:npreds;
plot(rn,tentout(:,2),'bs-');
hold on
plot(rn,sinout(:,2),'gs-');
xlabel('Forecast horizon');
ylabel('Forecast error, normalised to variance of test set');