IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 31722


Ignore:
Timestamp:
Jun 27, 2011, 6:23:47 PM (15 years ago)
Author:
watersc1
Message:

speed improvement for stacking. Not as large as I would have hoped but better than nothing.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tags/ipp-20110622/psModules/src/imcombine/pmStack.c

    r31634 r31722  
    3737
    3838
    39 //# if (0)
    40 #define TESTING                         // Enable test output
     39# if (0)
     40#define TESTING                         Enable test output
    4141/* #define TEST_X 5745                       // x coordinate to examine */
    4242/* #define TEST_Y 5331                       // y coordinate to examine */
     
    4444#define TEST_Y 25
    4545#define TEST_RADIUS 0.5                 // Radius to examine
    46 //# endif
     46# endif
    4747
    4848# ifdef TESTING
     
    122122  psVector *P2 = psVectorAlloc(values->n,PS_TYPE_F32);
    123123  int i;
     124  int discrepant_index = -1;
     125  double discrepant_value = 0;
    124126/*   int debug = 0; */
    125127 
     
    134136  for (i = 0; i < values->n; i++) { // Calculate sigma
    135137    *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   
    136145  }
    137146  *sU = sqrt(*sU / values->n);
     
    145154  *iter = 0;
    146155  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   
    151183  *pi1 = 0.5;
    152184  *pi2 = 0.5;
     
    157189  // These should be options.
    158190  float KMM_TOLERANCE = 1e-6;
    159   int KMM_MAX_ITERATIONS = 500;
     191  int KMM_MAX_ITERATIONS = 30;
    160192  float KMM_SMALL_NUMBER = 1e-5;
    161193  while (((dL > KMM_TOLERANCE)||(*iter < 3))&&(*iter < KMM_MAX_ITERATIONS)) {
     
    250282               &pi1,&m1,&s1,
    251283               &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"); */
    253295  if (*Punimodal > KMM_MINIMUM_PVALUE) {
    254296    // Is unimodal
Note: See TracChangeset for help on using the changeset viewer.