Changeset 31722
- Timestamp:
- Jun 27, 2011, 6:23:47 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tags/ipp-20110622/psModules/src/imcombine/pmStack.c
r31634 r31722 37 37 38 38 39 //# if (0)40 #define TESTING //Enable test output39 # if (0) 40 #define TESTING Enable test output 41 41 /* #define TEST_X 5745 // x coordinate to examine */ 42 42 /* #define TEST_Y 5331 // y coordinate to examine */ … … 44 44 #define TEST_Y 25 45 45 #define TEST_RADIUS 0.5 // Radius to examine 46 //# endif46 # endif 47 47 48 48 # ifdef TESTING … … 122 122 psVector *P2 = psVectorAlloc(values->n,PS_TYPE_F32); 123 123 int i; 124 int discrepant_index = -1; 125 double discrepant_value = 0; 124 126 /* int debug = 0; */ 125 127 … … 134 136 for (i = 0; i < values->n; i++) { // Calculate sigma 135 137 *sU += pow(values->data.F32[i] - *mU,2); 138 139 // Attempt to guess better starting values 140 if (pow(values->data.F32[i] - *mU,2) > discrepant_value) { 141 discrepant_value = pow(values->data.F32[i] - *mU,2); 142 discrepant_index = i; 143 } 144 136 145 } 137 146 *sU = sqrt(*sU / values->n); … … 145 154 *iter = 0; 146 155 logL_bimodal = logL_unimodal; 147 *m1 = *mU - 3 * *sU; 148 *m2 = *mU + 3 * *sU; 149 *s1 = *sU / 2; 150 *s2 = *sU / 2; 156 157 if (discrepant_index == -1) { 158 *m1 = *mU - 3 * *sU; 159 *m2 = *mU + 3 * *sU; 160 *s1 = *sU / 2; 161 *s2 = *sU / 2; 162 } 163 else { 164 // This is an attempt to speed up convergence. Find the largest contributor to sigma, and set one mean 165 // to that value. Set the other mean to the mean of all other points with this one removed. Next, 166 // set the sigmas to be equal to each other. Take the value of sigma to be such that a point equidistant 167 // to the initial values of the two modes is equally not believed by either mode (2.5 sigma away). 168 169 discrepant_value = values->data.F32[discrepant_index]; 170 171 if (discrepant_value > *mU) { 172 *m1 = ((*mU * values->n) - discrepant_value) / (values->n - 1); 173 *m2 = discrepant_value; 174 } 175 else { 176 *m1 = discrepant_value; 177 *m2 = ((*mU * values->n) - discrepant_value) / (values->n - 1); 178 } 179 *s1 = fabs((*m1 - *m2) / 5); 180 *s2 = *s1; 181 } 182 151 183 *pi1 = 0.5; 152 184 *pi2 = 0.5; … … 157 189 // These should be options. 158 190 float KMM_TOLERANCE = 1e-6; 159 int KMM_MAX_ITERATIONS = 500;191 int KMM_MAX_ITERATIONS = 30; 160 192 float KMM_SMALL_NUMBER = 1e-5; 161 193 while (((dL > KMM_TOLERANCE)||(*iter < 3))&&(*iter < KMM_MAX_ITERATIONS)) { … … 250 282 &pi1,&m1,&s1, 251 283 &pi2,&m2,&s2); 252 284 /* fprintf(stdout,"%g %g : %g %g %g : %g %g %g : %g %d\t", */ 285 /* mU,sU, */ 286 /* m1,s1,pi1, */ 287 /* m2,s2,pi2, */ 288 /* *Punimodal,iter); */ 289 /* if (iter > 3) { */ 290 /* for (int i = 0; i < values->n; i++) { */ 291 /* fprintf(stdout," %f ",values->data.F32[i]); */ 292 /* } */ 293 /* } */ 294 /* fprintf(stdout,"\n"); */ 253 295 if (*Punimodal > KMM_MINIMUM_PVALUE) { 254 296 // Is unimodal
Note:
See TracChangeset
for help on using the changeset viewer.
