doit(){ stats(); if (oldtop) { int i,j,bn=0,bnest=0; double P,R,F,estP,estR,estF,bF=0,bestF=0, bFest=0; for (i=1;i<=n;i++) { P = Rels[i]/i; R = Rels[i]/Rels[n]; F = 2/(1/P+1/R); estP = Estrel[i]/i; estR = Estrel[i]/Estrel[n]; estF = 2/(1/estP+1/estR); if (F > bF) { bF = F; bn = i; } if (estF > bestF) { bestF = estF; bFest = F; bnest = i; } } printf("%d Rel %0.0lf estRel %0.0lf acc %0.1lf%% possible F1 %0.1lf%% estimated %0.1lf%% actual F1 %0.1lf%% Ferr %0.1lf%% %d %d %0.1lf%% AUC %0.1lf%%\n", oldtop,Rels[n],Estrel[n],errcalc(Rels[n],Estrel[n]),100*bF,100*bestF,100*bFest,errcalc(bestF,bFest),bn,bnest,errcalc(bn,bnest), 100*auc/(Rels[n]*Nrels[n])); } bestF = 0; estrel = 0; n = 0; oldtop = top; memset(Rel,0,sizeof(Rel)); auc = 0; }
double errcalc(double a, double b) { if (b > a) return errcalc(b,a); return 100 - 100 * (a - b)/a; }
int mrqmin(float **y, float **sig, struct image *psf, int ma, double **covar, double **alpha, double *chisq, void (*funcs)(int, int, float *, float [], int [], int, struct fitpars *), float *alamda, struct fitpars *fpar, struct cons *constr, struct convpars *cpar, double *sigma) { void errcalc (double *sigma, double **alpha, int ma, int *ia, int mfit); int j,k,l; static int mfit; static double *da,**oneda,*beta,ochisq; static float *atry, *aorig; float *a; int *ia; /* Kludge -- copy from fpar->a to a */ a = vector (1, ma); ia = ivector (1, ma); copy_pars (a, ia, fpar, FROM); if (*alamda < 0.0) { aorig=vector(1,ma); copy_pars (aorig, ia, fpar, FROM); atry=vector(1,ma); beta=dvector(1,ma); da=dvector(1,ma); for (mfit=0,j=1;j<=ma;j++) if (ia[j]==1) mfit++; oneda=dmatrix(1,mfit,1,1); *alamda=0.01; mrqcof(y,sig,psf,a,ia,ma,alpha,beta,chisq,funcs,fpar,cpar); ochisq=(*chisq); for (j=1;j<=ma;j++) atry[j]=a[j]; } for (j=1;j<=mfit;j++) { for (k=1;k<=mfit;k++) covar[j][k]=alpha[j][k]; covar[j][j]=alpha[j][j]*(1.0+(*alamda)); oneda[j][1]=beta[j]; } gaussj(covar,mfit,oneda,1); for (j=1;j<=mfit;j++) da[j]=oneda[j][1]; if (*alamda == 0.0) { /* Convergence! */ errcalc (sigma, alpha, ma, ia, mfit); /* calculate uncert. */ covsrt(covar,ma,ia,mfit); covsrt(alpha,ma,ia,mfit); free_dmatrix(oneda,1,mfit,1,1); free_dvector(da,1,ma); free_dvector(beta,1,ma); free_vector(atry,1,ma); free_vector (a, 1, ma); free_ivector (ia, 1, ma); return; } par_monitor (ma, a, ia, atry, da, fpar); constraints (ma, mfit, atry, a, ia, constr, da, aorig); copy_pars (atry, ia, fpar, TO); mrqcof(y,sig,psf,atry,ia,ma,covar,da,chisq,funcs,fpar,cpar); if (*chisq < ochisq) { *alamda *= 0.1; ochisq=(*chisq); for (j=1;j<=mfit;j++) { for (k=1;k<=mfit;k++) alpha[j][k]=covar[j][k]; beta[j]=da[j]; } for (l=1;l<=ma;l++) a[l]=atry[l]; } else { *alamda *= 10.0; *chisq=ochisq; } copy_pars (a, ia, fpar, TO); free_vector (a, 1, ma); free_ivector (ia, 1, ma); return (0); }