=================================================================== RCS file: /home/cvs/OpenXM/src/hgm/mh/src/wmain.c,v retrieving revision 1.11 retrieving revision 1.24 diff -u -p -r1.11 -r1.24 --- OpenXM/src/hgm/mh/src/wmain.c 2013/03/07 05:23:31 1.11 +++ OpenXM/src/hgm/mh/src/wmain.c 2015/04/02 01:11:13 1.24 @@ -1,5 +1,5 @@ /* - $OpenXM: OpenXM/src/hgm/mh/src/wmain.c,v 1.10 2013/03/07 03:00:43 takayama Exp $ + $OpenXM: OpenXM/src/hgm/mh/src/wmain.c,v 1.23 2015/03/24 07:49:06 takayama Exp $ License: LGPL */ #include @@ -9,9 +9,13 @@ #include "sfile.h" #include "mh.h" #define SMAX 4096 -#define inci(i) { i++; if (i >= argc) { fprintf(stderr,"Option argument is not given.\n"); return(NULL); }} +#define inci(i) { i++; if (i >= argc) { oxprintfe("Option argument is not given.\n"); return(NULL); }} int MH_deallocate=0; +/* + changelog + 2014.03.15 --strategy 1 is default. A new parser in setParam() + */ extern char *MH_Gfname; extern char *MH_Dfname; @@ -31,7 +35,23 @@ int MH_Dp; /* Data sampling period */ static double Xng=0.0; /* the last point */ int MH_RawName = 0; static int Testrank=0; +/* If MH_success is set to 1, then strategy, MH_abserr, MH_relerr seem to + be properly set. +*/ +int MH_success=0; +/* + Estimation of the maximal coeff of A in y'=Ay. + This might be too rough estimate. + */ +double MH_coeff_max; +/* + Estimation of h by MH_coeff_max; + */ +double MH_estimated_start_step; extern int MH_Verbose; +extern int MH_strategy; +extern double MH_abserr; +extern double MH_relerr; extern int MH_P95; /* 95 % points */ int mh_gopen_file(void); @@ -40,6 +60,7 @@ static int setParamDefault(void); static int setParam(char *fname); static int showParam(void); static int next(struct SFILE *fp,char *s, char *msg); +static double estimateHg(int m, double beta[],double x0); /* #define DEBUG */ #ifdef DEBUG @@ -64,15 +85,20 @@ static int mypower(int x,int n) { return(a); } #ifdef STANDALONE2 -main(int argc,char *argv[]) { +int main(int argc,char *argv[]) { + int strategy=STRATEGY_DEFAULT; + double err[2]={-1.0,-1.0}; + int i; mh_exit(MH_RESET_EXIT); /* standalone mode */ /* mh_main(argc,argv); mh_freeWorkArea(); */ mh_main(argc,argv); + /* showParam(); */ + return(0); } #endif struct MH_RESULT *mh_main(int argc,char *argv[]) { - static double *y0; + static double *y0=NULL; double x0,xn; double ef; int i,rank; @@ -114,13 +140,18 @@ struct MH_RESULT *mh_main(int argc,char *argv[]) { MH_Verbose=1; }else if (strcmp(argv[i],"--bystring")==0) { MH_byFile = 0; + }else if (strcmp(argv[i],"--strategy")==0) { + i++; sscanf(argv[i],"%d",&MH_strategy); + }else if (strcmp(argv[i],"--abserr")==0) { + i++; sscanf(argv[i],"%lg",&MH_abserr); + }else if (strcmp(argv[i],"--relerr")==0) { + i++; sscanf(argv[i],"%lg",&MH_relerr); }else { - fprintf(stderr,"Unknown option %s\n",argv[i]); + oxprintfe("Unknown option %s\n",argv[i]); mh_usage(); return(rp); } } - if (MH_Verbose) showParam(); x0 = MH_X0g; xn = Xng; ef = Ef; @@ -128,40 +159,61 @@ struct MH_RESULT *mh_main(int argc,char *argv[]) { y0 = (double *) mh_malloc(sizeof(double)*rank); for (i=0; i SIGDIGIT_DEFAULT*myabs(y0[0])) { + MH_success = 0; + oxprintfe("%%%%Warning, abserr seems not to be small enough, abserr=%lg, y[0]=%lg\n",MH_abserr,y0[0]); + }else{ + MH_success = 1; + } + }else{ + MH_success = 0; + } + MH_estimated_start_step = estimateHg(MH_Mg,MH_Beta,MH_X0g); + if (MH_Verbose) showParam(); + if (MH_Verbose) {for (i=0; it.txt\n"); + oxprintfe(" ./hgm_w-n --idata t.txt --gnuplotf test-g --verbose\n"); + oxprintfe(" gnuplot -persist 1) dmin = myabs(beta[1]-beta[0]); + else dmin=myabs(beta[0]); + for (i=0; i