/* * This file is part of TISEAN * * Copyright (c) 1998-2007 Rainer Hegger, Holger Kantz, Thomas Schreiber * * TISEAN is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * TISEAN is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with TISEAN; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /*Author: Rainer Hegger. Last modified: Sep 5, 2004 */ #include #include #include #include #include #include "routines/tsa.h" #define WID_STR "Tests for nonstationarity by means of the average\n\t\ forecast error for a zeroth order fit" #ifndef _MATH_H #include #endif /*number of boxes for the neighbor search algorithm*/ #define NMAX 128 unsigned int nmax=(NMAX-1); long **box,*list; unsigned long *found; double *series,*series1,*series2; double interval,min,epsilon; char epsset=0,causalset=0; char *infile=NULL; char *outfile=NULL,stdo=1,centerset=0; char *firstwindow,*secondwindow,**window; unsigned int COLUMN=1,pieces; unsigned int verbosity=0xff; int DIM=3,DELAY=1,MINN=30,STEP=1; int firstoffset= -1,secondoffset= -1; double EPS0=1.e-3,EPSF=1.2; unsigned long LENGTH=ULONG_MAX,exclude=0,center,causal; void show_options(char *progname) { what_i_do(progname,WID_STR); fprintf(stderr," Usage: %s -# [other options]\n",progname); fprintf(stderr," Options:\n"); fprintf(stderr,"Everything not being a valid option will be interpreted" " as a possible" " datafile.\nIf no datafile is given stdin is read. Just - also" " means stdin\n"); fprintf(stderr,"\t-l # of data to use [default: whole file]\n"); fprintf(stderr,"\t-x # of lines to be ignored [default: 0]\n"); fprintf(stderr,"\t-c column to read [default: 1]\n"); fprintf(stderr,"\t-m embedding dimension [default: 3]\n"); fprintf(stderr,"\t-d delay [default: 1]\n"); fprintf(stderr,"\t-# # of pieces [no default]\n"); fprintf(stderr,"\t-1 which pieces for the first window " "[default: 1-pieces]\n"); fprintf(stderr,"\t-2 which pieces for the second window " "[default: 1-pieces]\n"); fprintf(stderr,"\t-n # of reference points in the window [default: all]\n"); fprintf(stderr,"\t-k minimal number of neighbors for the fit " "[default: 30]\n"); fprintf(stderr,"\t-r neighborhoud size to start with " "[default: (data interval)/1000]\n"); fprintf(stderr,"\t-f factor to increase size [default: 1.2]\n"); fprintf(stderr,"\t-s steps to forecast [default: 1]\n"); fprintf(stderr,"\t-C width of causality window [default: steps]\n"); fprintf(stderr,"\t-o output file [default: 'datafile.nsz'," " without -o: stdout]\n"); fprintf(stderr,"\t-V verbosity level [default: 1]\n\t\t" "0='only panic messages'\n\t\t" "1='+ input/output messages'\n"); fprintf(stderr,"\t-h show these options\n"); fprintf(stderr,"\n\t The -# option has to be set\n"); exit(0); } void parse_minus(char *str,char *array,char *wopt) { int cm=0,i,strl,n1,n2; strl=strlen(str); for (i=0;i 1) { fprintf(stderr,"Invalid string for the %s option! " "Please consult the help-page\n",wopt); exit(NSTAT_Z__INVALID_STRING_FOR_OPTION); } if (cm == 0) { sscanf(str,"%d",&n1); n1--; if (n1 < 0) { fprintf(stderr,"Numbers in %s option must be larger than 0!\n",wopt); exit(NSTAT_Z__NOT_UNSIGNED_FOR_OPTION); } if (n1 >= pieces) { fprintf(stderr,"Numbers in %s option must be smaller than %u!\n",wopt, pieces); exit(NSTAT_Z__TOO_LARGE_FOR_OPTION); } array[n1]=1; } else { sscanf(str,"%d-%d",&n1,&n2); n1--; n2--; if ((n1 < 0) || (n2 < 0)) { fprintf(stderr,"Numbers in %s option must be larger than 0!\n",wopt); exit(NSTAT_Z__NOT_UNSIGNED_FOR_OPTION); } if ((n1 >= pieces) || (n2 >= pieces)) { fprintf(stderr,"Numbers in %s option must be smaller than %u!\n",wopt, pieces+1); exit(NSTAT_Z__TOO_LARGE_FOR_OPTION); } if (n2 < n1) { i=n1; n1=n2; n2=i; } for (i=n1;i<=n2;i++) array[i]=1; } } void parse_comma(char *str,char *array,char *wopt) { unsigned int strl,i,cp=1,which,iwhich; char **hstr; strl=strlen(str); for (i=0;i 0) outfile=out; } } double make_fit(long act,unsigned long number) { double casted=0.0,*help; int i; help=series1+STEP; for (i=0;i= 0) && (first < pieces)) window[first][second]=secondwindow[second]; } if (secondoffset != -1) { for (first=0;first= 0) && (second < pieces)) window[first][second]=firstwindow[first]; } free(firstwindow); free(secondwindow); for (first=0;first= MINN) { error += make_fit(i,actfound); done[i]=1; } alldone &= done[i]; } } if (stdo) fprintf(stdout,"%ld %ld %e\n",first+1,second+1, sqrt(error/center)/rms[second]); else { fprintf(file,"%ld %ld %e\n",first+1,second+1, sqrt(error/center)/rms[second]); fflush(file); } } } if (sdone) { if (stdo) fprintf(stdout,"\n"); else fprintf(file,"\n"); } } if (!stdo) fclose(file); if (outfile != NULL) free(outfile); free(list); free(found); free(hfound); free(done); for (i=0;i