uint* RetroDetector::Discrepancy( uchar*i0, uchar*i1, Change R, Change G, Change B, uint &max,uint &min ) { int size = sizeof(i0)/(sizeof(uchar) * PIXELSIZE); uint discreps[size]; // the array of float values representing discrepancies max = 0; // keep track of largest and smallest values min = 99999; for(int i = 0,ind=0; i < size; i++,ind += PIXELSIZE) { uint dR = discrep(i0[ind+RIND],i1[ind+RIND],R); uint dG = discrep(i0[ind+GIND],i1[ind+GIND],G); uint dB = discrep(i0[ind+BIND],i1[ind+BIND],B); uint res = dR*dG*dB+1; discreps[i] = res; if(res > max){max = res;} if(res < min){min = res;} } return NULL; // discreps; Remove "warning: address of local variable `discreps' returned" }
float* RetroDetector::Discrepancy( uchar*R0, uchar*G0, uchar*B0, uchar*R1, uchar*G1, uchar*B1, Change R, Change G, Change B, int channelsused, float &max,float &min ) { int size = sizeof(R0)/sizeof(uchar); float discreps[size]; // the array of float values representing discrepancies max = -99999; // keep track of largest and smallest values min = 99999; for(int i = 0; i < size; i++) { float dR = discrep(R0[i],R1[i],R,3); float dG = discrep(G0[i],G1[i],G,3); float dB = discrep(B0[i],B1[i],B,3); float res = pow(dR*dG*dB,1.0/channelsused); discreps[i] = res; if(res > max){max = res;} if(res < min){min = res;} } return discreps; }
int dnls1_general_driver(DNLS1_STORAGE * pStorage, void * pGeop, double * x, double * fit, double *st_err, double * max_diff, char * message) { int iw = 4, i, err = 0; double dummy_fit = 0.; if(!pGeop) return 0; if(!pStorage) return 0; if(pStorage->err) return -1; if(pStorage->iopt==-1) pStorage->iopt=1; if(pStorage->ftol==-1.) pStorage->ftol= sqrt(d1mach_(&iw)); if(pStorage->xtol==-1.) pStorage->xtol= sqrt(d1mach_(&iw)); if(pStorage->gtol==-1.) pStorage->gtol= 0.; if(pStorage->maxfev==-1) pStorage->maxfev= 40000; if(pStorage->epsfcn==-1) pStorage->epsfcn= 0.; if(pStorage->mode ==-1) pStorage->mode= 1; if(pStorage->factor==-1) pStorage->factor = 100; if(pStorage->nprint==-1) pStorage->nprint = 1; pStorage->ldfjac = pStorage->m; pStorage->n_iterations = 0; memcpy(pStorage->x, x, sizeof(double)*pStorage->n); FCN_PARAMS params; params.pData = pStorage; params.pFcnParams = pGeop; /* if(pStorage->iopt==1) { // forward differencing for jackobian int iflag=1; memset(pStorage->fjac, sizeof(double)*pStorage->n*pStorage->m, 0); (*pStorage->fcn)(&iflag, &pStorage->m, &pStorage->n, pStorage->x, // need to compute fvec pStorage->fvec, pStorage->fjac, &pStorage->ldfjac, (void *)¶ms); dfdjc3_(pStorage->fcn, &pStorage->m, &pStorage->n, pStorage->x, pStorage->fvec, pStorage->fjac, &pStorage->ldfjac, &iflag, &pStorage->epsfcn, pStorage->wa4, (void *)¶ms); fprintf(stderr,"%d %d %d\n", pStorage->m, pStorage->n, pStorage->ldfjac); } else { int iflag=2; int ldfjac = 1; (*pStorage->fcn)(&iflag, &pStorage->m, &pStorage->n, pStorage->x, pStorage->fvec, pStorage->fjac, &pStorage->ldfjac, (void *)¶ms); } fprintf(stderr,"pStorage->n=%d pStorage->m=%d\n", pStorage->n, pStorage->m); for(i=0; i<pStorage->m; i++) { fprintf(stdout,"%d " ,i); for(int j=0; j<pStorage->n; j++) fprintf(stdout,"%lg ", pStorage->fjac[pStorage->m*j+i]); fprintf(stdout,"\n"); } exit(0); */ /*fprintf(stderr,"Before---------------------\n"); fprintf(stderr,"pStorage->ldfjac=%d\n", pStorage->ldfjac); fprintf(stderr,"pStorage->ftol=%lg\n", pStorage->ftol); fprintf(stderr,"pStorage->xtol=%lg\n", pStorage->xtol); fprintf(stderr,"pStorage->gtol=%lg\n", pStorage->gtol); fprintf(stderr,"pStorage->maxfev=%d\n", pStorage->maxfev); fprintf(stderr,"pStorage->epsfcn=%lg\n", pStorage->epsfcn); fprintf(stderr,"pStorage->mode=%d\n", pStorage->mode); fprintf(stderr,"pStorage->factor=%lg\n", pStorage->factor); fprintf(stderr,"pStorage->nprint=%d\n", pStorage->nprint);*/ if(!pStorage->compute_only_stdev) { dnls1_(pStorage->fcn, &pStorage->iopt, &pStorage->m, &pStorage->n, pStorage->x, pStorage->fvec, pStorage->fjac, &pStorage->ldfjac, &pStorage->ftol, &pStorage->xtol, &pStorage->gtol, &pStorage->maxfev, &pStorage->epsfcn, pStorage->diag, &pStorage->mode, &pStorage->factor, &pStorage->nprint, &pStorage->info, &pStorage->nfev, &pStorage->njev, pStorage->ipvt, pStorage->qtf, pStorage->wa1, pStorage->wa2, pStorage->wa3, pStorage->wa4, (void *)¶ms); if(message) { switch(pStorage->info) { case 0: strcpy(message, "DNLS1: improper input parameters."); break; case 1: sprintf(message, "DNLS1: both actual and predicted relative reductions in the sum of squares are at most FTOL=%lg",pStorage->ftol); break; case 2: sprintf(message, "DNLS1: relative error between two consecutive iterates is at most XTOL=%lg",pStorage->xtol); break; case 3: sprintf(message, "DNLS1: both actual and predicted relative reductions in the sum of squares are at most FTOL=%lg and relative error between two consecutive iterates is at most XTOL=%lg", pStorage->ftol, pStorage->xtol); break; case 4: sprintf(message, "DNLS1: the cosine of the angle between FVEC and any column of the Jacobian is at most GTOL=%lg in absolute value.",pStorage->gtol); break; case 5: strcpy(message, "DNLS1: number of calls to FCN for function evaluation has reached its limit or executaion has been cancelled"); break; case 6: sprintf(message, "DNLS1: FTOL=%lg is too small. No further reduction in the sum of squares is possible.", pStorage->ftol); break; case 7: sprintf(message, "DNLS1: XTOL=%lg is too small. No further improvement in the approximate solution X is possible",pStorage->xtol); break; case 8: sprintf(message, "DNLS1: GTOL=%lg is too small. FVEC is orthogonal to the columns of the Jacobian to machine precision.", pStorage->xtol); break; default: strcpy(message, "DNLS1: No information is available."); } } *fit = discrep(pStorage->fvec,pStorage->m, pStorage->n); // find max. difference *max_diff = fabs(pStorage->fvec[0]); double am; for(i=0; i<pStorage->m; i++) { am = fabs(pStorage->fvec[i]); if(am > *max_diff) *max_diff = am; } } else { // only estimate std. dev //*fit = 0.; //*max_diff = 0.; } memcpy(x, pStorage->x, sizeof(double)*pStorage->n); //fprintf(stdout,"-----------------scov matrix ---------------\n"); //for(i=0; i<pStorage->n; i++) { // for(int j=0; j<pStorage->n; j++) { // fprintf(stdout,"%10e ", r[ldr*j+i]/((*fit)*(*fit))); // } // fprintf(stdout,"\n"); //} //fprintf(stdout,"-----------------end of scov matrix ---------------\n"); // old way how to compute covariance #ifndef OLD_COVARIANCE // compute standard covariance matrix int ldr = (pStorage->iopt == 3) ? pStorage->n : pStorage->m; int info; int iflag=1; dcov_(pStorage->fcn, &pStorage->iopt, &pStorage->m, &pStorage->n, pStorage->x, pStorage->fvec, pStorage->fjac, &ldr, &info, pStorage->wa1, pStorage->wa2, pStorage->wa3, pStorage->wa4, (void *)¶ms); if(pStorage->compute_only_stdev) { // only could find discr AFTER dcov_ dummy_fit = discrep(pStorage->fvec,pStorage->m, pStorage->n); for(i=0; i<pStorage->n; i++) st_err[i] = sqrt(fabs(pStorage->fjac[ldr*i+i]))/(dummy_fit); } else for(i=0; i<pStorage->n; i++) { //fprintf(stderr,"Jc %lf\n", pStorage->fjac[ldr*i+i]); st_err[i] = sqrt(fabs(pStorage->fjac[ldr*i+i])); } for(i=0; i<pStorage->n; i++) { for(int j=0; j<pStorage->n; j++) { //fprintf(stderr, "Jc %d %d %6.2lf ", i, j, pStorage->fjac[ldr*i+j]); pStorage->fjac[ldr*i+j] /= (st_err[i]*st_err[j]); } //fprintf(stderr, "\n"); } #else // compute jackobian int pack = 1; if(pStorage->iopt==1) { // forward differencing for jackobian int iflag=1; pack =1; (*pStorage->fcn)(&iflag, &pStorage->m, &pStorage->n, pStorage->x, // need to compute fvec pStorage->fvec, pStorage->fjac, &pStorage->ldfjac, (void *)¶ms); dfdjc3_(pStorage->fcn, &pStorage->m, &pStorage->n, pStorage->x, pStorage->fvec, pStorage->fjac, &pStorage->ldfjac, &iflag, &pStorage->epsfcn, pStorage->wa4, (void *)¶ms); } else { int iflag=2; int ldfjac = 1; (*pStorage->fcn)(&iflag, &pStorage->m, &pStorage->n, pStorage->x, pStorage->fvec, pStorage->fjac, &ldfjac, (void *)¶ms); } compute_standard_errors(pStorage->fjac, pStorage->m, pStorage->n, pStorage->ipvt, pStorage->wa1, pack, *fit, st_err); //compute_standard_errors_svd(pStorage->fjac, pStorage->m, pStorage->n, *fit, // st_err); #endif return 1; }