1 c===========================================================================
3 c This file is part of TISEAN
5 c Copyright (c) 1998-2007 Rainer Hegger, Holger Kantz, Thomas Schreiber
7 c TISEAN is free software; you can redistribute it and/or modify
8 c it under the terms of the GNU General Public License as published by
9 c the Free Software Foundation; either version 2 of the License, or
10 c (at your option) any later version.
12 c TISEAN is distributed in the hope that it will be useful,
13 c but WITHOUT ANY WARRANTY; without even the implied warranty of
14 c MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 c GNU General Public License for more details.
17 c You should have received a copy of the GNU General Public License
18 c along with TISEAN; if not, write to the Free Software
19 c Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 c===========================================================================
22 c simple nonlinear prediction, fast neighbour search
23 c see H. Kantz, T. Schreiber, Nonlinear Time Series Analysis, Cambridge
24 c University Press (1997,2004)
25 c author T. Schreiber (1998)
26 c===========================================================================
28 dimension x(nx), y(nx)
29 character*72 file, fout
30 data eps/0./, frac/0./, ifc/1/
33 call whatido("prediction with locally constant fits",iverb)
42 isout=igetout(fout,iverb)
43 if(eps.eq.0.and.frac.eq.0.) call usage()
45 do 10 ifi=1,nstrings()
46 call nthstring(ifi,file)
48 call readfile(nmax,x,nexcl,jcol,file,iverb)
49 if(file.eq."-") file="stdin"
50 if(isout.eq.1) call addsuff(fout,file,"_pred")
51 call rms(nmax,x,sc,sd)
52 if(frac.gt.0) eps=sd*frac
54 if(fout.eq." ") iun=istderr()
55 write(iun,*) "err: ", fcerror(nmax,x,y,m,id,ifc,eps),
56 . " "//file(1:index(file," ")-1)
57 10 call writefile(nmax,y,fout,iverb)
64 . "-d# -m# [-r# | -v#]"//
65 . " [-s# -o outfile -l# -x# -c# -V# -h] file(s)")
66 call ptext("either -r or -v must be present")
67 call popt("d","delay")
68 call popt("m","embedding dimension")
69 call popt("r","absolute radius of neighbourhoods")
70 call popt("v","same as fraction of standard deviation")
71 call popt("s","time steps ahead forecast (one step)")
72 call popt("l","number of values to be read (all)")
73 call popt("x","number of values to be skipped (0)")
74 call popt("c","column to be read (1 or file,#)")
75 call pout("file_pred")
80 function fcerror(nmax,y,yp,m,id,ifc,eps)
81 parameter(im=100,ii=100000000,nx=1000000)
82 dimension y(nmax),yp(nx),jh(0:im*im),jpntr(nx),nlist(nx)
84 if(nmax.gt.nx) stop "fcerror: make nx larger."
85 call base(nmax-ifc,y,id,m,jh,jpntr,eps)
88 call rms(nmax,y,sx,sd)
89 do 10 n=1,(m-1)*id+ifc
91 do 20 n=(m-1)*id+1,nmax-ifc
92 call neigh(nmax,y,y,n,nmax,id,m,jh,jpntr,eps,nlist,nfound)
95 30 if(nlist(nn).ne.n) av=av+y(nlist(nn)+ifc)
97 yp(n+ifc)=av/(nfound-1)
101 20 fcerror=fcerror+(y(n+ifc)-yp(n+ifc))**2
102 fcerror=sqrt(fcerror/(nmax-ifc-(m-1)*id))