/* * 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 4, 1999 */ #include #include #include #include #include #include #include "routines/tsa.h" #define WID_STR "Does a backward elimination for a polynomial" char *outfile=NULL,stdo=1; char *parin=NULL,*infile=NULL; unsigned long length=ULONG_MAX,insample=ULONG_MAX,exclude=0; unsigned int plength=UINT_MAX; unsigned int column=1,dim=2,delay=1,down_to=1,step=1; unsigned int **order; unsigned int verbosity=0xff; double *series,*param; 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 use [default: whole file]\n"); fprintf(stderr,"\t-x # of lines to ignore [default: %lu]\n",exclude); fprintf(stderr,"\t-c column to read [default: %u]\n",column); fprintf(stderr,"\t-m embedding dimension [default: %u]\n",dim); fprintf(stderr,"\t-d delay [default: %u]\n",delay); fprintf(stderr,"\t-n insample data [default: all]\n"); fprintf(stderr,"\t-s steps to forecast [default: %u]\n",step); fprintf(stderr,"\t-# reduce down to # terms [default: %u]\n",down_to); fprintf(stderr,"\t-p name of parameter file [default: parameter.pol]\n"); fprintf(stderr,"\t-o output file name [default: 'datafile'.pbe]\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','u')) != NULL) sscanf(out,"%u",&column); if ((out=check_option(in,n,'m','u')) != NULL) sscanf(out,"%u",&dim); if ((out=check_option(in,n,'d','u')) != NULL) sscanf(out,"%u",&delay); if ((out=check_option(in,n,'n','u')) != NULL) sscanf(out,"%lu",&insample); if ((out=check_option(in,n,'#','u')) != NULL) sscanf(out,"%u",&down_to); if ((out=check_option(in,n,'s','u')) != NULL) sscanf(out,"%u",&step); if ((out=check_option(in,n,'V','u')) != NULL) sscanf(out,"%u",&verbosity); if ((out=check_option(in,n,'p','s')) != NULL) parin=out; if ((out=check_option(in,n,'o','o')) != NULL) { stdo=0; if (strlen(out) > 0) outfile=out; } } double polynom(unsigned long act,unsigned int which) { unsigned int i,j; double ret=1.0,h; for (i=0;i= length) { insample=length; out_set=0; } check_alloc(order=(unsigned int**)malloc(sizeof(int*)*hlength)); check_alloc(param=(double*)malloc(sizeof(double)*hlength)); for (i=0;i hlength)) down_to=1; for (i=1;i<=hlength-down_to;i++) { plength=hlength-i; besti=besto=0.0; ibest= -1; check_alloc(order=(unsigned int**)malloc(sizeof(int*)*plength)); check_alloc(param=(double*)malloc(sizeof(double)*plength)); for (j=0;j