From: N. Brouard Date: Fri, 22 Jul 2016 17:45:30 +0000 (+0000) Subject: Summary: Fixing some arrays, still debugging X-Git-Tag: imach-099s7~277 X-Git-Url: https://henry.ined.fr/git/?a=commitdiff_plain;h=449963ba2406e53cb1b8f6b929ab7f34736a9de8;p=.git Summary: Fixing some arrays, still debugging --- diff --git a/src/imach.c b/src/imach.c index e3b7944..77f9f7c 100644 --- a/src/imach.c +++ b/src/imach.c @@ -1058,7 +1058,9 @@ int *Fixed; /** Fixed[k] 0=fixed, 1 varying, 2 fixed with age product, 3 varying int *Dummy; /** Dummy[k] 0=dummy (0 1), 1 quantitative (single or product without age), 2 dummy with age product, 3 quant with age product */ int *Tage; int anyvaryingduminmodel=0; /**< Any varying dummy in Model=1 yes, 0 no, to avoid a loop on waves in freq */ -int *Tmodelind; /** Tmodelind[Tvaraff[3]]=9,Tvaraff[1]@9={4, 3, 1, 0, 0, 0, 0, 0, 0}, model=V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1*/ +int *Tmodelind; /** Tmodelind[Tvaraff[3]]=9 for V1 position,Tvaraff[1]@9={4, 3, 1, 0, 0, 0, 0, 0, 0}, model=V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1*/ +int *TmodelInvind; /** Tmodelind[Tvaraff[3]]=9 for V1 position,Tvaraff[1]@9={4, 3, 1, 0, 0, 0, 0, 0, 0}, model=V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1*/ +int *TmodelInvQind; /** Tmodelqind[1]=1 for V5(quantitative varying) position,Tvaraff[1]@9={4, 3, 1, 0, 0, 0, 0, 0, 0}, model=V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1*/ int *Ndum; /** Freq of modality (tricode */ /* int **codtab;*/ /**< codtab=imatrix(1,100,1,10); */ int **Tvard; @@ -2943,10 +2945,9 @@ double func( double *x) int ioffset=0; double l, ll[NLSTATEMAX+1], cov[NCOVMAX+1]; double **out; - double sw; /* Sum of weights */ double lli; /* Individual log likelihood */ int s1, s2; - int iv=0, iqv=0, itv=0, iqtv=0 ; /* Index of varying covariate, fixed quantitative cov, time varying covariate, quatitative time varying covariate */ + int iv=0, iqv=0, itv=0, iqtv=0 ; /* Index of varying covariate, fixed quantitative cov, time varying covariate, quantitative time varying covariate */ double bbh, survp; long ipmx; double agexact; @@ -2976,7 +2977,7 @@ double func( double *x) cov[++ioffset]=covar[Tvar[k]][i]; } for(iqv=1; iqv <= nqfveff; iqv++){ /* Quantitatives and Fixed covariates */ - cov[++ioffset]=coqvar[iqv][i]; + cov[++ioffset]=coqvar[Tvar[iqv]][i]; } /* In model V2+V1*V4+age*V3+V3*V2 Tvar[1] is V2, Tvar[2=V1*V4] @@ -2993,7 +2994,7 @@ double func( double *x) */ for(mi=1; mi<= wav[i]-1; mi++){ for(itv=1; itv <= ntveff; itv++){ /* Varying dummy covariates */ - cov[ioffset+itv]=cotvar[mw[mi][i]][itv][i]; + cov[ioffset+itv]=cotvar[mw[mi][i]][Tvar[itv]][i]; /* Not sure, Tvar V4+V3+V5 Tvaraff ? */ } for(iqtv=1; iqtv <= nqtveff; iqtv++){ /* Varying quantitatives covariates */ if(cotqvar[mw[mi][i]][iqtv][i] == -1){ @@ -3272,15 +3273,16 @@ double func( double *x) /*************** log-likelihood *************/ double funcone( double *x) { - /* Same as likeli but slower because of a lot of printf and if */ + /* Same as func but slower because of a lot of printf and if */ int i, ii, j, k, mi, d, kk; - int ioffset=0; + int ioffset=0; double l, ll[NLSTATEMAX+1], cov[NCOVMAX+1]; double **out; double lli; /* Individual log likelihood */ double llt; int s1, s2; - int iv=0, iqv=0, itv=0, iqtv=0 ; /* Index of varying covariate, fixed quantitative cov, time varying covariate */ + int iv=0, iqv=0, itv=0, iqtv=0 ; /* Index of varying covariate, fixed quantitative cov, time varying covariate, quantitative time varying covariate */ + double bbh, survp; double agexact; double agebegin, ageend; @@ -3306,10 +3308,16 @@ double funcone( double *x) for(mi=1; mi<= wav[i]-1; mi++){ /* Varying with waves */ for(itv=1; itv <= ntveff; itv++){ /* Varying dummy covariates */ - cov[ioffset+itv]=cotvar[mw[mi][i]][itv][i]; + /* iv= Tvar[Tmodelind[ioffset-2-nagesqr-cptcovage+itv]]-ncovcol-nqv; /\* Counting the # varying covariate from 1 to ntveff *\/ */ + /* cov[ioffset+iv]=cotvar[mw[mi][i]][iv][i]; */ + k=ioffset-2-nagesqr-cptcovage+itv; /* position in simple model */ + cov[ioffset+itv]=cotvar[mw[mi][i]][TmodelInvind[itv]][i]; + printf(" i=%d,mi=%d,itv=%d,TmodelInvind[itv]=%d,cotvar[mw[mi][i]][TmodelInvind[itv]][i]=%f\n", i, mi, itv, TmodelInvind[itv],cotvar[mw[mi][i]][TmodelInvind[itv]][i]); } for(iqtv=1; iqtv <= nqtveff; iqtv++){ /* Varying quantitatives covariates */ - cov[ioffset+ntveff+iqtv]=cotqvar[mw[mi][i]][iqtv][i]; + iv=TmodelInvQind[iqtv]; /* Counting the # varying covariate from 1 to ntveff */ + printf(" i=%d,mi=%d,iqtv=%d,TmodelInvQind[iqtv]=%d,cotqvar[mw[mi][i]][TmodelInvQind[iqtv]][i]=%f\n", i, mi, iqtv, TmodelInvQind[iqtv],cotqvar[mw[mi][i]][TmodelInvQind[iqtv]][i]); + cov[ioffset+ntveff+iqtv]=cotqvar[mw[mi][i]][TmodelInvQind[iqtv]][i]; } for (ii=1;ii<=nlstate+ndeath;ii++) for (j=1;j<=nlstate+ndeath;j++){ @@ -4710,6 +4718,7 @@ void concatwav(int wav[], int **dh, int **bh, int **mw, int **s, double *agedc ++ij; Tvaraff[ij]=Tvar[k]; /*For printing */ Tmodelind[ij]=k; + TmodelInvind[k]=Tvar[k]- ncovcol-nqv; if(Fixed[k]!=0) anyvaryingduminmodel=1; /* }else if((Ndum[i]!=0) && (i<=ncovcol+nqv)){ */ @@ -4729,6 +4738,9 @@ void concatwav(int wav[], int **dh, int **bh, int **mw, int **s, double *agedc Tvaraff[j]=0; Tmodelind[j]=0; } + for(j=ntveff+1; j<= cptcovt; j++){ + TmodelInvind[j]=0; + } /* To be sorted */ ; } @@ -8003,10 +8015,15 @@ Dummy[k] 0=dummy (0 1), 1 quantitative (single or product without age), 2 dummy Fixed[k]= 1; Dummy[k]= 0; ntveff++; /* Only simple time varying dummy variable */ + printf("Quasi Tmodelind[%d]=%d,Tvar[Tmodelind[%d]]=V%d, ncovcol=%d, nqv=%d,Tvar[k]- ncovcol-nqv=%d\n",ntveff,k,ntveff,Tvar[k], ncovcol, nqv,Tvar[k]- ncovcol-nqv); + printf("Quasi TmodelInvind[%d]=%d\n",k,Tvar[k]- ncovcol-nqv); }else if( Tvar[k] <=ncovcol+nqv+ntv+nqtv && Typevar[k]==0){ Fixed[k]= 1; Dummy[k]= 1; - nqtveff++;/* Only simple time varying quantitative variable */ + TmodelInvQind[++nqtveff]=Tvar[k]- ncovcol-nqv-ntv;/* Only simple time varying quantitative variable */ + /* Tmodeliqind[k]=nqtveff;/\* Only simple time varying quantitative variable *\/ */ + printf("Quasi TmodelQind[%d]=%d,Tvar[TmodelQind[%d]]=V%d, ncovcol=%d, nqv=%d, ntv=%d,Tvar[k]- ncovcol-nqv-ntv=%d\n",nqtveff,k,nqtveff,Tvar[k], ncovcol, nqv, ntv, Tvar[k]- ncovcol-nqv-ntv); + printf("Quasi TmodelInvQind[%d]=%d\n",k,Tvar[k]- ncovcol-nqv-ntv); }else if (Typevar[k] == 1) { /* product with age */ if (Tvar[k] <=ncovcol ){ /* Simple or product fixed dummy covariatee */ Fixed[k]= 2; @@ -9387,6 +9404,12 @@ Please run with mle=-1 to get a correct covariance matrix.\n",optionfile,numline * Tmodelind[Tvaraff[3]]=9,Tvaraff[1]@9={4, * 3, 1, 0, 0, 0, 0, 0, 0}, * model=V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1*/ + TmodelInvind=ivector(1,NCOVMAX); + TmodelInvQind=ivector(1,NCOVMAX);/** five the k model position of an + * individual quantitative, fixed or varying: + * Tmodelqind[1]=1,Tvaraff[1]@9={4, + * 3, 1, 0, 0, 0, 0, 0, 0}, + * model=V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1*/ /* Main decodemodel */ @@ -10537,6 +10560,8 @@ Please run with mle=-1 to get a correct covariance matrix.\n",ageminpar,agemaxpa free_ivector(invalidvarcomb,1,ncovcombmax); free_ivector(Tage,1,NCOVMAX); free_ivector(Tmodelind,1,NCOVMAX); + free_ivector(TmodelInvind,1,NCOVMAX); + free_ivector(TmodelInvQind,1,NCOVMAX); free_imatrix(nbcode,0,NCOVMAX,0,NCOVMAX); /* free_imatrix(codtab,1,100,1,10); */