DEBUGPRINT("eosBayesRefinementConditon start\n");
fseek(fptIn,0,SEEK_SET);
-
- eosBayesParameterOfMaxPosteriorGet(d->posterior,d->numDistribution,0);
for(i=0;i<d->numDistribution;i++){
DEBUGPRINT2("%d/%d loop\n",i+1,d->numDistribution);
llinfo->sigma = d->posterior[i].delta;
llinfo->mean = value[1];
llinfo->delta = d->posterior[i].delta/n;
+ llinfo->mode = 0;
DEBUGPRINT1("%s\n",s);
DEBUGPRINT6("min:%f max:%f delta:%f mode:%u mean:%f sigma:%f\n",llinfo->min,llinfo->max,llinfo->delta,llinfo->mode,llinfo->mean,llinfo->sigma);
eosBayesDistributionInit(&(d->prior[i]),llinfo,1);
llinfo->sigma = d->posterior[i].delta;
llinfo->mean = value[1];
llinfo->delta = d->posterior[i].delta/n;
+ llinfo->mode = 0;
DEBUGPRINT1("%s\n",s);
DEBUGPRINT6("min:%f max:%f delta:%f mode:%u mean:%f sigma:%f\n",llinfo->min,llinfo->max,llinfo->delta,llinfo->mode,llinfo->mean,llinfo->sigma);
eosBayesDistributionInit(&(d->prior[i]),llinfo,1);
void eosBayesGettopthreepoint(eosBayesDistribution* d, float* value, float* prob){
- value[0] = d->value[d->iofmaxposterior-1];
- prob[0] = d->prob[d->iofmaxposterior-1];
+ if(d->valueofmaxposterior==d->min){
+ value[0] = d->valueofmaxposterior;
+ prob[0] = d->probofmaxposterior;
+ }else{
+ value[0] = d->value[d->iofmaxposterior-1];
+ prob[0] = d->prob[d->iofmaxposterior-1];
+ }
value[1] = d->valueofmaxposterior;
prob[1] = d->probofmaxposterior;
- value[2] = d->value[d->iofmaxposterior+1];
- prob[2] = d->prob[d->iofmaxposterior+1];
-
+ if(d->valueofmaxposterior==d->max){
+ value[2] = d->valueofmaxposterior;
+ prob[2] = d->probofmaxposterior;
+ }else{
+ value[2] = d->value[d->iofmaxposterior+1];
+ prob[2] = d->prob[d->iofmaxposterior+1];
+ }
}
int i;
float sum;
-
- a1 = (prob[0]-prob[1])/(value[0]-value[1]);
- b1 = -a1*value[1]+prob[1];
- a2 = (prob[1]-prob[2])/(value[1]-value[2]);
- b2 = -a2*value[1]+prob[1];
+ a1 = 0;
+ a2 = 0;
+ b1 = 0;
+ b2 = 0;
+
+ if(value[0] != value[1]){
+ a1 = (prob[0]-prob[1])/(value[0]-value[1]);
+ b1 = -a1*value[1]+prob[1];
+ }
+
+ if(value[2] != value[1]){
+ a2 = (prob[1]-prob[2])/(value[1]-value[2]);
+ b2 = -a2*value[1]+prob[1];
+ }
sum = 0;
for(i=0;i<d->n;i++){
}
-void eosBayesProbabilityReset(eosBayes* d, int mode){
-
- FILE* fpt;
+void eosBayesProbabilityReset(FILE* fptIn, eosBayes* d, int n, int mode){
int i;
- int j;
char s[1024];
+ eosBayesDistributionInfo info;
DEBUGPRINT("eosBayesProbabilityReset\n");
+ fseek(fptIn,0,SEEK_SET);
for(i=0;i<d->numDistribution;i++){
+ DEBUGPRINT2("%d/%d loop\n",i+1,d->numDistribution);
+ stringGetFromFile(s, "in main", fptIn, stdout, 3);
if(d->prior[i].resetflag==1){
+ DEBUGPRINT("Set new peior\n");
+ info.min = stringGetNthRealData(s, 2," \t");
+ info.max = stringGetNthRealData(s, 3," \t");
+ info.delta = stringGetNthRealData(s, 4," \t");
+ info.mode = 0;
+ info.mean = stringGetNthRealData(s, 6," \t");
+ info.sigma = stringGetNthRealData(s, 7," \t");
+ info.delta = info.delta/n;
+ DEBUGPRINT1("%s\n",s);
+ DEBUGPRINT6("min:%f max:%f delta:%f mode:%u mean:%f sigma:%f\n",info.min,info.max,info.delta,info.mode,info.mean,info.sigma);
+ eosBayesDistributionInit(&(d->prior[i]),&info,1);
+ eosBayesDistributionInit(&(d->posterior[i]),&info,1);
+ eosBayesDistributionInit(&(d->likelihood[i]),&info,1);
+ eosBayesDistributionInitialProbabilitySet(&(d->prior[i]), &info, 1);
+ eosBayesDistributionInitialProbabilitySet(&(d->posterior[i]), &info, 1);
DEBUGPRINT1("dist%d was reset\n",i);
- free(d->prior[i].value);
- free(d->prior[i].prob);
- free(d->posterior[i].value);
- free(d->posterior[i].prob);
- free(d->likelihood[i].value);
- free(d->likelihood[i].prob);
- sprintf(s,"%s%d.out","./prior",i);
- if((fpt=fopen(s,"r"))==NULL){
- fprintf(stderr,"fopen error: %s\n",s);
- }
- DEBUGPRINT("eosBayesDistributionRead start\n");
- eosBayesDistributionRead(fpt,&(d->prior[i]),1);
- eosBayesDistributionRead(fpt,&(d->posterior[i]),1);
- eosBayesDistributionRead(fpt,&(d->likelihood[i]),1);
- fclose(fpt);
leosBayesParameterOfMaxPosteriorGet(&(d->posterior[i]),0);
d->posterior[i].maxposteriorflag = 0;
d->prior[i].resetflag = 0;
{
int i;
+ int j;
ctfDeterminationByBayesInfo info;
ctfInfo ctfinfo;
eosBayesDistributionInfo llinfo;
/*MTF,B serch start\n*/
+ for(j=0;j<2;j++){
DEBUGPRINT("MTF,B search start\n");
+ ctf.rmax = Rintermediate;
DEBUGPRINT2("set R range:%f~%f\n",ctf.rmin,ctf.rmax);
-
DEBUGPRINT("set maxposteriorflag of MTF,B\n");
eosBayesMaxposteriorflagSet(&out,0);
eosBayesMaxposteriorflagSet(&out,1);
DEBUGPRINT("set resetflag of df,A,k\n");
out.prior[2].resetflag = 1;
out.prior[4].resetflag = 1;
- eosBayesProbabilityReset(&out,0);
+ eosBayesProbabilityReset(info.fptIn,&out,5,0);
DefocusEstimationLoop(info,&out,&ctfinfo,&ctf,&intensity,&likelihood,1);
DEBUGPRINT("MTF,B search finish\n");
/*df,A serch*/
DEBUGPRINT("df, A, k search start\n");
-
ctf.rmax = Rintermediate;
+ ctf.rmin = Rmin;
DEBUGPRINT2("set R range:%f~%f\n",ctf.rmin,ctf.rmax);
DEBUGPRINT("set maxposteriorflag of MTF,B\n");
out.prior[0].resetflag = 1;
out.prior[1].resetflag = 1;
out.prior[3].resetflag = 1;
- eosBayesProbabilityReset(&out,0);
+ eosBayesProbabilityReset(info.fptIn,&out,1,0);
DEBUGPRINT("----maxflagcheck----\n");
#ifdef DEBUG
DEBUGPRINT("set resetflag of df\n");
out.prior[0].resetflag = 1;
- eosBayesProbabilityReset(&out,0);
+ eosBayesProbabilityReset(info.fptIn,&out,5,0);
DEBUGPRINT("----maxflagcheck----\n");
#ifdef DEBUG
DefocusEstimationLoop(info,&out,&ctfinfo,&ctf,&intensity,&likelihood,1);
DEBUGPRINT("df search finish\n");
ctfforbayescheckIntensityOfMaxPosterior(ctf,out.posterior,out.numDistribution,&ctfinfo,intensity.MTFmode,intensity.Ainmode,1,1);
+
+ }
+
+ /*MTF refinement*/
+ DEBUGPRINT("MTF,refinement\n");
+ ctf.rmax = Rmax;
+ DEBUGPRINT2("set R range:%f~%f\n",ctf.rmin,ctf.rmax);
-
- /*defocus refinement*/
+ DEBUGPRINT("set maxposteriorflag of defocus,A,k\n");
+ eosBayesMaxposteriorflagSet(&out,0);
+ eosBayesMaxposteriorflagSet(&out,1);
+ eosBayesMaxposteriorflagSet(&out,2);
+ eosBayesMaxposteriorflagSet(&out,3);
+
+ DEBUGPRINT("set canstantflag of Ain");
+ out.posterior[5].constantflag = 1;
+
+ DEBUGPRINT("set resetflag of B,MTF\n");
+ out.prior[4].resetflag = 1;
+ eosBayesProbabilityReset(info.fptIn,&out,5,0);
+
+ DEBUGPRINT("----maxflagcheck----\n");
+ #ifdef DEBUG
+ for(i=0;i<out.numDistribution;i++){
+ printf("dist%d:%d\n",i,(out.posterior[i].maxposteriorflag));
+ }
+ #endif
+
+ DefocusEstimationLoop(info,&out,&ctfinfo,&ctf,&intensity,&likelihood,1);
+ DEBUGPRINT("MTF, B refinement finish\n");
+ ctfforbayescheckIntensityOfMaxPosterior(ctf,out.posterior,out.numDistribution,&ctfinfo,intensity.MTFmode,intensity.Ainmode,1,1);
+
+
+ /*df search*/
+ /*
+ DEBUGPRINT("df serch start\n");
+ ctf.rmax = Rintermediate;
+ DEBUGPRINT2("set R range:%f~%f\n",ctf.rmin,ctf.rmax);
+
+ DEBUGPRINT("set maxposteriorflag of defocus,A,B\n");
+ eosBayesMaxposteriorflagSet(&out,1);
+ eosBayesMaxposteriorflagSet(&out,2);
+ eosBayesMaxposteriorflagSet(&out,3);
+ eosBayesMaxposteriorflagSet(&out,4);
+
+ DEBUGPRINT("set canstantflag of Ain");
+ out.posterior[5].constantflag = 1;
+
+ DEBUGPRINT("set resetflag of df\n");
+ out.prior[0].resetflag = 1;
+ eosBayesProbabilityReset(info.fptIn,&out,5,0);
+
+ DEBUGPRINT("----maxflagcheck----\n");
+ #ifdef DEBUG
+ for(i=0;i<out.numDistribution;i++){
+ printf("dist%d:%d\n",i,(out.posterior[i].maxposteriorflag));
+ }
+ #endif
+
+ DefocusEstimationLoop(info,&out,&ctfinfo,&ctf,&intensity,&likelihood,1);
+ DEBUGPRINT("df search finish\n");
+ ctfforbayescheckIntensityOfMaxPosterior(ctf,out.posterior,out.numDistribution,&ctfinfo,intensity.MTFmode,intensity.Ainmode,1,1);
+*/
+
+ /*A, Ain refinement*/
/*
+ DEBUGPRINT("A, k, Ain refinement start\n");
+
+ ctf.rmax = Rintermediate;
+ ctf.rmin = Rmin;
+ DEBUGPRINT2("set R range:%f~%f\n",ctf.rmin,ctf.rmax);
+
+ DEBUGPRINT("set maxposteriorflag of MTF,B\n");
+ eosBayesMaxposteriorflagSet(&out,0);
+ eosBayesMaxposteriorflagSet(&out,2);
+ eosBayesMaxposteriorflagSet(&out,4);
+
+ DEBUGPRINT("set canstantflag of Ain");
+ out.posterior[5].constantflag = 0;
+
+ DEBUGPRINT("set resetflag of df,A,k\n");
+ out.prior[0].resetflag = 1;
+ out.prior[1].resetflag = 1;
+ out.prior[3].resetflag = 1;
+ out.prior[5].resetflag = 1;
+ eosBayesProbabilityReset(info.fptIn,&out,5,0);
+
+ DEBUGPRINT("----maxflagcheck----\n");
+ #ifdef DEBUG
+ for(i=0;i<out.numDistribution;i++){
+ printf("dist%d:%d\n",i,(out.posterior[i].maxposteriorflag));
+ }
+ #endif
+
+ DefocusEstimationLoop(info,&out,&ctfinfo,&ctf,&intensity,&likelihood,1);
+ DEBUGPRINT("df, A, k, Ain refinementfinish\n");
+ ctfforbayescheckIntensityOfMaxPosterior(ctf,out.posterior,out.numDistribution,&ctfinfo,intensity.MTFmode,intensity.Ainmode,1,1);
+*/
+ /*defocus refinement*/
+
DEBUGPRINT("defocus refinement start\n");
- ctf.rmax = Rmax;
+ ctf.rmax = Rintermediate;
ctf.rmin = Rmin;
DEBUGPRINT2("set R range:%f~%f\n",ctf.rmin,ctf.rmax);
DEBUGPRINT("set maxposteriorflag of defocus,A,B,MTF\n");
out.posterior[0].maxposteriorflag = 0;
out.posterior[1].maxposteriorflag = 0;
-
- out.posterior[2].maxposteriorflag = 1;
- out.posterior[2].n = 1;
- out.prior[2].n = 1;
- out.posterior[4].maxposteriorflag = 1;
- out.posterior[4].n = 1;
- out.prior[4].n = 1;
+ out.posterior[3].maxposteriorflag = 0;
+ out.posterior[5].maxposteriorflag = 0;
+ eosBayesMaxposteriorflagSet(&out,2);
+ eosBayesMaxposteriorflagSet(&out,4);
DEBUGPRINT("set canstantflag of k and Ain");
- out.posterior[3].constantflag = 0;
out.posterior[5].constantflag = 0;
DEBUGPRINT("set refmode\n");
out.posterior[0].refmode = 1;
out.posterior[1].refmode = 1;
- out.posterior[2].refmode = 1;
- out.posterior[3].refmode = 0;
- out.posterior[4].refmode = 1;
- out.posterior[5].refmode = 0;
+ out.posterior[2].refmode = 0;
+ out.posterior[3].refmode = 1;
+ out.posterior[4].refmode = 0;
+ out.posterior[5].refmode = 2;
eosBayesRefinementCondition(info.fptIn,&out,&llinfo,5,0);
DistributionChangeCheck(&out, 0);
- defocusLikelihoodInit(&likelihood,out,1);
+ defocusLikelihoodInit(&likelihood,&out,1);
- DefocusEstimationLoop(info,&out,&ctfinfo,&ctf,&intensity,&likelihood);
+ DefocusEstimationLoop(info,&out,&ctfinfo,&ctf,&intensity,&likelihood,1);
DEBUGPRINT("defocus refinement finish\n");
ctfforbayescheckIntensityOfMaxPosterior(ctf,out.posterior,out.numDistribution,&ctfinfo,intensity.MTFmode,intensity.Ainmode,1,1);
-*/
+
eosBayesPosteriorWrite(&out,0);
ctfforbayesFree(&ctf,&intensity,&likelihood,out.numLikelihood);