This repository is a base of Eos.
Revisión | 87ea6b9a251e5b1b5988123cf24dd4fb7e9caee9 (tree) |
---|---|
Tiempo | 2017-01-11 14:30:14 |
Autor | 久永浩司 <hisanagakouji@hisa...> |
Commiter | 久永浩司 |
modified eosBayesCondision.c
@@ -69,7 +69,7 @@ extern void eosBayesDistributionInit(eosBayesDistribution* d,eosBayesDistributio | ||
69 | 69 | |
70 | 70 | // Initialize probe of Each distribution of eosBayesDistriubutions |
71 | 71 | extern void eosBayesDistributionInitialProbabilitySet(eosBayesDistribution* d, eosBayesDistributionInfo* info, int mode); |
72 | -extern void eosBayesProbabilityReset(eosBayes* d, int mode); | |
72 | +extern void eosBayesProbabilityReset(FILE* fptIn,eosBayes* d, int n, int mode); | |
73 | 73 | extern void eosBayesProbabilitysetLinear(eosBayesDistribution* d, float a, float b); |
74 | 74 | |
75 | 75 | /* eosBayesEstimation.c */ |
@@ -69,7 +69,7 @@ extern void eosBayesDistributionInit(eosBayesDistribution* d,eosBayesDistributio | ||
69 | 69 | |
70 | 70 | // Initialize probe of Each distribution of eosBayesDistriubutions |
71 | 71 | extern void eosBayesDistributionInitialProbabilitySet(eosBayesDistribution* d, eosBayesDistributionInfo* info, int mode); |
72 | -extern void eosBayesProbabilityReset(eosBayes* d, int mode); | |
72 | +extern void eosBayesProbabilityReset(FILE* fptIn,eosBayes* d, int n, int mode); | |
73 | 73 | extern void eosBayesProbabilitysetLinear(eosBayesDistribution* d, float a, float b); |
74 | 74 | |
75 | 75 | /* eosBayesEstimation.c */ |
@@ -71,8 +71,6 @@ void eosBayesRefinementCondition(FILE* fptIn, eosBayes* d, eosBayesDistributionI | ||
71 | 71 | |
72 | 72 | DEBUGPRINT("eosBayesRefinementConditon start\n"); |
73 | 73 | fseek(fptIn,0,SEEK_SET); |
74 | - | |
75 | - eosBayesParameterOfMaxPosteriorGet(d->posterior,d->numDistribution,0); | |
76 | 74 | |
77 | 75 | for(i=0;i<d->numDistribution;i++){ |
78 | 76 | DEBUGPRINT2("%d/%d loop\n",i+1,d->numDistribution); |
@@ -90,6 +88,7 @@ void eosBayesRefinementCondition(FILE* fptIn, eosBayes* d, eosBayesDistributionI | ||
90 | 88 | llinfo->sigma = d->posterior[i].delta; |
91 | 89 | llinfo->mean = value[1]; |
92 | 90 | llinfo->delta = d->posterior[i].delta/n; |
91 | + llinfo->mode = 0; | |
93 | 92 | DEBUGPRINT1("%s\n",s); |
94 | 93 | 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); |
95 | 94 | eosBayesDistributionInit(&(d->prior[i]),llinfo,1); |
@@ -106,6 +105,7 @@ void eosBayesRefinementCondition(FILE* fptIn, eosBayes* d, eosBayesDistributionI | ||
106 | 105 | llinfo->sigma = d->posterior[i].delta; |
107 | 106 | llinfo->mean = value[1]; |
108 | 107 | llinfo->delta = d->posterior[i].delta/n; |
108 | + llinfo->mode = 0; | |
109 | 109 | DEBUGPRINT1("%s\n",s); |
110 | 110 | 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); |
111 | 111 | eosBayesDistributionInit(&(d->prior[i]),llinfo,1); |
@@ -151,15 +151,24 @@ void eosBayesRefinementCondition(FILE* fptIn, eosBayes* d, eosBayesDistributionI | ||
151 | 151 | |
152 | 152 | void eosBayesGettopthreepoint(eosBayesDistribution* d, float* value, float* prob){ |
153 | 153 | |
154 | - value[0] = d->value[d->iofmaxposterior-1]; | |
155 | - prob[0] = d->prob[d->iofmaxposterior-1]; | |
154 | + if(d->valueofmaxposterior==d->min){ | |
155 | + value[0] = d->valueofmaxposterior; | |
156 | + prob[0] = d->probofmaxposterior; | |
157 | + }else{ | |
158 | + value[0] = d->value[d->iofmaxposterior-1]; | |
159 | + prob[0] = d->prob[d->iofmaxposterior-1]; | |
160 | + } | |
156 | 161 | |
157 | 162 | value[1] = d->valueofmaxposterior; |
158 | 163 | prob[1] = d->probofmaxposterior; |
159 | 164 | |
160 | - value[2] = d->value[d->iofmaxposterior+1]; | |
161 | - prob[2] = d->prob[d->iofmaxposterior+1]; | |
162 | - | |
165 | + if(d->valueofmaxposterior==d->max){ | |
166 | + value[2] = d->valueofmaxposterior; | |
167 | + prob[2] = d->probofmaxposterior; | |
168 | + }else{ | |
169 | + value[2] = d->value[d->iofmaxposterior+1]; | |
170 | + prob[2] = d->prob[d->iofmaxposterior+1]; | |
171 | + } | |
163 | 172 | } |
164 | 173 | |
165 | 174 |
@@ -171,12 +180,21 @@ void eosBayesLiniearinterpolationofTopthreepoint(eosBayesDistribution* d, float* | ||
171 | 180 | |
172 | 181 | int i; |
173 | 182 | float sum; |
174 | - | |
175 | - a1 = (prob[0]-prob[1])/(value[0]-value[1]); | |
176 | - b1 = -a1*value[1]+prob[1]; | |
177 | 183 | |
178 | - a2 = (prob[1]-prob[2])/(value[1]-value[2]); | |
179 | - b2 = -a2*value[1]+prob[1]; | |
184 | + a1 = 0; | |
185 | + a2 = 0; | |
186 | + b1 = 0; | |
187 | + b2 = 0; | |
188 | + | |
189 | + if(value[0] != value[1]){ | |
190 | + a1 = (prob[0]-prob[1])/(value[0]-value[1]); | |
191 | + b1 = -a1*value[1]+prob[1]; | |
192 | + } | |
193 | + | |
194 | + if(value[2] != value[1]){ | |
195 | + a2 = (prob[1]-prob[2])/(value[1]-value[2]); | |
196 | + b2 = -a2*value[1]+prob[1]; | |
197 | + } | |
180 | 198 | |
181 | 199 | sum = 0; |
182 | 200 | for(i=0;i<d->n;i++){ |
@@ -58,33 +58,34 @@ void eosBayesDistributionInitialProbabilitySet(eosBayesDistribution* d, eosBayes | ||
58 | 58 | |
59 | 59 | } |
60 | 60 | |
61 | -void eosBayesProbabilityReset(eosBayes* d, int mode){ | |
62 | - | |
63 | - FILE* fpt; | |
61 | +void eosBayesProbabilityReset(FILE* fptIn, eosBayes* d, int n, int mode){ | |
64 | 62 | int i; |
65 | - int j; | |
66 | 63 | char s[1024]; |
64 | + eosBayesDistributionInfo info; | |
67 | 65 | |
68 | 66 | DEBUGPRINT("eosBayesProbabilityReset\n"); |
67 | + fseek(fptIn,0,SEEK_SET); | |
69 | 68 | |
70 | 69 | for(i=0;i<d->numDistribution;i++){ |
70 | + DEBUGPRINT2("%d/%d loop\n",i+1,d->numDistribution); | |
71 | + stringGetFromFile(s, "in main", fptIn, stdout, 3); | |
71 | 72 | if(d->prior[i].resetflag==1){ |
73 | + DEBUGPRINT("Set new peior\n"); | |
74 | + info.min = stringGetNthRealData(s, 2," \t"); | |
75 | + info.max = stringGetNthRealData(s, 3," \t"); | |
76 | + info.delta = stringGetNthRealData(s, 4," \t"); | |
77 | + info.mode = 0; | |
78 | + info.mean = stringGetNthRealData(s, 6," \t"); | |
79 | + info.sigma = stringGetNthRealData(s, 7," \t"); | |
80 | + info.delta = info.delta/n; | |
81 | + DEBUGPRINT1("%s\n",s); | |
82 | + 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); | |
83 | + eosBayesDistributionInit(&(d->prior[i]),&info,1); | |
84 | + eosBayesDistributionInit(&(d->posterior[i]),&info,1); | |
85 | + eosBayesDistributionInit(&(d->likelihood[i]),&info,1); | |
86 | + eosBayesDistributionInitialProbabilitySet(&(d->prior[i]), &info, 1); | |
87 | + eosBayesDistributionInitialProbabilitySet(&(d->posterior[i]), &info, 1); | |
72 | 88 | DEBUGPRINT1("dist%d was reset\n",i); |
73 | - free(d->prior[i].value); | |
74 | - free(d->prior[i].prob); | |
75 | - free(d->posterior[i].value); | |
76 | - free(d->posterior[i].prob); | |
77 | - free(d->likelihood[i].value); | |
78 | - free(d->likelihood[i].prob); | |
79 | - sprintf(s,"%s%d.out","./prior",i); | |
80 | - if((fpt=fopen(s,"r"))==NULL){ | |
81 | - fprintf(stderr,"fopen error: %s\n",s); | |
82 | - } | |
83 | - DEBUGPRINT("eosBayesDistributionRead start\n"); | |
84 | - eosBayesDistributionRead(fpt,&(d->prior[i]),1); | |
85 | - eosBayesDistributionRead(fpt,&(d->posterior[i]),1); | |
86 | - eosBayesDistributionRead(fpt,&(d->likelihood[i]),1); | |
87 | - fclose(fpt); | |
88 | 89 | leosBayesParameterOfMaxPosteriorGet(&(d->posterior[i]),0); |
89 | 90 | d->posterior[i].maxposteriorflag = 0; |
90 | 91 | d->prior[i].resetflag = 0; |
@@ -44,6 +44,7 @@ void leosBayesParameterOfMaxPosteriorGet(eosBayesDistribution* d, int mode){ | ||
44 | 44 | |
45 | 45 | d->valueofmaxposterior = d->value[0]; |
46 | 46 | d->probofmaxposterior = d->prob[0]; |
47 | + d->iofmaxposterior = 0; | |
47 | 48 | for(i=0;i<d->n;i++){ |
48 | 49 | if(d->probofmaxposterior < d->prob[i]){ |
49 | 50 | d->valueofmaxposterior = d->value[i]; |
@@ -44,6 +44,7 @@ main(int argc, char* argv[]) | ||
44 | 44 | { |
45 | 45 | |
46 | 46 | int i; |
47 | + int j; | |
47 | 48 | ctfDeterminationByBayesInfo info; |
48 | 49 | ctfInfo ctfinfo; |
49 | 50 | eosBayesDistributionInfo llinfo; |
@@ -94,9 +95,10 @@ main(int argc, char* argv[]) | ||
94 | 95 | |
95 | 96 | |
96 | 97 | /*MTF,B serch start\n*/ |
98 | + for(j=0;j<2;j++){ | |
97 | 99 | DEBUGPRINT("MTF,B search start\n"); |
100 | + ctf.rmax = Rintermediate; | |
98 | 101 | DEBUGPRINT2("set R range:%f~%f\n",ctf.rmin,ctf.rmax); |
99 | - | |
100 | 102 | DEBUGPRINT("set maxposteriorflag of MTF,B\n"); |
101 | 103 | eosBayesMaxposteriorflagSet(&out,0); |
102 | 104 | eosBayesMaxposteriorflagSet(&out,1); |
@@ -115,7 +117,7 @@ main(int argc, char* argv[]) | ||
115 | 117 | DEBUGPRINT("set resetflag of df,A,k\n"); |
116 | 118 | out.prior[2].resetflag = 1; |
117 | 119 | out.prior[4].resetflag = 1; |
118 | - eosBayesProbabilityReset(&out,0); | |
120 | + eosBayesProbabilityReset(info.fptIn,&out,5,0); | |
119 | 121 | |
120 | 122 | DefocusEstimationLoop(info,&out,&ctfinfo,&ctf,&intensity,&likelihood,1); |
121 | 123 | DEBUGPRINT("MTF,B search finish\n"); |
@@ -133,8 +135,8 @@ main(int argc, char* argv[]) | ||
133 | 135 | |
134 | 136 | /*df,A serch*/ |
135 | 137 | DEBUGPRINT("df, A, k search start\n"); |
136 | - | |
137 | 138 | ctf.rmax = Rintermediate; |
139 | + ctf.rmin = Rmin; | |
138 | 140 | DEBUGPRINT2("set R range:%f~%f\n",ctf.rmin,ctf.rmax); |
139 | 141 | |
140 | 142 | DEBUGPRINT("set maxposteriorflag of MTF,B\n"); |
@@ -148,7 +150,7 @@ main(int argc, char* argv[]) | ||
148 | 150 | out.prior[0].resetflag = 1; |
149 | 151 | out.prior[1].resetflag = 1; |
150 | 152 | out.prior[3].resetflag = 1; |
151 | - eosBayesProbabilityReset(&out,0); | |
153 | + eosBayesProbabilityReset(info.fptIn,&out,1,0); | |
152 | 154 | |
153 | 155 | DEBUGPRINT("----maxflagcheck----\n"); |
154 | 156 | #ifdef DEBUG |
@@ -178,7 +180,7 @@ main(int argc, char* argv[]) | ||
178 | 180 | |
179 | 181 | DEBUGPRINT("set resetflag of df\n"); |
180 | 182 | out.prior[0].resetflag = 1; |
181 | - eosBayesProbabilityReset(&out,0); | |
183 | + eosBayesProbabilityReset(info.fptIn,&out,5,0); | |
182 | 184 | |
183 | 185 | DEBUGPRINT("----maxflagcheck----\n"); |
184 | 186 | #ifdef DEBUG |
@@ -190,46 +192,138 @@ main(int argc, char* argv[]) | ||
190 | 192 | DefocusEstimationLoop(info,&out,&ctfinfo,&ctf,&intensity,&likelihood,1); |
191 | 193 | DEBUGPRINT("df search finish\n"); |
192 | 194 | ctfforbayescheckIntensityOfMaxPosterior(ctf,out.posterior,out.numDistribution,&ctfinfo,intensity.MTFmode,intensity.Ainmode,1,1); |
195 | + | |
196 | + } | |
197 | + | |
198 | + /*MTF refinement*/ | |
199 | + DEBUGPRINT("MTF,refinement\n"); | |
200 | + ctf.rmax = Rmax; | |
201 | + DEBUGPRINT2("set R range:%f~%f\n",ctf.rmin,ctf.rmax); | |
193 | 202 | |
194 | - | |
195 | - /*defocus refinement*/ | |
203 | + DEBUGPRINT("set maxposteriorflag of defocus,A,k\n"); | |
204 | + eosBayesMaxposteriorflagSet(&out,0); | |
205 | + eosBayesMaxposteriorflagSet(&out,1); | |
206 | + eosBayesMaxposteriorflagSet(&out,2); | |
207 | + eosBayesMaxposteriorflagSet(&out,3); | |
208 | + | |
209 | + DEBUGPRINT("set canstantflag of Ain"); | |
210 | + out.posterior[5].constantflag = 1; | |
211 | + | |
212 | + DEBUGPRINT("set resetflag of B,MTF\n"); | |
213 | + out.prior[4].resetflag = 1; | |
214 | + eosBayesProbabilityReset(info.fptIn,&out,5,0); | |
215 | + | |
216 | + DEBUGPRINT("----maxflagcheck----\n"); | |
217 | + #ifdef DEBUG | |
218 | + for(i=0;i<out.numDistribution;i++){ | |
219 | + printf("dist%d:%d\n",i,(out.posterior[i].maxposteriorflag)); | |
220 | + } | |
221 | + #endif | |
222 | + | |
223 | + DefocusEstimationLoop(info,&out,&ctfinfo,&ctf,&intensity,&likelihood,1); | |
224 | + DEBUGPRINT("MTF, B refinement finish\n"); | |
225 | + ctfforbayescheckIntensityOfMaxPosterior(ctf,out.posterior,out.numDistribution,&ctfinfo,intensity.MTFmode,intensity.Ainmode,1,1); | |
226 | + | |
227 | + | |
228 | + /*df search*/ | |
229 | + /* | |
230 | + DEBUGPRINT("df serch start\n"); | |
231 | + ctf.rmax = Rintermediate; | |
232 | + DEBUGPRINT2("set R range:%f~%f\n",ctf.rmin,ctf.rmax); | |
233 | + | |
234 | + DEBUGPRINT("set maxposteriorflag of defocus,A,B\n"); | |
235 | + eosBayesMaxposteriorflagSet(&out,1); | |
236 | + eosBayesMaxposteriorflagSet(&out,2); | |
237 | + eosBayesMaxposteriorflagSet(&out,3); | |
238 | + eosBayesMaxposteriorflagSet(&out,4); | |
239 | + | |
240 | + DEBUGPRINT("set canstantflag of Ain"); | |
241 | + out.posterior[5].constantflag = 1; | |
242 | + | |
243 | + DEBUGPRINT("set resetflag of df\n"); | |
244 | + out.prior[0].resetflag = 1; | |
245 | + eosBayesProbabilityReset(info.fptIn,&out,5,0); | |
246 | + | |
247 | + DEBUGPRINT("----maxflagcheck----\n"); | |
248 | + #ifdef DEBUG | |
249 | + for(i=0;i<out.numDistribution;i++){ | |
250 | + printf("dist%d:%d\n",i,(out.posterior[i].maxposteriorflag)); | |
251 | + } | |
252 | + #endif | |
253 | + | |
254 | + DefocusEstimationLoop(info,&out,&ctfinfo,&ctf,&intensity,&likelihood,1); | |
255 | + DEBUGPRINT("df search finish\n"); | |
256 | + ctfforbayescheckIntensityOfMaxPosterior(ctf,out.posterior,out.numDistribution,&ctfinfo,intensity.MTFmode,intensity.Ainmode,1,1); | |
257 | +*/ | |
258 | + | |
259 | + /*A, Ain refinement*/ | |
196 | 260 | /* |
261 | + DEBUGPRINT("A, k, Ain refinement start\n"); | |
262 | + | |
263 | + ctf.rmax = Rintermediate; | |
264 | + ctf.rmin = Rmin; | |
265 | + DEBUGPRINT2("set R range:%f~%f\n",ctf.rmin,ctf.rmax); | |
266 | + | |
267 | + DEBUGPRINT("set maxposteriorflag of MTF,B\n"); | |
268 | + eosBayesMaxposteriorflagSet(&out,0); | |
269 | + eosBayesMaxposteriorflagSet(&out,2); | |
270 | + eosBayesMaxposteriorflagSet(&out,4); | |
271 | + | |
272 | + DEBUGPRINT("set canstantflag of Ain"); | |
273 | + out.posterior[5].constantflag = 0; | |
274 | + | |
275 | + DEBUGPRINT("set resetflag of df,A,k\n"); | |
276 | + out.prior[0].resetflag = 1; | |
277 | + out.prior[1].resetflag = 1; | |
278 | + out.prior[3].resetflag = 1; | |
279 | + out.prior[5].resetflag = 1; | |
280 | + eosBayesProbabilityReset(info.fptIn,&out,5,0); | |
281 | + | |
282 | + DEBUGPRINT("----maxflagcheck----\n"); | |
283 | + #ifdef DEBUG | |
284 | + for(i=0;i<out.numDistribution;i++){ | |
285 | + printf("dist%d:%d\n",i,(out.posterior[i].maxposteriorflag)); | |
286 | + } | |
287 | + #endif | |
288 | + | |
289 | + DefocusEstimationLoop(info,&out,&ctfinfo,&ctf,&intensity,&likelihood,1); | |
290 | + DEBUGPRINT("df, A, k, Ain refinementfinish\n"); | |
291 | + ctfforbayescheckIntensityOfMaxPosterior(ctf,out.posterior,out.numDistribution,&ctfinfo,intensity.MTFmode,intensity.Ainmode,1,1); | |
292 | +*/ | |
293 | + /*defocus refinement*/ | |
294 | + | |
197 | 295 | DEBUGPRINT("defocus refinement start\n"); |
198 | - ctf.rmax = Rmax; | |
296 | + ctf.rmax = Rintermediate; | |
199 | 297 | ctf.rmin = Rmin; |
200 | 298 | DEBUGPRINT2("set R range:%f~%f\n",ctf.rmin,ctf.rmax); |
201 | 299 | |
202 | 300 | DEBUGPRINT("set maxposteriorflag of defocus,A,B,MTF\n"); |
203 | 301 | out.posterior[0].maxposteriorflag = 0; |
204 | 302 | out.posterior[1].maxposteriorflag = 0; |
205 | - | |
206 | - out.posterior[2].maxposteriorflag = 1; | |
207 | - out.posterior[2].n = 1; | |
208 | - out.prior[2].n = 1; | |
209 | - out.posterior[4].maxposteriorflag = 1; | |
210 | - out.posterior[4].n = 1; | |
211 | - out.prior[4].n = 1; | |
303 | + out.posterior[3].maxposteriorflag = 0; | |
304 | + out.posterior[5].maxposteriorflag = 0; | |
305 | + eosBayesMaxposteriorflagSet(&out,2); | |
306 | + eosBayesMaxposteriorflagSet(&out,4); | |
212 | 307 | |
213 | 308 | DEBUGPRINT("set canstantflag of k and Ain"); |
214 | - out.posterior[3].constantflag = 0; | |
215 | 309 | out.posterior[5].constantflag = 0; |
216 | 310 | |
217 | 311 | DEBUGPRINT("set refmode\n"); |
218 | 312 | out.posterior[0].refmode = 1; |
219 | 313 | out.posterior[1].refmode = 1; |
220 | - out.posterior[2].refmode = 1; | |
221 | - out.posterior[3].refmode = 0; | |
222 | - out.posterior[4].refmode = 1; | |
223 | - out.posterior[5].refmode = 0; | |
314 | + out.posterior[2].refmode = 0; | |
315 | + out.posterior[3].refmode = 1; | |
316 | + out.posterior[4].refmode = 0; | |
317 | + out.posterior[5].refmode = 2; | |
224 | 318 | |
225 | 319 | eosBayesRefinementCondition(info.fptIn,&out,&llinfo,5,0); |
226 | 320 | DistributionChangeCheck(&out, 0); |
227 | - defocusLikelihoodInit(&likelihood,out,1); | |
321 | + defocusLikelihoodInit(&likelihood,&out,1); | |
228 | 322 | |
229 | - DefocusEstimationLoop(info,&out,&ctfinfo,&ctf,&intensity,&likelihood); | |
323 | + DefocusEstimationLoop(info,&out,&ctfinfo,&ctf,&intensity,&likelihood,1); | |
230 | 324 | DEBUGPRINT("defocus refinement finish\n"); |
231 | 325 | ctfforbayescheckIntensityOfMaxPosterior(ctf,out.posterior,out.numDistribution,&ctfinfo,intensity.MTFmode,intensity.Ainmode,1,1); |
232 | -*/ | |
326 | + | |
233 | 327 | eosBayesPosteriorWrite(&out,0); |
234 | 328 | |
235 | 329 | ctfforbayesFree(&ctf,&intensity,&likelihood,out.numLikelihood); |