/* * 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 29, 2000 */ #include #include #include #include #include #include "routines/tsa.h" #define WID_STR "Makes a local linear fit for multivariate data\n\ and iterates a trajectory" #define NMAX 128 char onscreen=1,epsset=0,*outfile=NULL; char *infile=NULL; unsigned int nmax=(NMAX-1); unsigned int verbosity=0xff; long **box,*list,*found; double **series,**cast; double *interval,*min,epsilon; unsigned int embed=2,dim=1,dim1,DELAY=1; char *column=NULL,dimset=0,do_zeroth=0; int MINN=30; unsigned long LENGTH=ULONG_MAX,FLENGTH=1000,exclude=0; double EPS0=1.e-3,EPSF=1.2; double **mat,**imat,*vec,*localav,*foreav; 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 30]\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-0 perfom a zeroth order fit [default not set]\n"); fprintf(stderr,"\t-o output file [default 'datafile'.cast;" " 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,'0','n')) != NULL) do_zeroth=1; 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,'o','o')) != NULL) { onscreen=0; if (strlen(out) > 0) outfile=out; } } void put_in_boxes(void) { int i,j,n; static int hdim; double epsinv; hdim=(embed-1)*DELAY; epsinv=1.0/epsilon; for (i=0;imax) ? dx : max; if (max > epsilon) { toolarge=1; break; } } if (toolarge) break; } if (max <= epsilon) found[nfound++]=element; element=list[element]; } } } return nfound; } void multiply_matrix(double **mat,double *vec) { double *hvec; long i,j; check_alloc(hvec=(double*)malloc(sizeof(double)*dim*embed)); for (i=0;i= hi) { for (n=0;n maxinterval) maxinterval=interval[i]; } check_alloc(cast=(double**)malloc(sizeof(double*)*hdim)); for (i=0;i= MINN) { if (!do_zeroth) make_fit(actfound,newcast); else make_zeroth(actfound,newcast); if (onscreen) { for (j=0;j 2.0) || (newcast[j] < -1.0)) { fprintf(stderr,"Forecast failed. Escaping data region!\n"); exit(NSTEP__ESCAPE_REGION); } } swap=cast[0]; for (j=0;j