--- imach/src/imach.c 2024/05/12 20:29:32 1.361 +++ imach/src/imach.c 2024/07/02 09:42:10 1.366 @@ -1,6 +1,23 @@ -/* $Id: imach.c,v 1.361 2024/05/12 20:29:32 brouard Exp $ +/* $Id: imach.c,v 1.366 2024/07/02 09:42:10 brouard Exp $ $State: Exp $ $Log: imach.c,v $ + Revision 1.366 2024/07/02 09:42:10 brouard + Summary: trying clang on Linux + + Revision 1.365 2024/06/28 13:53:38 brouard + * imach.c (Module): fixing some bugs in gnuplot and quantitative variables, but not completely solved + + Revision 1.364 2024/06/28 12:27:05 brouard + * imach.c (Module): fixing some bugs in gnuplot and quantitative variables, but not completely solved + + Revision 1.363 2024/06/28 09:31:55 brouard + Summary: Adding log lines too + + Revision 1.362 2024/06/28 08:00:31 brouard + Summary: 0.99s6 + + * imach.c (Module): s6 errors with age*age (harmless). + Revision 1.361 2024/05/12 20:29:32 brouard Summary: Version 0.99s5 @@ -1240,7 +1257,7 @@ Important routines - Tricode which tests the modality of dummy variables (in order to warn with wrong or empty modalities) and returns the number of efficient covariates cptcoveff and modalities nbcode[Tvar[k]][1]= 0 and nbcode[Tvar[k]][2]= 1 usually. - printinghtml which outputs results like life expectancy in and from a state for a combination of modalities of dummy variables - o There are 2**cptcoveff combinations of (0,1) for cptcoveff variables. Outputting only combinations with people, eĢliminating 1 1 if + o There are 2**cptcoveff combinations of (0,1) for cptcoveff variables. Outputting only combinations with people, eliminating 1 1 if race White (0 0), Black vs White (1 0), Hispanic (0 1) and 1 1 being meaningless. @@ -1405,12 +1422,12 @@ double gnuplotversion=GNUPLOTVERSION; #define ODIRSEPARATOR '\\' #endif -/* $Id: imach.c,v 1.361 2024/05/12 20:29:32 brouard Exp $ */ +/* $Id: imach.c,v 1.366 2024/07/02 09:42:10 brouard Exp $ */ /* $State: Exp $ */ #include "version.h" char version[]=__IMACH_VERSION__; char copyright[]="April 2024,INED-EUROREVES-Institut de longevite-Japan Society for the Promotion of Science (Grant-in-Aid for Scientific Research 25293121), Intel Software 2015-2020, Nihon University 2021-202, INED 2000-2024"; -char fullversion[]="$Revision: 1.361 $ $Date: 2024/05/12 20:29:32 $"; +char fullversion[]="$Revision: 1.366 $ $Date: 2024/07/02 09:42:10 $"; char strstart[80]; char optionfilext[10], optionfilefiname[FILENAMELENGTH]; int erreur=0, nberr=0, nbwarn=0; /* Error number, number of errors number of warnings */ @@ -1469,7 +1486,8 @@ int countcallfunc=0; /* Count the numbe int selected(int kvar); /* Is covariate kvar selected for printing results */ double jmean=1; /* Mean space between 2 waves */ -double **matprod2(); /* test */ +double **matprod2(double **out, double **in,int nrl, int nrh, int ncl, int nch, int ncolol, int ncoloh, double **b); /* test */ +/* double **matprod2(); *//* test */ double **oldm, **newm, **savm; /* Working pointers to matrices */ double **oldms, **newms, **savms; /* Fixed working pointers to matrices */ double **ddnewms, **ddoldms, **ddsavms; /* for freeing later */ @@ -1516,14 +1534,16 @@ char optionfilegnuplot[FILENAMELENGTH], /* struct timeval start_time, end_time, curr_time, last_time, forecast_time; */ /* struct timezone tzp; */ /* extern int gettimeofday(); */ -struct tm tml, *gmtime(), *localtime(); -extern time_t time(); +/* extern time_t time(); */ /* Commented out for clang */ +/* struct tm tml, *gmtime(), *localtime(); */ + struct tm start_time, end_time, curr_time, last_time, forecast_time; time_t rstart_time, rend_time, rcurr_time, rlast_time, rforecast_time; /* raw time */ time_t rlast_btime; /* raw time */ -struct tm tm; +/* struct tm tm; */ +struct tm tm, tml; char strcurr[80], strfor[80]; @@ -1531,6 +1551,12 @@ char *endptr; long lval; double dval; +/* This for praxis gegen */ + /* int prin=1; */ + double h0=0.25; + double macheps; + double ffmin; + #define NR_END 1 #define FREE_ARG char* #define FTOL 1.0e-10 @@ -1981,9 +2007,7 @@ int nboccstr(char *textin, char *chain) /* in="+V7*V4+age*V2+age*V3+age*V4" chain="age" */ char *strloc; - int i,j=0; - - i=0; + int j=0; strloc=textin; /* strloc points to "^+V7*V4+age+..." in textin */ for(;;) { @@ -2117,14 +2141,15 @@ int **imatrix(long nrl, long nrh, long n } /****************** free_imatrix *************************/ -void free_imatrix(m,nrl,nrh,ncl,nch) - int **m; - long nch,ncl,nrh,nrl; - /* free an int matrix allocated by imatrix() */ -{ - free((FREE_ARG) (m[nrl]+ncl-NR_END)); - free((FREE_ARG) (m+nrl-NR_END)); -} +/* void free_imatrix(m,nrl,nrh,ncl,nch); */ +/* int **m; */ +/* long nch,ncl,nrh,nrl; */ +void free_imatrix(int **m,long nrl, long nrh, long ncl, long nch) + /* free an int matrix allocated by imatrix() */ +{ + free((FREE_ARG) (m[nrl]+ncl-NR_END)); + free((FREE_ARG) (m+nrl-NR_END)); +} /******************* matrix *******************************/ double **matrix(long nrl, long nrh, long ncl, long nch) @@ -2384,8 +2409,8 @@ values at the three points, fa, fb , and double ulim,u,r,q, dum; double fu; - double scale=10.; - int iterscale=0; + /* double scale=10.; */ + /* int iterscale=0; */ *fa=(*func)(*ax); /* xta[j]=pcom[j]+(*ax)*xicom[j]; fa=f(xta[j])*/ *fb=(*func)(*bx); /* xtb[j]=pcom[j]+(*bx)*xicom[j]; fb=f(xtb[j]) */ @@ -2775,7 +2800,8 @@ double *e; /* used in minfit, don't konw static int prin; /* added */ static int n; static double *x; -static double (*fun)(); +static double (*fun)(double *x); /* New for clang */ +/* static double (*fun)(); */ /* static double (*fun)(double *x, int n); */ /* these will be set by praxis to the global control parameters */ @@ -3000,31 +3026,38 @@ static void print() /* print a line of /* static void print2(int n, double *x, int prin, double fx, int nf, int nl) */ /* print a line of traces */ static void print2() /* print a line of traces */ { - int i; double fmin=0.; + int i; /* double fmin=0.; */ /* printf("\n"); */ /* printf("... chi square reduced to ... %20.10e\n", fx); */ /* printf("... after %u function calls ...\n", nf); */ /* printf("... including %u linear searches ...\n", nl); */ /* printf("%10d %10d%14.7g",nl, nf, fx); */ - printf ( "\n" ); + /* printf ( "\n" ); */ printf ( " Linear searches %d", nl ); + fprintf (ficlog, " Linear searches %d", nl ); /* printf ( " Linear searches %d\n", nl ); */ /* printf ( " Function evaluations %d\n", nf ); */ /* printf ( " Function value FX = %g\n", fx ); */ printf ( " Function evaluations %d", nf ); printf ( " Function value FX = %.12lf\n", fx ); + fprintf (ficlog, " Function evaluations %d", nf ); + fprintf (ficlog, " Function value FX = %.12lf\n", fx ); #ifdef DEBUGPRAX printf("n=%d prin=%d\n",n,prin); #endif - if(fx <= fmin) printf(" UNDEFINED "); else printf("%14.7g",log(fx-fmin)); + /* if(fx <= fmin) printf(" UNDEFINED "); else printf("%14.7g",log(fx-fmin)); */ if ( n <= 4 || 2 < prin ) { /* for(i=1;i<=n;i++)printf("%14.7g",x[i-1]); */ - for(i=1;i<=n;i++)printf("%14.7g",x[i]); + for(i=1;i<=n;i++){ + printf(" %14.7g",x[i]); + fprintf(ficlog," %14.7g",x[i]); + } /* r8vec_print ( n, x, " X:" ); */ } printf("\n"); + fprintf(ficlog,"\n"); } @@ -3231,7 +3264,7 @@ L1: /* L1 or try loop */ if (k > 0) *d2 = 0; } #ifdef DEBUGPRAX - printf(" bebe end of min x1=%14.8e fx=%14.8e d2=%14.8e\n",*x1, fx, *d2); + printf(" bebe end of min x1 might be very wrong x1=%14.8e fx=%14.8e d2=%14.8e\n",*x1, fx, *d2); #endif if (*d2 <= small_windows) *d2 = small_windows; *x1 = x2; fx = fm; @@ -3707,7 +3740,7 @@ mloop: printf("praxis4 macheps=%14g h=%14g step=%14g small=%14g t=%14g\n",macheps,h, h0,small_windows, t); #endif /* min(0, 2, &d[0], &s, fx, 0); /\* mac heps not global *\/ */ - minny(1, 2, &d[1], &s, fx, 0); /* mac heps not global */ + minny(1, 2, &d[1], &s, fx, 0); /* mac heps not global it seems that fx doesn't correspond to f(s=*x1) */ #ifdef DEBUGPRAX printf("praxis5 macheps=%14g h=%14g looks at sign of s=%14g fx=%14g\n",macheps,h, s,fx); #endif @@ -3772,7 +3805,7 @@ next: #ifdef NR_SHIFT fx = (*fun)((x-1), n); #else - fx = (*fun)(x, n); + fx = (*fun)(x); #endif /* fx = (*func) ( (x-1) ); *//* This for func which is computed from x[1] and not from x[0] xm1=(x-1)*/ nf++; @@ -4218,7 +4251,7 @@ void powell(double p[], double **xi, int printf(" + age*age "); fprintf(ficlog," + age*age "); } - for(j=1;j <=ncovmodel-2;j++){ + for(j=1;j <=ncovmodel-2-nagesqr;j++){ if(Typevar[j]==0) { printf(" + V%d ",Tvar[j]); fprintf(ficlog," + V%d ",Tvar[j]); @@ -4566,8 +4599,10 @@ void powell(double p[], double **xi, int int i, ii,j,k, k1; double *min, *max, *meandiff, maxmax,sumnew=0.; - /* double **matprod2(); */ /* test */ - double **out, cov[NCOVMAX+1], **pmij(); /* **pmmij is a global variable feeded with oldms etc */ + double **matprod2(double **out, double **in,int nrl, int nrh, int ncl, int nch, int ncolol, int ncoloh, double **b); /* test */ /* for clang */ +/* double **matprod2(); */ /* test */ + /* double **out, cov[NCOVMAX+1], **pmij(); */ /* **pmmij is a global variable feeded with oldms etc */ + double **out, cov[NCOVMAX+1], **pmij(double **ps, double *cov, int ncovmodel, double *x, int nlstate); /* **pmmij is a global variable feeded with oldms etc */ double **newm; double agefin, delaymax=200. ; /* 100 Max number of years to converge */ int ncvloop=0; @@ -4773,7 +4808,8 @@ void powell(double p[], double **xi, int int first=0; double *min, *max, *meandiff, maxmax,sumnew=0.; /* double **matprod2(); */ /* test */ - double **out, cov[NCOVMAX+1], **bmij(); + double **out, cov[NCOVMAX+1], **bmij(double **ps, double *cov, int ncovmodel, double *x, int nlstate, double ***prevacurrent, int ij); + /* double **out, cov[NCOVMAX+1], **bmij(); */ /* Deprecated in clang */ double **newm; double **dnewm, **doldm, **dsavm; /* for use */ double **oldm, **savm; /* for use */ @@ -5038,7 +5074,8 @@ double **pmij(double **ps, double *cov, */ int ii, j; - double **pmij(); + double **pmij(double **ps, double *cov, int ncovmodel, double *x, int nlstate); + /* double **pmij(); */ /* No more for clang */ double sumnew=0.; double agefin; double k3=0.; /* constant of the w_x diagonal matrix (in order for B to sum to 1 even for death state) */ @@ -5433,7 +5470,8 @@ double ***hbxij(double ***po, int nhstep */ int i, j, d, h, k1; - double **out, cov[NCOVMAX+1], **bmij(); + double **out, cov[NCOVMAX+1], **bmij(double **ps, double *cov, int ncovmodel, double *x, int nlstate, double ***prevacurrent, int ij); + /* double **out, cov[NCOVMAX+1], **bmij(); */ /* No more for clang */ double **newm, ***newmm; double agexact; /*double agebegin, ageend;*/ @@ -6593,10 +6631,10 @@ void mlikeli(FILE *ficres,double p[], in #else /* FLATSUP */ /* powell(p,xi,npar,ftol,&iter,&fret,func);*/ /* praxis ( t0, h0, n, prin, x, beale_f ); */ - int prin=1; - double h0=0.25; - double macheps; - double fmin; + int prin=4; + /* double h0=0.25; */ + /* double macheps; */ + /* double fmin; */ macheps=pow(16.0,-13.0); /* #include "praxis.h" */ /* Be careful that praxis start at x[0] and powell start at p[1] */ @@ -6606,7 +6644,7 @@ printf("Praxis Gegenfurtner \n"); fprintf(ficlog, "Praxis Gegenfurtner\n");fflush(ficlog); /* praxis ( ftol, h0, npar, prin, p1, func ); */ /* fmin = praxis(1.e-5,macheps, h, n, prin, x, func); */ - fmin = praxis(ftol,macheps, h0, npar, prin, p, func); + ffmin = praxis(ftol,macheps, h0, npar, prin, p, func); printf("End Praxis\n"); #endif /* FLATSUP */ @@ -8602,7 +8640,7 @@ void concatwav(int wav[], int **dh, int double ***gradg, ***trgradg; /**< for var eij */ double **gradgp, **trgradgp; /**< for var p point j */ double *gpp, *gmp; /**< for var p point j */ - double **varppt; /**< for var e.. nlstate+1 to nlstate+ndeath */ + double **varppt; /**< for var p.3 p.death nlstate+1 to nlstate+ndeath */ double ***p3mat; double age,agelim, hf; /* double ***mobaverage; */ @@ -9969,7 +10007,9 @@ void printinggnuplot(char fileresu[], ch char dirfileres[256],optfileres[256]; char gplotcondition[256], gplotlabel[256]; int cpt=0,k1=0,i=0,k=0,j=0,jk=0,k2=0,k3=0,k4=0,kf=0,kvar=0,kk=0,ipos=0,iposold=0,ij=0, ijp=0, l=0; - int lv=0, vlv=0, kl=0; + /* int lv=0, vlv=0, kl=0; */ + int lv=0, kl=0; + double vlv=0; int ng=0; int vpopbased; int ioffset; /* variable offset for columns */ @@ -10767,8 +10807,9 @@ set ter svg size 640, 480\nunset log y\n /* vlv= nbcode[Tvaraff[k]][lv]; /\* Value of the modality of Tvaraff[k] *\/ */ /* vlv= nbcode[Tvaraff[k]][codtabm(k1,TnsdVar[Tvaraff[k]])]; */ kl++; + /* Problem with quantitative variables TinvDoQresult[nres] */ /* sprintf(gplotcondition+strlen(gplotcondition),"$%d==%d && $%d==%d " ,kl,Tvaraff[k], kl+1, nbcode[Tvaraff[k]][lv]); */ - sprintf(gplotcondition+strlen(gplotcondition),"$%d==%d && $%d==%d " ,kl,lv, kl+1, vlv ); + sprintf(gplotcondition+strlen(gplotcondition),"$%d==%d && $%d==%lg " ,kl,lv, kl+1, vlv );/* Solved but quantitative must be shifted */ kl++; if(k 1) sprintf(gplotcondition+strlen(gplotcondition)," && "); @@ -10782,7 +10823,9 @@ set ter svg size 640, 480\nunset log y\n fprintf(ficgp,"%s ? $%d/(1.-$%d) : 1/0):%d t 'p.%d' with line lc variable", gplotcondition, \ ioffset+(cpt-1)*(nlstate+1)+1+(i-1), ioffset+1+(i-1)+(nlstate+1)*nlstate,iyearc, cpt ); fprintf(ficgp,",\\\n '' "); - fprintf(ficgp," u %d:(",iagec); + fprintf(ficgp," u %d:(",iagec); /* Below iyearc should be increades if quantitative variable in the reult line */ + /* $7==6 && $8==2.47 ) && (($9-$10) == 1953 ) ? $12/(1.-$24) : 1/0):7 with labels center not */ + /* but was && $7==6 && $8==2 ) && (($7-$8) == 1953 ) ? $12/(1.-$24) : 1/0):7 with labels center not */ fprintf(ficgp,"%s && (($%d-$%d) == %d ) ? $%d/(1.-$%d) : 1/0):%d with labels center not ", gplotcondition, \ iyearc, iagec, offyear, \ ioffset+(cpt-1)*(nlstate+1)+1+(i-1), ioffset+1+(i-1)+(nlstate+1)*nlstate, iyearc ); @@ -12283,7 +12326,8 @@ double gompertz(double x[]) A=-x[1]/(x[2])*(exp(x[2]*(agecens[i]-agegomp))-exp(x[2]*(ageexmed[i]-agegomp))); } else if (cens[i] == 0){ A=-x[1]/(x[2])*(exp(x[2]*(agedc[i]-agegomp))-exp(x[2]*(ageexmed[i]-agegomp))) - +log(x[1]/YEARM) +x[2]*(agedc[i]-agegomp)+log(YEARM); + +log(fabs(x[1])/YEARM) +x[2]*(agedc[i]-agegomp)+log(YEARM); + /* +log(x[1]/YEARM) +x[2]*(agedc[i]-agegomp)+log(YEARM); */ /* To be seen */ } else printf("Gompertz cens[%d] neither 1 nor 0\n",i); /*if (wav[i] > 1 && agecens[i] > 15) {*/ /* ??? */ @@ -15843,14 +15887,22 @@ Interval (in months) between two waves: flatdir=ivector(1,npar); for (j=1;j<=npar;j++) flatdir[j]=0; #endif /*LINMINORIGINAL */ - powell(p,ximort,NDIM,ftol,&iter,&fret,gompertz); -#endif + /* powell(p,ximort,NDIM,ftol,&iter,&fret,gompertz); */ + /* double h0=0.25; */ + macheps=pow(16.0,-13.0); + printf("Praxis Gegenfurtner mle=%d\n",mle); + fprintf(ficlog, "Praxis Gegenfurtner mle=%d\n", mle);fflush(ficlog); + /* ffmin = praxis(ftol,macheps, h0, npar, prin, p, gompertz); */ + /* For the Gompertz we use only two parameters */ + int _npar=2; + ffmin = praxis(ftol,macheps, h0, _npar, 4, p, gompertz); + printf("End Praxis\n"); fclose(ficrespow); #ifdef LINMINORIGINAL #else free_ivector(flatdir,1,npar); #endif /* LINMINORIGINAL*/ - +#endif /* POWELL */ hesscov(matcov, hess, p, NDIM, delti, 1e-4, gompertz); for(i=1; i <=NDIM; i++) @@ -15984,7 +16036,7 @@ Please run with mle=-1 to get a correct fprintf(ficlog," + age*age "); fprintf(fichtm, "+ age*age"); } - for(j=1;j <=ncovmodel-2;j++){ + for(j=1;j <=ncovmodel-2-nagesqr;j++){ if(Typevar[j]==0) { printf(" + V%d ",Tvar[j]); fprintf(ficres," + V%d ",Tvar[j]); @@ -16055,7 +16107,7 @@ Please run with mle=-1 to get a correct fprintf(ficlog," + age*age "); fprintf(fichtm, "+ age*age"); } - for(j=1;j <=ncovmodel-2;j++){ + for(j=1;j <=ncovmodel-2-nagesqr;j++){ if(Typevar[j]==0) { printf(" + V%d ",Tvar[j]); fprintf(fichtm, "+ V%d",Tvar[j]);