/* * 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: Feb 19, 2007 */ /* Changes: 2/19/2007: Changed name and default for noise 10/26/2006: Add seed option */ #include #include #include #include #include #include #include "routines/tsa.h" #define WID_STR "Makes a local zeroth order forecast for multivariate data\n\ and iterates a trajectory" #define NMAX 128 char onscreen=1,epsset=0,*outfile=NULL,setsort=1,setnoise=0; char *infile=NULL; unsigned int nmax=(NMAX-1); unsigned int verbosity=0xff; long **box,*list,*found; double **series,**cast,*abstand,*var; double epsilon; unsigned int embed=2,dim=1,dim1,DELAY=1; char *column=NULL,dimset=0; unsigned int MINN=50; unsigned int **indexes; unsigned long LENGTH=ULONG_MAX,FLENGTH=1000,exclude=0; unsigned long seed=0x9074325L; double EPS0=1.e-3,EPSF=1.2,Q=10.0; double **mat,*vec,*hsum,*newav; void show_options(char *progname) { what_i_do(progname,WID_STR); fprintf(stderr," Usage: %s [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 be used [default whole file]\n"); fprintf(stderr,"\t-x # of lines to be ignored [default 0]\n"); fprintf(stderr,"\t-c column [default 1,...,# of components]\n"); fprintf(stderr,"\t-m #of components,embedding dimension [default 1,2]\n"); fprintf(stderr,"\t-d delay for the embedding [default 1]\n"); fprintf(stderr,"\t-L # of iterations [default 1000]\n"); fprintf(stderr,"\t-k # of neighbors [default %u]\n",MINN); fprintf(stderr,"\t-K fix # of neighbors [default no]\n"); fprintf(stderr,"\t-%% # variance of noise [default %3.1lf]\n",Q); fprintf(stderr,"\t-I seed for the rnd-generator (If seed=0, the time\n" "\t\tcommand is used to set the seed) [Default: fixed]\n"); fprintf(stderr,"\t-r size of initial neighborhood [" " default (data interval)/1000]\n"); fprintf(stderr,"\t-f factor to increase size [default 1.2]\n"); fprintf(stderr,"\t-o output file [default 'datafile'.lzr;" " no -o means write to 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"); exit(0); } void scan_options(int n,char **in) { char *out; if ((out=check_option(in,n,'l','u')) != NULL) sscanf(out,"%lu",&LENGTH); if ((out=check_option(in,n,'x','u')) != NULL) sscanf(out,"%lu",&exclude); if ((out=check_option(in,n,'c','s')) != NULL) { column=out; dimset=1; } if ((out=check_option(in,n,'m','2')) != NULL) sscanf(out,"%u,%u",&dim,&embed); if ((out=check_option(in,n,'d','u')) != NULL) sscanf(out,"%u",&DELAY); if ((out=check_option(in,n,'L','u')) != NULL) sscanf(out,"%lu",&FLENGTH); if ((out=check_option(in,n,'k','u')) != NULL) sscanf(out,"%u",&MINN); if ((out=check_option(in,n,'K','n')) != NULL) setsort=1; if ((out=check_option(in,n,'I','u')) != NULL) { sscanf(out,"%lu",&seed); if (seed == 0) seed=(unsigned long)time((time_t*)&seed); } if ((out=check_option(in,n,'V','u')) != NULL) sscanf(out,"%u",&verbosity); if ((out=check_option(in,n,'r','f')) != NULL) { epsset=1; sscanf(out,"%lf",&EPS0); } if ((out=check_option(in,n,'f','f')) != NULL) sscanf(out,"%lf",&EPSF); if ((out=check_option(in,n,'%','f')) != NULL) { sscanf(out,"%lf",&Q); if (Q>0.0) setnoise=1; } if ((out=check_option(in,n,'o','o')) != NULL) { onscreen=0; if (strlen(out) > 0) outfile=out; } } void sort(unsigned long nfound) { double dx,dswap; int i,j,k,hf,iswap,hdim; hdim=(embed-1)*DELAY; for (i=0;i abstand[i]) abstand[i]=dx; } } } for (i=0;imax) ? dx : max; if (max > epsilon) { toolarge=1; break; } } if (max <= epsilon) found[nfound++]=element; element=list[element]; } } } return nfound; } void make_zeroth(int number,double *newcast) { long d,i; double *sd; for (d=0;d maxinterval) maxinterval=interval[i]; } if (epsset) EPS0 /= maxinterval; check_alloc(cast=(double**)malloc(sizeof(double*)*hdim)); for (i=0;i= MINN) { if (setsort) { epsilon0 += epsilon; count++; sort(actfound); actfound=MINN; } make_zeroth(actfound,newcast); if (onscreen) { for (j=0;j