version 1.22, 2015/03/24 05:59:43 |
version 1.27, 2016/02/04 06:56:05 |
|
|
/* |
/* |
$OpenXM: OpenXM/src/hgm/mh/src/wmain.c,v 1.21 2014/03/20 10:58:37 takayama Exp $ |
$OpenXM: OpenXM/src/hgm/mh/src/wmain.c,v 1.26 2016/02/01 11:37:14 takayama Exp $ |
License: LGPL |
License: LGPL |
*/ |
*/ |
#include <stdio.h> |
#include <stdio.h> |
Line 14 int MH_deallocate=0; |
|
Line 14 int MH_deallocate=0; |
|
|
|
/* |
/* |
changelog |
changelog |
|
2016.02.04 MH_Ef_type exponential or scalar factor |
|
2016.02.01 C_2F1 |
2014.03.15 --strategy 1 is default. A new parser in setParam() |
2014.03.15 --strategy 1 is default. A new parser in setParam() |
*/ |
*/ |
extern char *MH_Gfname; |
extern char *MH_Gfname; |
Line 48 double MH_coeff_max; |
|
Line 50 double MH_coeff_max; |
|
Estimation of h by MH_coeff_max; |
Estimation of h by MH_coeff_max; |
*/ |
*/ |
double MH_estimated_start_step; |
double MH_estimated_start_step; |
|
|
|
#ifdef C_2F1 |
|
int MH_P_pFq=2; |
|
int MH_Q_pFq=1; |
|
double MH_A_pFq[2]; |
|
double MH_B_pFq[1]; |
|
int MH_Ef_type=2; |
|
#else |
|
int MH_P_pFq=1; |
|
int MH_Q_pFq=1; |
|
double MH_A_pFq[1]; |
|
double MH_B_pFq[1]; |
|
int MH_Ef_type=1; |
|
#endif |
extern int MH_Verbose; |
extern int MH_Verbose; |
extern int MH_strategy; |
extern int MH_strategy; |
extern double MH_abserr; |
extern double MH_abserr; |
Line 62 static int showParam(void); |
|
Line 78 static int showParam(void); |
|
static int next(struct SFILE *fp,char *s, char *msg); |
static int next(struct SFILE *fp,char *s, char *msg); |
static double estimateHg(int m, double beta[],double x0); |
static double estimateHg(int m, double beta[],double x0); |
|
|
|
#ifdef C_2F1 |
|
void mh_setabc(double a,double b,double c); |
|
#endif |
/* #define DEBUG */ |
/* #define DEBUG */ |
#ifdef DEBUG |
#ifdef DEBUG |
char *MH_Dfname; char *MH_Gfname; double MH_Hg; |
char *MH_Dfname; char *MH_Gfname; double MH_Hg; |
Line 85 static int mypower(int x,int n) { |
|
Line 104 static int mypower(int x,int n) { |
|
return(a); |
return(a); |
} |
} |
#ifdef STANDALONE2 |
#ifdef STANDALONE2 |
main(int argc,char *argv[]) { |
int main(int argc,char *argv[]) { |
int strategy=STRATEGY_DEFAULT; |
int strategy=STRATEGY_DEFAULT; |
double err[2]={-1.0,-1.0}; |
double err[2]={-1.0,-1.0}; |
int i; |
int i; |
Line 175 struct MH_RESULT *mh_main(int argc,char *argv[]) { |
|
Line 194 struct MH_RESULT *mh_main(int argc,char *argv[]) { |
|
if (MH_Verbose) showParam(); |
if (MH_Verbose) showParam(); |
if (MH_Verbose) {for (i=0; i<rank; i++) oxprintf("%lf\n",y0[i]); } |
if (MH_Verbose) {for (i=0; i<rank; i++) oxprintf("%lf\n",y0[i]); } |
|
|
|
#ifdef C_2F1 |
|
mh_setabc(MH_A_pFq[0],MH_A_pFq[1],MH_B_pFq[0]); |
|
#endif |
*rp=mh_rkmain(x0,y0,xn); |
*rp=mh_rkmain(x0,y0,xn); |
return(rp); |
return(rp); |
} |
} |
|
|
int mh_usage() { |
int mh_usage() { |
oxprintfe("Usages:\n"); |
oxprintfe("Usages:\n"); |
oxprintfe("hgm_w-n [--idata input_data_file --gnuplotf gnuplot_file_name\n"); |
#ifdef C_2F1 |
|
oxprintfe("hgm_w-n-2f1 "); |
|
#else |
|
oxprintfe("hgm_w-n "); |
|
#endif |
|
oxprintfe(" [--idata input_data_file --gnuplotf gnuplot_file_name\n"); |
oxprintfe(" --dataf output_data_file --raw --xmax xmax --test m --step h]\n"); |
oxprintfe(" --dataf output_data_file --raw --xmax xmax --test m --step h]\n"); |
oxprintfe("[ --95 --verbose] \n"); |
oxprintfe("[ --95 --verbose] \n"); |
oxprintfe("[ --strategy s --abserr ae --relerr re] \n"); |
oxprintfe("[ --strategy s --abserr ae --relerr re] \n"); |
Line 213 int mh_usage() { |
|
Line 240 int mh_usage() { |
|
oxprintfe(" gnuplot -persist <test-g-gp.txt\n"); |
oxprintfe(" gnuplot -persist <test-g-gp.txt\n"); |
oxprintfe(" tmp-idata3.txt is a sample input data distributed with this file.\n"); |
oxprintfe(" tmp-idata3.txt is a sample input data distributed with this file.\n"); |
oxprintfe(" test-g-gp.txt is an input file of the gnuplot\n"); |
oxprintfe(" test-g-gp.txt is an input file of the gnuplot\n"); |
oxprintfe(" test-g is the table of x and the values of Pr({y | y<x}).\n"); |
oxprintfe(" test-g is the table of x and the values of Pr({y | y<x}).\n"); return(0); |
} |
} |
|
|
static int setParamTest() { |
static int setParamTest() { |
Line 234 static int setParamTest() { |
|
Line 261 static int setParamTest() { |
|
MH_X0g = 0.3; |
MH_X0g = 0.3; |
MH_Hg = 0.001; |
MH_Hg = 0.001; |
MH_Dp = 1; |
MH_Dp = 1; |
Xng = 10.0; |
Xng = 10.0; return(0); |
} |
} |
static int setParamDefault() { |
static int setParamDefault() { |
int rank; |
int rank; |
Line 252 static int setParamDefault() { |
|
Line 279 static int setParamDefault() { |
|
MH_X0g = 0.3; |
MH_X0g = 0.3; |
MH_Hg = 0.001; |
MH_Hg = 0.001; |
MH_Dp = 1; |
MH_Dp = 1; |
Xng = 10.0; |
Xng = 10.0; return(0); |
} |
} |
|
|
static int next(struct SFILE *sfp,char *s,char *msg) { |
static int next(struct SFILE *sfp,char *s,char *msg) { |
Line 263 static int next(struct SFILE *sfp,char *s,char *msg) { |
|
Line 290 static int next(struct SFILE *sfp,char *s,char *msg) { |
|
mh_exit(-1); |
mh_exit(-1); |
} |
} |
if (s[0] != '%') return(0); |
if (s[0] != '%') return(0); |
} |
} return(0); |
} |
} |
static int setParam(char *fname) { |
static int setParam(char *fname) { |
int rank; |
int rank; |
Line 356 static int setParam(char *fname) { |
|
Line 383 static int setParam(char *fname) { |
|
MH_strategy = tk.ival; |
MH_strategy = tk.ival; |
continue; |
continue; |
} |
} |
oxprintfe("Unknown ID at %s\n",s); mh_exit(-1); |
// Format: #p_pFq=2 1.5 3.2 |
|
if (strcmp(s,"p_pFq")==0) { |
|
if (mh_getoken(s,SMAX-1,fp).type != MH_TOKEN_EQ) { |
|
oxprintfe("Syntax error at %s\n",s); mh_exit(-1); |
|
} |
|
if ((tk=mh_getoken(s,SMAX-1,fp)).type != MH_TOKEN_INT) { |
|
oxprintfe("Syntax error at %s\n",s); mh_exit(-1); |
|
} |
|
MH_P_pFq = tk.ival; |
|
for (i=0; i<MH_P_pFq; i++) { |
|
if ((tk=mh_getoken(s,SMAX-1,fp)).type == MH_TOKEN_DOUBLE) { |
|
MH_A_pFq[i] = tk.dval; |
|
}else if (tk.type == MH_TOKEN_INT) { |
|
MH_A_pFq[i] = tk.ival; |
|
}else{ |
|
oxprintfe("Syntax error at %s\n",s); mh_exit(-1); |
|
} |
|
} |
|
continue; |
|
} |
|
if (strcmp(s,"q_pFq")==0) { |
|
if (mh_getoken(s,SMAX-1,fp).type != MH_TOKEN_EQ) { |
|
oxprintfe("Syntax error at %s\n",s); mh_exit(-1); |
|
} |
|
if ((tk=mh_getoken(s,SMAX-1,fp)).type != MH_TOKEN_INT) { |
|
oxprintfe("Syntax error at %s\n",s); mh_exit(-1); |
|
} |
|
MH_Q_pFq = tk.ival; |
|
for (i=0; i<MH_Q_pFq; i++) { |
|
if ((tk=mh_getoken(s,SMAX-1,fp)).type == MH_TOKEN_DOUBLE) { |
|
MH_B_pFq[i] = tk.dval; |
|
}else if (tk.type == MH_TOKEN_INT) { |
|
MH_B_pFq[i] = tk.ival; |
|
}else{ |
|
oxprintfe("Syntax error at %s\n",s); mh_exit(-1); |
|
} |
|
} |
|
continue; |
|
} |
|
if (strcmp(s,"ef_type")==0) { |
|
if (mh_getoken(s,SMAX-1,fp).type != MH_TOKEN_EQ) { |
|
oxprintfe("Syntax error at %s\n",s); mh_exit(-1); |
|
} |
|
if ((tk=mh_getoken(s,SMAX-1,fp)).type != MH_TOKEN_INT) { |
|
oxprintfe("Syntax error at %s\n",s); mh_exit(-1); |
|
} |
|
MH_Ef_type = tk.ival; |
|
continue; |
|
} |
|
oxprintfe("Unknown ID for wmain.c (old...) at %s.\n",s); mh_exit(-1); |
} |
} |
|
|
mh_fclose(fp); |
mh_fclose(fp); return(0); |
} |
} |
|
|
static int showParam() { |
static int showParam() { |
Line 385 static int showParam() { |
|
Line 461 static int showParam() { |
|
oxprintf("%%abserr=%lg, %%relerr=%lg\n",MH_abserr,MH_relerr); |
oxprintf("%%abserr=%lg, %%relerr=%lg\n",MH_abserr,MH_relerr); |
oxprintf("#MH_success=%d\n",MH_success); |
oxprintf("#MH_success=%d\n",MH_success); |
oxprintf("#MH_coeff_max=%lg\n",MH_coeff_max); |
oxprintf("#MH_coeff_max=%lg\n",MH_coeff_max); |
oxprintf("#MH_estimated_start_step=%lg\n",MH_estimated_start_step); |
oxprintf("#MH_estimated_start_step=%lg\n",MH_estimated_start_step); |
|
oxprintf("%%ef_type=%d\n",MH_Ef_type); |
|
#ifdef C_2F1 |
|
oxprintf("%%q_pFq=%d, ",MH_P_pFq); |
|
for (i=0; i<MH_P_pFq; i++) { |
|
if (i != MH_P_pFq-1) oxprintf(" %lg,",MH_A_pFq[i]); |
|
else oxprintf(" %lg\n",MH_A_pFq[i]); |
|
} |
|
oxprintf("%%q_pFq=%d, ",MH_Q_pFq); |
|
for (i=0; i<MH_Q_pFq; i++) { |
|
if (i != MH_Q_pFq-1) oxprintf(" %lg,",MH_B_pFq[i]); |
|
else oxprintf(" %lg\n",MH_B_pFq[i]); |
|
} |
|
#endif |
|
return(0); |
} |
} |
|
|
static double estimateHg(int m, double beta[],double x0) { |
static double estimateHg(int m, double beta[],double x0) { |