Changeset 36651 for trunk/psModules/src/imcombine/pmStack.c
- Timestamp:
- Apr 4, 2014, 4:19:48 PM (12 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/imcombine/pmStack.c (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/imcombine/pmStack.c
r35455 r36651 43 43 // #define TEST_X 972 44 44 // #define TEST_Y 3213 45 #define TEST_X 3289 46 #define TEST_Y 4810 47 #define TEST_RADIUS 0.5 // Radius to examine 45 //#define TEST_X 3289 46 //#define TEST_Y 4810 47 //#define TEST_RADIUS 0.5 // Radius to examine 48 //MEH -- streak-like junk md04s065i 49 #define TEST_X 1129 50 #define TEST_Y 4256 51 #define TEST_RADIUS 2.0 // Radius to examine 48 52 # endif 49 53 … … 108 112 109 113 // KMM functions to do bimodality rejection of pixels 110 floatgaussian(float x, float m, float s) {114 double gaussian(float x, float m, float s) { 111 115 return(pow(s * sqrt(2 * M_PI),-1) * exp(-0.5 * pow( (x - m) / s, 2))); 112 116 } … … 116 120 float *mU, float *sU, 117 121 float *pi1, float *m1, float *s1, 118 float *pi2, float *m2, float *s2) { 122 float *pi2, float *m2, float *s2, 123 int xyrdebug) { 119 124 assert(values); 120 125 assert(values->type.type == PS_TYPE_F32); … … 151 156 } 152 157 158 if (xyrdebug == 1) { 159 fprintf(stderr,"KMM uni: %d %f %d (%f %f)\n", 160 xyrdebug,logL_unimodal,discrepant_index, 161 *mU,*sU); 162 } 163 153 164 // Do EM loop 154 165 float dL = 0; … … 186 197 *pi2 = 0.5; 187 198 188 float g1,g2,norm; 199 //MEH -- need to be double to help avoid 0 in norm 200 double g1,g2,norm; 189 201 float w1,w2; 190 202 … … 203 215 /* *m2,*s2,*pi2); */ 204 216 /* } */ 217 218 if (xyrdebug == 1) { 219 fprintf(stderr,"KMM EM iter: %d %f %f %f %f (%f %f %e) (%f %f %e)\n", 220 *iter,logL_unimodal,logL_bimodal,oldL,dL, 221 *m1,*s1,*pi1, 222 *m2,*s2,*pi2); 223 } 224 205 225 // Expectation/P-stage 206 226 for (i = 0; i < values->n; i++) { // Calculate probabilities for each mode … … 208 228 g2 = gaussian(values->data.F32[i],*m2,*s2); 209 229 norm = (*pi1 * g1 + *pi2 * g2); 210 P1->data.F32[i] = (*pi1 * g1) / norm; 211 P2->data.F32[i] = (*pi2 * g2) / norm; 230 //MEH -- must protect denom from norm=0 231 if (norm > 0) { 232 P1->data.F32[i] = (*pi1 * g1) / norm; 233 P2->data.F32[i] = (*pi2 * g2) / norm; 234 } else { 235 P1->data.F32[i] = 0.0; 236 P2->data.F32[i] = 0.0; 237 } 238 239 if (xyrdebug == 1) { 240 fprintf(stderr,"KMM EM-P loop: %d %d %le %le %le\n", 241 *iter,i,norm,g1,g2); 242 } 243 212 244 } 213 245 // Maximization/M-stage … … 231 263 w1 += P1->data.F32[i]; 232 264 w2 += P2->data.F32[i]; 265 266 if (xyrdebug == 1) { 267 fprintf(stderr,"KMM EM-M loop: %d %d (%f %f %f %e) (%f %f %f %e)\n", 268 *iter,i,*m1,values->data.F32[i],w1,P1->data.F32[i],*m2,values->data.F32[i],w2,P2->data.F32[i]); 269 } 270 233 271 } 234 272 *m1 /= w1; … … 250 288 *pi2 = 0.0; 251 289 } 252 if (*s1 == 0) { // sigma may not be zero 253 *s1 = KMM_SMALL_NUMBER * *m1; 254 } 255 if (*s2 == 0) { // sigma may not be zero 256 *s2 = KMM_SMALL_NUMBER * *m2; 257 } 290 if (*s1 == 0) { // sigma may not be zero -- MEH -- nor <0 and need additive offset if m~0 291 *s1 = fabsf(KMM_SMALL_NUMBER * *m1) + KMM_SMALL_NUMBER; 292 } 293 if (*s2 == 0) { // sigma may not be zero 294 *s2 = fabsf(KMM_SMALL_NUMBER * *m2) + KMM_SMALL_NUMBER; 295 } 296 297 if (xyrdebug == 1) { 298 fprintf(stderr,"KMM EM end: %d %f %f %f %f (%f %e %e %f) (%f %e %e %f)\n", 299 *iter,logL_unimodal,logL_bimodal,oldL,dL, 300 *m1,*s1,*pi1,w1, 301 *m2,*s2,*pi2,w2); 302 } 303 258 304 } // End EM phase 259 305 … … 267 313 *Punimodal = 1.0; 268 314 } 315 316 if (xyrdebug == 1) { 317 fprintf(stderr,"KMM calc Puni: %d %f %d %f\n", 318 xyrdebug,lambda,df,*Punimodal); 319 } 320 269 321 psFree(P1); 270 322 psFree(P2); 271 323 } 272 324 273 static void KMMFindPopular(const psVector *values, float *Punimodal, float *mean, float *sigma, float *pi ) {325 static void KMMFindPopular(const psVector *values, float *Punimodal, float *mean, float *sigma, float *pi, int xyrdebug) { 274 326 float KMM_MINIMUM_PVALUE = 0.05; // Should be an option. 275 327 float mU,sU; … … 283 335 &mU,&sU, 284 336 &pi1,&m1,&s1, 285 &pi2,&m2,&s2 );337 &pi2,&m2,&s2,xyrdebug); 286 338 /* fprintf(stdout,"%g %g : %g %g %g : %g %g %g : %g %d\t", */ 287 339 /* mU,sU, */ … … 898 950 psVector *pixelSuspects = buffer->suspects; // Is the pixel suspect? 899 951 psVector *pixelLimits = buffer->limits; // Is the pixel suspect? 952 //MEH -- adding a debug option for TESTING xyr position but could be better.. 953 int xyrdebug = 0; 900 954 901 955 // KMM values; … … 917 971 // This should probably be an option 918 972 if (useKMM) { 919 KMMFindPopular(pixelData,&Punimodal,&KMMmean,&KMMsigma,&KMMpi); 973 #ifdef TESTING 974 if (PS_SQR(x - TEST_X) + PS_SQR(y - TEST_Y) <= PS_SQR(TEST_RADIUS)) { 975 xyrdebug = 1; 976 } 977 # endif 978 KMMFindPopular(pixelData,&Punimodal,&KMMmean,&KMMsigma,&KMMpi,xyrdebug); 920 979 CHECKPIX(x,y,"KMM Popularity Contest: (%d,%d) Puni: %g Mean: %f Sigma %f Pi: %f\n", 921 980 x,y,Punimodal,KMMmean,KMMsigma,KMMpi);
Note:
See TracChangeset
for help on using the changeset viewer.
