OSDN Git Service

modified eosBayesCondision.c v2.3.9p0192
author久永浩司 <hisanagakouji@hisanagakouji-no-MacBook-Air.local>
Wed, 11 Jan 2017 05:30:14 +0000 (14:30 +0900)
committer久永浩司 <hisanagakouji@hisanagakouji-no-MacBook-Air.local>
Wed, 11 Jan 2017 05:30:14 +0000 (14:30 +0900)
include/eosBayes.h
src/Objects/General/eosBayes/inc/eosBayes.h
src/Objects/General/eosBayes/src/eosBayesCondition.c
src/Objects/General/eosBayes/src/eosBayesDistributionInitialProbabilitySet.c
src/Objects/General/eosBayes/src/eosBayesParameterOfMaxPosterior.c
src/Tools/ctfInfo/ctfDeterminationByBayes/src/ctfDeterminationByBayes.c

index c190db7..19d0262 100644 (file)
@@ -69,7 +69,7 @@ extern void eosBayesDistributionInit(eosBayesDistribution* d,eosBayesDistributio
 
 // Initialize probe of Each distribution of eosBayesDistriubutions
 extern void eosBayesDistributionInitialProbabilitySet(eosBayesDistribution* d, eosBayesDistributionInfo* info, int mode);
-extern void eosBayesProbabilityReset(eosBayes* d, int mode);
+extern void eosBayesProbabilityReset(FILE* fptIn,eosBayes* d, int n, int mode);
 extern void eosBayesProbabilitysetLinear(eosBayesDistribution* d, float a, float b);
 
 /* eosBayesEstimation.c */
index c190db7..19d0262 100644 (file)
@@ -69,7 +69,7 @@ extern void eosBayesDistributionInit(eosBayesDistribution* d,eosBayesDistributio
 
 // Initialize probe of Each distribution of eosBayesDistriubutions
 extern void eosBayesDistributionInitialProbabilitySet(eosBayesDistribution* d, eosBayesDistributionInfo* info, int mode);
-extern void eosBayesProbabilityReset(eosBayes* d, int mode);
+extern void eosBayesProbabilityReset(FILE* fptIn,eosBayes* d, int n, int mode);
 extern void eosBayesProbabilitysetLinear(eosBayesDistribution* d, float a, float b);
 
 /* eosBayesEstimation.c */
index 723e82c..a9e1934 100644 (file)
@@ -71,8 +71,6 @@ void eosBayesRefinementCondition(FILE* fptIn, eosBayes* d, eosBayesDistributionI
 
   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);
@@ -90,6 +88,7 @@ void eosBayesRefinementCondition(FILE* fptIn, eosBayes* d, eosBayesDistributionI
                  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);
@@ -106,6 +105,7 @@ void eosBayesRefinementCondition(FILE* fptIn, eosBayes* d, eosBayesDistributionI
                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);
@@ -151,15 +151,24 @@ void eosBayesRefinementCondition(FILE* fptIn, eosBayes* d, eosBayesDistributionI
 
 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];
+  }
 }
 
 
@@ -171,12 +180,21 @@ void eosBayesLiniearinterpolationofTopthreepoint(eosBayesDistribution* d, float*
 
   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++){
index d7207cc..cc2404d 100644 (file)
@@ -58,33 +58,34 @@ void eosBayesDistributionInitialProbabilitySet(eosBayesDistribution* d, eosBayes
 
 }
 
-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;
index 347ba7b..435da5d 100644 (file)
@@ -44,6 +44,7 @@ void leosBayesParameterOfMaxPosteriorGet(eosBayesDistribution* d, int mode){
 
          d->valueofmaxposterior = d->value[0];
          d->probofmaxposterior = d->prob[0];
+         d->iofmaxposterior = 0;
          for(i=0;i<d->n;i++){
                if(d->probofmaxposterior < d->prob[i]){
                  d->valueofmaxposterior = d->value[i];
index 0b1c385..de04ab9 100755 (executable)
@@ -44,6 +44,7 @@ main(int argc, char* argv[])
 {
   
   int i;
+  int j;
   ctfDeterminationByBayesInfo info;
   ctfInfo ctfinfo;
   eosBayesDistributionInfo llinfo;
@@ -94,9 +95,10 @@ main(int argc, char* argv[])
 
 
   /*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);
@@ -115,7 +117,7 @@ main(int argc, char* argv[])
   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");
@@ -133,8 +135,8 @@ main(int argc, char* argv[])
 
   /*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");
@@ -148,7 +150,7 @@ main(int argc, char* argv[])
   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
@@ -178,7 +180,7 @@ main(int argc, char* argv[])
 
   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
@@ -190,46 +192,138 @@ main(int argc, char* argv[])
   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);