[BACK]Return to wmain.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / hgm / mh / src

Annotation of OpenXM/src/hgm/mh/src/wmain.c, Revision 1.27

1.1       takayama    1: /*
1.27    ! takayama    2:   $OpenXM: OpenXM/src/hgm/mh/src/wmain.c,v 1.26 2016/02/01 11:37:14 takayama Exp $
1.10      takayama    3:   License: LGPL
                      4: */
1.1       takayama    5: #include <stdio.h>
                      6: #include <stdlib.h>
                      7: #include <math.h>
                      8: #include <string.h>
1.4       takayama    9: #include "sfile.h"
1.11      takayama   10: #include "mh.h"
1.1       takayama   11: #define SMAX 4096
1.22      takayama   12: #define inci(i) { i++; if (i >= argc) { oxprintfe("Option argument is not given.\n"); return(NULL); }}
1.3       takayama   13: int MH_deallocate=0;
                     14:
1.20      takayama   15: /*
                     16:   changelog
1.27    ! takayama   17:   2016.02.04  MH_Ef_type  exponential or scalar factor
1.26      takayama   18:   2016.02.01  C_2F1
1.20      takayama   19:   2014.03.15  --strategy 1 is default. A new parser in setParam()
                     20:  */
1.1       takayama   21: extern char *MH_Gfname;
                     22: extern char *MH_Dfname;
                     23:
                     24: /* global variables. They are set in setParam() */
1.4       takayama   25: int MH_byFile=1;
1.1       takayama   26: int MH_RANK;
                     27: int MH_M;
                     28:
                     29: int MH_Mg;  /* m */
                     30: double *MH_Beta; /* beta[0], ..., beta[m-1] */
1.2       takayama   31: double *MH_Ng;   /* freedom n.  c=(m+1)/2+n/2; Note that it is a pointer */
                     32: double MH_X0g;   /* initial point */
                     33: static double *Iv;   /* Initial values of mhg sorted by mhbase() in rd.rr at beta*x0 */
                     34: static double Ef;   /* exponential factor at beta*x0 */
                     35: extern double MH_Hg;   /* step size of rk defined in rk.c */
                     36: int MH_Dp;      /* Data sampling period */
                     37: static double Xng=0.0;   /* the last point */
                     38: int MH_RawName = 0;
                     39: static int Testrank=0;
1.20      takayama   40: /* If MH_success is set to 1, then strategy, MH_abserr, MH_relerr seem to
                     41:   be properly set.
                     42: */
                     43: int MH_success=0;
                     44: /*
                     45:   Estimation of the maximal coeff of A in y'=Ay.
                     46:   This might be too rough estimate.
                     47:  */
                     48: double MH_coeff_max;
                     49: /*
                     50:   Estimation of h by MH_coeff_max;
                     51:  */
                     52: double MH_estimated_start_step;
1.26      takayama   53:
                     54: #ifdef C_2F1
                     55: int MH_P_pFq=2;
                     56: int MH_Q_pFq=1;
                     57: double MH_A_pFq[2];
                     58: double MH_B_pFq[1];
1.27    ! takayama   59: int MH_Ef_type=2;
1.26      takayama   60: #else
                     61: int MH_P_pFq=1;
                     62: int MH_Q_pFq=1;
                     63: double MH_A_pFq[1];
                     64: double MH_B_pFq[1];
1.27    ! takayama   65: int MH_Ef_type=1;
1.26      takayama   66: #endif
1.2       takayama   67: extern int MH_Verbose;
1.20      takayama   68: extern int MH_strategy;
                     69: extern double MH_abserr;
                     70: extern double MH_relerr;
1.16      takayama   71:
1.2       takayama   72: extern int MH_P95;  /* 95 % points */
                     73: int mh_gopen_file(void);
                     74: static int setParamTest(void);
                     75: static int setParamDefault(void);
                     76: static int setParam(char *fname);
                     77: static int showParam(void);
1.6       takayama   78: static int next(struct SFILE *fp,char *s, char *msg);
1.20      takayama   79: static double estimateHg(int m, double beta[],double x0);
1.1       takayama   80:
1.26      takayama   81: #ifdef C_2F1
                     82: void mh_setabc(double a,double b,double c);
                     83: #endif
1.1       takayama   84: /* #define DEBUG */
                     85: #ifdef DEBUG
1.2       takayama   86: char *MH_Dfname; char *MH_Gfname; double MH_Hg;
                     87: int mh_gopen_file(void) { }
1.4       takayama   88: struct MH_RESULT mh_rkmain(double x0,double y0[],double xn) { }
1.1       takayama   89: #endif
                     90:
1.3       takayama   91: void mh_freeWorkArea(void) {
                     92:   extern int MH_deallocate;
                     93:   MH_deallocate=1; /* switch to deallocation mode. */
                     94:   mh_main(0,NULL);
                     95:   setParam(NULL);
                     96:   mh_rkmain(0.0, NULL, 0.0);
                     97:   mh_rf(0.0, NULL, 0, NULL, 0);
                     98:   MH_deallocate=0; /* switch to the normal mode. */
                     99: }
1.8       takayama  100: static int mypower(int x,int n) {
1.1       takayama  101:   int a,i;
                    102:   a = 1;
                    103:   for (i=0; i<n; i++) a = a*x;
                    104:   return(a);
                    105: }
1.9       takayama  106: #ifdef STANDALONE2
1.24      takayama  107: int main(int argc,char *argv[]) {
1.12      takayama  108:   int strategy=STRATEGY_DEFAULT;
                    109:   double err[2]={-1.0,-1.0};
                    110:   int i;
1.6       takayama  111:   mh_exit(MH_RESET_EXIT); /* standalone mode */
1.10      takayama  112:   /*  mh_main(argc,argv);
                    113:       mh_freeWorkArea(); */
1.3       takayama  114:   mh_main(argc,argv);
1.12      takayama  115:   /* showParam(); */
1.18      takayama  116:   return(0);
1.2       takayama  117: }
                    118: #endif
1.4       takayama  119: struct MH_RESULT *mh_main(int argc,char *argv[]) {
1.13      takayama  120:   static double *y0=NULL;
1.1       takayama  121:   double x0,xn;
                    122:   double ef;
                    123:   int i,rank;
1.4       takayama  124:   struct MH_RESULT *rp=NULL;
1.3       takayama  125:   extern int MH_deallocate;
1.4       takayama  126:   extern int MH_byFile;
                    127:   MH_byFile=1;
                    128:   if (MH_deallocate) { if (y0) mh_free(y0); return(rp); }
1.2       takayama  129:   setParam(NULL); MH_Gfname = MH_Dfname = NULL; MH_Verbose=1;
1.1       takayama  130:   for (i=1; i<argc; i++) {
1.10      takayama  131:     if (strcmp(argv[i],"--idata")==0) {
1.1       takayama  132:       inci(i);
1.10      takayama  133:       setParam(argv[i]); MH_Verbose=0;
                    134:     }else if (strcmp(argv[i],"--gnuplotf")==0) {
1.1       takayama  135:       inci(i);
1.10      takayama  136:       MH_Gfname = (char *)mh_malloc(SMAX);
                    137:       strcpy(MH_Gfname,argv[i]);
                    138:     }else if (strcmp(argv[i],"--dataf")==0) {
                    139:       inci(i);
                    140:       MH_Dfname = (char *)mh_malloc(SMAX);
                    141:       strcpy(MH_Dfname,argv[i]);
                    142:     }else if (strcmp(argv[i],"--xmax")==0) {
                    143:       inci(i);
                    144:       sscanf(argv[i],"%lf",&Xng);
                    145:     }else if (strcmp(argv[i],"--step")==0) {
                    146:       inci(i);
                    147:       sscanf(argv[i],"%lg",&MH_Hg);
                    148:     }else if (strcmp(argv[i],"--help")==0) {
                    149:       mh_usage(); return(rp);
                    150:     }else if (strcmp(argv[i],"--raw")==0) {
                    151:       MH_RawName = 1;
                    152:     }else if (strcmp(argv[i],"--test")==0) {
                    153:       inci(i);
                    154:       sscanf(argv[i],"%d",&Testrank);
                    155:       setParamTest();
                    156:     }else if (strcmp(argv[i],"--95")==0) {
                    157:       MH_P95=1;
                    158:     }else if (strcmp(argv[i],"--verbose")==0) {
                    159:       MH_Verbose=1;
                    160:     }else if (strcmp(argv[i],"--bystring")==0) {
                    161:       MH_byFile = 0;
1.20      takayama  162:     }else if (strcmp(argv[i],"--strategy")==0) {
                    163:       i++; sscanf(argv[i],"%d",&MH_strategy);
                    164:     }else if (strcmp(argv[i],"--abserr")==0) {
                    165:       i++; sscanf(argv[i],"%lg",&MH_abserr);
                    166:     }else if (strcmp(argv[i],"--relerr")==0) {
                    167:       i++; sscanf(argv[i],"%lg",&MH_relerr);
1.10      takayama  168:     }else {
1.22      takayama  169:       oxprintfe("Unknown option %s\n",argv[i]);
1.10      takayama  170:       mh_usage();
                    171:       return(rp);
                    172:     }
1.1       takayama  173:   }
1.2       takayama  174:   x0 = MH_X0g;
1.1       takayama  175:   xn = Xng;
                    176:   ef = Ef;
                    177:   rank = mypower(2,MH_Mg);
1.2       takayama  178:   y0 = (double *) mh_malloc(sizeof(double)*rank);
1.1       takayama  179:   for (i=0; i<rank; i++) y0[i] = ef*Iv[i];
1.2       takayama  180:   mh_gopen_file();
1.20      takayama  181:   rp = (struct MH_RESULT*) mh_malloc(sizeof(struct MH_RESULT));
                    182:
                    183:   if (MH_strategy) {
                    184:     if (MH_abserr > SIGDIGIT_DEFAULT*myabs(y0[0])) {
                    185:       MH_success = 0;
1.22      takayama  186:       oxprintfe("%%%%Warning, abserr seems not to be small enough, abserr=%lg, y[0]=%lg\n",MH_abserr,y0[0]);
1.20      takayama  187:     }else{
                    188:       MH_success = 1;
                    189:     }
                    190:   }else{
                    191:     MH_success = 0;
                    192:   }
                    193:   MH_estimated_start_step = estimateHg(MH_Mg,MH_Beta,MH_X0g);
                    194:   if (MH_Verbose) showParam();
1.22      takayama  195:   if (MH_Verbose) {for (i=0; i<rank; i++) oxprintf("%lf\n",y0[i]); }
1.19      takayama  196:
1.26      takayama  197: #ifdef C_2F1
                    198:   mh_setabc(MH_A_pFq[0],MH_A_pFq[1],MH_B_pFq[0]);
                    199: #endif
1.4       takayama  200:   *rp=mh_rkmain(x0,y0,xn);
                    201:   return(rp);
1.1       takayama  202: }
                    203:
1.8       takayama  204: int mh_usage() {
1.22      takayama  205:   oxprintfe("Usages:\n");
1.26      takayama  206: #ifdef C_2F1
                    207:   oxprintfe("hgm_w-n-2f1 ");
                    208: #else
                    209:   oxprintfe("hgm_w-n ");
                    210: #endif
                    211:   oxprintfe("   [--idata input_data_file --gnuplotf gnuplot_file_name\n");
1.22      takayama  212:   oxprintfe(" --dataf output_data_file --raw --xmax xmax --test m --step h]\n");
                    213:   oxprintfe("[ --95 --verbose] \n");
                    214:   oxprintfe("[ --strategy s --abserr ae --relerr re] \n");
                    215:   oxprintfe("s:0 rk, s:1 adaptive, s:2 adaptive&multiply, see rk.c for the default value of ae and re.\n");
                    216:   oxprintfe("strategy default = %d\n",MH_strategy);
                    217:   oxprintfe("--raw does not add data parameters to the output_data_file.\n");
                    218:   oxprintfe("\nThe command hgm_w-n [options] evaluates Pr({y | y<xmax}), which is the cumulative distribution function of the largest root of the m by m Wishart matrix with n degrees of freedom and the covariantce matrix sigma.\n");
                    219:   oxprintfe("All the eigenvalues of sigma must be simple.\n");
                    220:   oxprintfe("Parameters are specified by the input_data_file.\n");
                    221:   oxprintfe("Parameters are redefined when they appear more than once in the idata file and the command line options.\n");
                    222:   oxprintfe("The format of the input_data_file, which should be generated by the command hgm_jack-n.\n");
                    223:   oxprintfe(" MH_Mg: m, MH_Beta: beta=sigma^(-1)/2 (diagonized), MH_Ng: n, MH_X0g: starting value of x,\n");
                    224:   oxprintfe(" Iv: initial values at MH_X0g*MH_Beta (see our paper how to order them), \n");
                    225:   oxprintfe(" Ef: a scalar factor to the initial value. It may set to 1.\n");
                    226:   oxprintfe(" MH_Hg: h (step size),\n");
                    227:   oxprintfe(" MH_Dp: output data is stored in every MH_Dp steps when output_data_file is specified.\n");
                    228:   oxprintfe(" Xng: terminating value of x.\n\n");
                    229:   oxprintfe("--95: output the 95%% point. --verbose: verbose mode.\n");
                    230:   oxprintfe("The line started with %%%% or # is a comment line.\n");
                    231:   oxprintfe("An example format of the input_data_file can be obtained by executing hgm_jack-n with no option.\n");
                    232:   oxprintfe("When --idata option is used, this command is quiet. Use --verbose option if you want to see some messages.\n");
                    233:   oxprintfe("\nExamples:\n");
                    234:   oxprintfe("[1] ./hgm_w-n \n");
                    235:   oxprintfe("[2] ./hgm_w-n --xmax 20\n");
                    236:   oxprintfe("[3] ./hgm_w-n --test 6\n");
                    237:   oxprintfe("   A test run in Mg=6.\n");
                    238:   oxprintfe("[4] ./hgm_jack-n --idata Testdata/tmp-idata3.txt >t.txt\n");
                    239:   oxprintfe("    ./hgm_w-n --idata t.txt --gnuplotf test-g --verbose\n");
                    240:   oxprintfe("    gnuplot -persist <test-g-gp.txt\n");
                    241:   oxprintfe("  tmp-idata3.txt is a sample input data distributed with this file.\n");
                    242:   oxprintfe("  test-g-gp.txt is an input file of the gnuplot\n");
1.23      takayama  243:   oxprintfe("  test-g is the table of x and the values of Pr({y | y<x}).\n"); return(0);
1.1       takayama  244: }
                    245:
1.8       takayama  246: static int setParamTest() {
1.1       takayama  247:   int rank;
                    248:   int i;
                    249:   extern int Testrank;
1.2       takayama  250:   extern int MH_Verbose;
                    251:   MH_Verbose=1;
1.1       takayama  252:   MH_M= MH_Mg = Testrank ;
                    253:   MH_RANK = rank = mypower(2,MH_Mg);
1.2       takayama  254:   MH_Beta = (double *)mh_malloc(sizeof(double)*MH_Mg);
1.1       takayama  255:   for (i=0; i<MH_Mg; i++) MH_Beta[i] = 1.0+0.1*i;
1.2       takayama  256:   MH_Ng = (double *)mh_malloc(sizeof(double)); *MH_Ng = 3.0;
                    257:   Iv = (double *)mh_malloc(sizeof(double)*rank);
1.1       takayama  258:   for (i=0; i<rank; i++) Iv[i] = 0;
                    259:   Iv[0] = 0.001;
                    260:   Ef = 1;
1.2       takayama  261:   MH_X0g = 0.3;
                    262:   MH_Hg = 0.001;
                    263:   MH_Dp = 1;
1.23      takayama  264:   Xng = 10.0; return(0);
1.1       takayama  265: }
1.8       takayama  266: static int setParamDefault() {
1.1       takayama  267:   int rank;
                    268:   MH_M=MH_Mg = 2 ;
                    269:   MH_RANK=rank = mypower(2,MH_Mg);
1.2       takayama  270:   MH_Beta = (double *)mh_malloc(sizeof(double)*MH_Mg);
1.1       takayama  271:   MH_Beta[0] = 1.0; MH_Beta[1] = 2.0;
1.2       takayama  272:   MH_Ng = (double *)mh_malloc(sizeof(double)); *MH_Ng = 3.0;
                    273:   Iv = (double *)mh_malloc(sizeof(double)*rank);
1.1       takayama  274:   Iv[0] = 1.58693;
                    275:   Iv[1] = 0.811369;
                    276:   Iv[2] = 0.846874;
                    277:   Iv[3] = 0.413438;
                    278:   Ef = 0.01034957388338225707;
1.2       takayama  279:   MH_X0g = 0.3;
                    280:   MH_Hg = 0.001;
                    281:   MH_Dp = 1;
1.23      takayama  282:   Xng = 10.0; return(0);
1.1       takayama  283: }
                    284:
1.8       takayama  285: static int next(struct SFILE *sfp,char *s,char *msg) {
1.1       takayama  286:   s[0] = '%';
                    287:   while (s[0] == '%') {
1.10      takayama  288:     if (!mh_fgets(s,SMAX,sfp)) {
1.22      takayama  289:       oxprintfe("Data format error at %s\n",msg);
1.10      takayama  290:       mh_exit(-1);
                    291:     }
                    292:     if (s[0] != '%') return(0);
1.23      takayama  293:   } return(0);
1.1       takayama  294: }
1.8       takayama  295: static int setParam(char *fname) {
1.1       takayama  296:   int rank;
                    297:   char s[SMAX];
1.4       takayama  298:   struct SFILE *fp;
1.1       takayama  299:   int i;
1.20      takayama  300:   struct mh_token tk;
1.3       takayama  301:   extern int MH_deallocate;
1.4       takayama  302:   extern int MH_byFile;
1.3       takayama  303:   if (MH_deallocate) {
1.10      takayama  304:     if (MH_Beta) mh_free(MH_Beta);
                    305:     if (MH_Ng) mh_free(MH_Ng);
                    306:     if (Iv) mh_free(Iv);
                    307:     return(0);
1.3       takayama  308:   }
1.1       takayama  309:   if (fname == NULL) return(setParamDefault());
                    310:
1.4       takayama  311:   if ((fp=mh_fopen(fname,"r",MH_byFile)) == NULL) {
1.22      takayama  312:     oxprintfe("File %s is not found.\n",fname);
1.10      takayama  313:     mh_exit(-1);
1.1       takayama  314:   }
                    315:   next(fp,s,"MH_Mg(m)");
                    316:   sscanf(s,"%d",&MH_Mg); MH_M=MH_Mg;
                    317:   MH_RANK=rank = mypower(2,MH_Mg);
                    318:
1.2       takayama  319:   MH_Beta = (double *)mh_malloc(sizeof(double)*MH_Mg);
1.1       takayama  320:   for (i=0; i<MH_Mg; i++) {
                    321:     next(fp,s,"MH_Beta");
1.10      takayama  322:     sscanf(s,"%lf",&(MH_Beta[i]));
1.1       takayama  323:   }
                    324:
1.2       takayama  325:   MH_Ng = (double *)mh_malloc(sizeof(double));
                    326:   next(fp,s,"MH_Ng(freedom parameter n)");
                    327:   sscanf(s,"%lf",MH_Ng);
1.1       takayama  328:
1.2       takayama  329:   next(fp,s,"MH_X0g(initial point)");
                    330:   sscanf(s,"%lf",&MH_X0g);
1.1       takayama  331:
1.2       takayama  332:   Iv = (double *)mh_malloc(sizeof(double)*rank);
1.1       takayama  333:   for (i=0; i<rank; i++) {
1.10      takayama  334:     next(fp,s,"Iv(initial values)");
                    335:     sscanf(s,"%lg",&(Iv[i]));
1.1       takayama  336:   }
                    337:
                    338:   next(fp,s,"Ef(exponential factor)");
                    339:   sscanf(s,"%lg",&Ef);
                    340:
1.2       takayama  341:   next(fp,s,"MH_Hg (step size of rk)");
                    342:   sscanf(s,"%lg",&MH_Hg);
1.1       takayama  343:
1.2       takayama  344:   next(fp,s,"MH_Dp (data sampling period)");
                    345:   sscanf(s,"%d",&MH_Dp);
1.1       takayama  346:
                    347:   next(fp,s,"Xng (the last point, cf. --xmax)");
                    348:   sscanf(s,"%lf",&Xng);
1.20      takayama  349:
                    350:   /* Reading the optional parameters */
                    351:   while ((tk = mh_getoken(s,SMAX-1,fp)).type != MH_TOKEN_EOF) {
                    352:     /* expect ID */
                    353:     if (tk.type != MH_TOKEN_ID) {
1.22      takayama  354:       oxprintfe("Syntax error at %s\n",s); mh_exit(-1);
1.20      takayama  355:     }
                    356:     if ((strcmp(s,"abserr")==0) || (strcmp(s,"abserror")==0)) {
                    357:       if (mh_getoken(s,SMAX-1,fp).type != MH_TOKEN_EQ) {
1.22      takayama  358:         oxprintfe("Syntax error at %s\n",s); mh_exit(-1);
1.20      takayama  359:       }
                    360:       if ((tk=mh_getoken(s,SMAX-1,fp)).type != MH_TOKEN_DOUBLE) {
1.22      takayama  361:         oxprintfe("Syntax error at %s\n",s); mh_exit(-1);
1.20      takayama  362:       }
                    363:       MH_abserr = tk.dval;
                    364:       continue;
                    365:     }
                    366:     if ((strcmp(s,"relerr")==0) || (strcmp(s,"relerror")==0)) {
                    367:       if (mh_getoken(s,SMAX-1,fp).type != MH_TOKEN_EQ) {
1.22      takayama  368:         oxprintfe("Syntax error at %s\n",s); mh_exit(-1);
1.20      takayama  369:       }
                    370:       if ((tk=mh_getoken(s,SMAX-1,fp)).type != MH_TOKEN_DOUBLE) {
1.22      takayama  371:         oxprintfe("Syntax error at %s\n",s); mh_exit(-1);
1.20      takayama  372:       }
                    373:       MH_relerr = tk.dval;
                    374:       continue;
                    375:     }
                    376:     if (strcmp(s,"strategy")==0) {
                    377:       if (mh_getoken(s,SMAX-1,fp).type != MH_TOKEN_EQ) {
1.22      takayama  378:         oxprintfe("Syntax error at %s\n",s); mh_exit(-1);
1.20      takayama  379:       }
                    380:       if ((tk=mh_getoken(s,SMAX-1,fp)).type != MH_TOKEN_INT) {
1.22      takayama  381:         oxprintfe("Syntax error at %s\n",s); mh_exit(-1);
1.20      takayama  382:       }
                    383:       MH_strategy = tk.ival;
                    384:       continue;
                    385:     }
1.26      takayama  386:     // Format: #p_pFq=2  1.5  3.2
                    387:     if (strcmp(s,"p_pFq")==0) {
                    388:       if (mh_getoken(s,SMAX-1,fp).type != MH_TOKEN_EQ) {
                    389:         oxprintfe("Syntax error at %s\n",s); mh_exit(-1);
                    390:       }
                    391:       if ((tk=mh_getoken(s,SMAX-1,fp)).type != MH_TOKEN_INT) {
                    392:         oxprintfe("Syntax error at %s\n",s); mh_exit(-1);
                    393:       }
                    394:       MH_P_pFq = tk.ival;
                    395:       for (i=0; i<MH_P_pFq; i++) {
                    396:        if ((tk=mh_getoken(s,SMAX-1,fp)).type == MH_TOKEN_DOUBLE) {
                    397:          MH_A_pFq[i] = tk.dval;
                    398:        }else if (tk.type == MH_TOKEN_INT) {
                    399:          MH_A_pFq[i] = tk.ival;
                    400:        }else{
                    401:          oxprintfe("Syntax error at %s\n",s); mh_exit(-1);
                    402:        }
                    403:       }
                    404:       continue;
                    405:     }
                    406:     if (strcmp(s,"q_pFq")==0) {
                    407:       if (mh_getoken(s,SMAX-1,fp).type != MH_TOKEN_EQ) {
                    408:         oxprintfe("Syntax error at %s\n",s); mh_exit(-1);
                    409:       }
                    410:       if ((tk=mh_getoken(s,SMAX-1,fp)).type != MH_TOKEN_INT) {
                    411:         oxprintfe("Syntax error at %s\n",s); mh_exit(-1);
                    412:       }
                    413:       MH_Q_pFq = tk.ival;
                    414:       for (i=0; i<MH_Q_pFq; i++) {
                    415:        if ((tk=mh_getoken(s,SMAX-1,fp)).type == MH_TOKEN_DOUBLE) {
                    416:          MH_B_pFq[i] = tk.dval;
                    417:        }else if (tk.type == MH_TOKEN_INT) {
                    418:          MH_B_pFq[i] = tk.ival;
                    419:        }else{
                    420:          oxprintfe("Syntax error at %s\n",s); mh_exit(-1);
                    421:        }
                    422:       }
                    423:       continue;
                    424:     }
1.27    ! takayama  425:     if (strcmp(s,"ef_type")==0) {
        !           426:       if (mh_getoken(s,SMAX-1,fp).type != MH_TOKEN_EQ) {
        !           427:         oxprintfe("Syntax error at %s\n",s); mh_exit(-1);
        !           428:       }
        !           429:       if ((tk=mh_getoken(s,SMAX-1,fp)).type != MH_TOKEN_INT) {
        !           430:         oxprintfe("Syntax error at %s\n",s); mh_exit(-1);
        !           431:       }
        !           432:       MH_Ef_type = tk.ival;
        !           433:       continue;
        !           434:     }
1.25      takayama  435:     oxprintfe("Unknown ID for wmain.c (old...) at %s.\n",s);  mh_exit(-1);
1.20      takayama  436:   }
                    437:
1.23      takayama  438:   mh_fclose(fp); return(0);
1.1       takayama  439: }
                    440:
1.20      takayama  441: static int showParam() {
1.1       takayama  442:   int rank,i;
1.12      takayama  443:   extern int MH_strategy;
                    444:   extern double MH_abserr;
                    445:   extern double MH_relerr;
1.1       takayama  446:   rank = mypower(2,MH_Mg);
1.22      takayama  447:   oxprintf("%%MH_Mg=\n%d\n",MH_Mg);
1.1       takayama  448:   for (i=0; i<MH_Mg; i++) {
1.22      takayama  449:     oxprintf("%%MH_Beta[%d]=\n%lf\n",i,MH_Beta[i]);
1.1       takayama  450:   }
1.22      takayama  451:   oxprintf("%%MH_Ng=\n%lf\n",*MH_Ng);
                    452:   oxprintf("%%MH_X0g=\n%lf\n",MH_X0g);
1.1       takayama  453:   for (i=0; i<rank; i++) {
1.22      takayama  454:     oxprintf("%%Iv[%d]=\n%lg\n",i,Iv[i]);
1.1       takayama  455:   }
1.22      takayama  456:   oxprintf("%%Ef=\n%lf\n",Ef);
                    457:   oxprintf("%%MH_Hg=\n%lf\n",MH_Hg);
                    458:   oxprintf("%%MH_Dp=\n%d\n",MH_Dp);
                    459:   oxprintf("%%Xng=\n%lf\n",Xng);
                    460:   oxprintf("%%strategy=%d\n",MH_strategy);
                    461:   oxprintf("%%abserr=%lg, %%relerr=%lg\n",MH_abserr,MH_relerr);
                    462:   oxprintf("#MH_success=%d\n",MH_success);
                    463:   oxprintf("#MH_coeff_max=%lg\n",MH_coeff_max);
1.26      takayama  464:   oxprintf("#MH_estimated_start_step=%lg\n",MH_estimated_start_step);
1.27    ! takayama  465:   oxprintf("%%ef_type=%d\n",MH_Ef_type);
1.26      takayama  466: #ifdef C_2F1
                    467:   oxprintf("%%q_pFq=%d, ",MH_P_pFq);
                    468:   for (i=0; i<MH_P_pFq; i++) {
                    469:     if (i != MH_P_pFq-1) oxprintf(" %lg,",MH_A_pFq[i]);
                    470:     else oxprintf(" %lg\n",MH_A_pFq[i]);
                    471:   }
                    472:   oxprintf("%%q_pFq=%d, ",MH_Q_pFq);
                    473:   for (i=0; i<MH_Q_pFq; i++) {
                    474:     if (i != MH_Q_pFq-1) oxprintf(" %lg,",MH_B_pFq[i]);
                    475:     else oxprintf(" %lg\n",MH_B_pFq[i]);
                    476:   }
                    477: #endif
                    478:   return(0);
1.1       takayama  479: }
                    480:
1.20      takayama  481: static double estimateHg(int m, double beta[],double x0) {
                    482:   int i,j;
                    483:   double dmin;
                    484:   double cmax;
                    485:   double h;
                    486:   /* mynote on 2014.03.15 */
                    487:   if (m>1) dmin = myabs(beta[1]-beta[0]);
                    488:   else dmin=myabs(beta[0]);
                    489:   for (i=0; i<m; i++) {
                    490:     for (j=i+1; j<m; j++) {
                    491:       if (myabs(beta[i]-beta[j]) < dmin) dmin = myabs(beta[i]-beta[j]);
                    492:     }
                    493:   }
                    494:   dmin = dmin*x0*2;
                    495:   cmax = 1.0;
                    496:   for (i=0; i<m; i++) cmax = cmax*dmin;
                    497:   cmax = 1.0/cmax;
                    498:   MH_coeff_max=cmax;
                    499:   h = exp(log(MH_abserr/cmax)/5.0);
                    500:   MH_estimated_start_step = h;
                    501:   return h;
                    502: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>