IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 35798


Ignore:
Timestamp:
Jul 11, 2013, 8:00:59 AM (13 years ago)
Author:
watersc1
Message:

Fix to psMM that avoids memory corruption when Ncensored = 0.

Location:
trunk/psLib/src/math
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/math/psMinimizeLMM.c

    r35767 r35798  
    501501        psTrace("psLib.math", 5, "Iteration number %d.  (max iterations is %d).\n", min->iter, min->maxIter);
    502502        psTrace("psLib.math", 5, "Last delta is %f.  stop if < %f, accept if < %f\n", min->lastDelta, min->minTol, min->maxTol);
     503        psTrace("psLib.math.dLinear", 5, "Iteration number %d.  (max iterations is %d).\n", min->iter, min->maxIter);
     504        psTrace("psLib.math.dLinear", 5, "Last delta is %f.  stop if < %f, accept if < %f\n", min->lastDelta, min->minTol, min->maxTol);
    503505
    504506        // set a new guess for Alpha, Beta, Params
     
    519521            p_psVectorPrint(psTraceGetDestination(), Params, "params guess (1)");
    520522        }
     523        if (psTraceGetLevel("psLib.math.dLinear") >= 6) {
     524          p_psImagePrint(psTraceGetDestination(), Alpha, "alpha guess (1)");
     525          p_psVectorPrint(psTraceGetDestination(), Beta, "beta guess (1)");
     526          p_psVectorPrint(psTraceGetDestination(), Params, "params guess (1)");
     527          p_psVectorPrint(psTraceGetDestination(), params, "params guess (1)");
     528        }         
    521529
    522530        // calculate Chisq for new guess, update Alpha & Beta
     
    538546
    539547        psTrace("psLib.math.dLinear", 5, "last chisq: %f, new chisq %f, delta: %f, dLinear: %f, rho: %f, lambda: %g\n", min->value, Chisq, min->lastDelta, dLinear, rho, lambda);
    540 
     548        if (psTraceGetLevel("psLib.math.dLinear") >= 6) {
     549          p_psImagePrint(psTraceGetDestination(), Alpha, "alpha guess (2)");
     550          p_psVectorPrint(psTraceGetDestination(), Beta, "beta guess (2)");
     551          p_psVectorPrint(psTraceGetDestination(), Params, "params guess (2)");
     552        }         
    541553        // dump some useful info if trace is defined
    542554        if (psTraceGetLevel("psLib.math") >= 6) {
  • trunk/psLib/src/math/psMixtureModels.c

    • Property svn:mergeinfo set to (toggle deleted branches)
      /branches/eam_branches/ipp-20130307/psLib/src/math/psMixtureModels.cmergedeligible
      /branches/eam_branches/ipp-20130419/psLib/src/math/psMixtureModels.cmergedeligible
      /branches/eam_branches/ipp-20130509/psLib/src/math/psMixtureModels.cmergedeligible
      /tags/ipp-test-20130710/psLib/src/math/psMixtureModels.cmergedeligible
      /branches/czw_branch/20101203/psLib/src/math/psMixtureModels.c29907-30631
      /branches/czw_branch/20120906/psLib/src/math/psMixtureModels.c34410-34786
      /branches/eam_branches/ipp-20101103/psLib/src/math/psMixtureModels.c29657-29920
      /branches/eam_branches/ipp-20101205/psLib/src/math/psMixtureModels.c29959-30585
      /branches/eam_branches/ipp-20110213/psLib/src/math/psMixtureModels.c30628-31149
      /branches/eam_branches/ipp-20110404/psLib/src/math/psMixtureModels.c31166-31444
      /branches/eam_branches/ipp-20110505/psLib/src/math/psMixtureModels.c31458-31658
      /branches/eam_branches/ipp-20110710/psLib/src/math/psMixtureModels.c31852-32345
      /branches/eam_branches/ipp-20110906/psLib/src/math/psMixtureModels.c32363-32631
      /branches/eam_branches/ipp-20111110/psLib/src/math/psMixtureModels.c32645-32694
      /branches/eam_branches/ipp-20120405/psLib/src/math/psMixtureModels.c33724-33957
      /branches/eam_branches/ipp-20120601/psLib/src/math/psMixtureModels.c33977-34079
      /branches/eam_branches/ipp-20120627/psLib/src/math/psMixtureModels.c34099-34256
      /branches/eam_branches/ipp-20120805/psLib/src/math/psMixtureModels.c34292-34401
      /branches/eam_branches/ipp-20120905/psLib/src/math/psMixtureModels.c34407-34747
      /branches/eam_branches/ipp-20121130/psLib/src/math/psMixtureModels.c34755-34841
      /branches/eam_branches/ipp-20121219/psLib/src/math/psMixtureModels.c34857-35096
      /branches/eam_branches/ipp-20130207/psLib/src/math/psMixtureModels.c35125-35236
      /branches/haf_add201112/psLib/src/math/psMixtureModels.c32980-33029
    r35785 r35798  
    116116                        psVector *offsets) {
    117117  // Allocate offset vector
    118   offsets = psVectorRecycle(offsets,in->numRows,PS_TYPE_S32);
     118  //  offsets = psVectorRecycle(offsets,in->numRows,PS_TYPE_S32);
    119119
    120120  *Ncensored = 0;
     
    169169  psImage  *Dcensored = psMMCensorData(D,&Ncensored,offsets);
    170170
    171   psVector *tempModes = psVectorAlloc(N - Ncensored,PS_TYPE_F32);
    172   bool success = psMMkmeansUncensored(Dcensored,
    173                                       dim,
    174                                       N - Ncensored,
    175                                       tempModes,
    176                                       means,
    177                                       m,
    178                                       iterations,
    179                                       V);
     171
     172  bool success;
    180173  if (Ncensored == 0) { // We can directly return the modes and means calculated
    181     if (modes) {
    182       psFree(modes);
    183     }
    184     modes = psMemIncrRefCounter(tempModes);
     174    success = psMMkmeansUncensored(Dcensored,
     175                                   dim,
     176                                   N,
     177                                   modes,
     178                                   means,
     179                                   m,
     180                                   iterations,
     181                                   V);
    185182  }
    186183  else {
     184    psVector *tempModes = psVectorAlloc(N - Ncensored,PS_TYPE_F32);
     185    success = psMMkmeansUncensored(Dcensored,
     186                                   dim,
     187                                   N - Ncensored,
     188                                   tempModes,
     189                                   means,
     190                                   m,
     191                                   iterations,
     192                                   V);
     193   
    187194    if (!modes) {
    188195      modes = psVectorAlloc(N,PS_TYPE_F32);
    189196    }
    190 
     197   
    191198    psVectorInit(modes,NAN);
    192199    for (int i = 0; i < N - Ncensored; i++) {
    193200      modes->data.F32[i - offsets->data.S32[i]] = tempModes->data.F32[i];
    194201    }
     202    psFree(tempModes);
    195203  }
    196204  psFree(offsets);
    197205  psFree(Dcensored);
    198   psFree(tempModes);
     206
    199207  return(success);
    200208}
     
    373381  // We need to scan the input for invalid d
    374382  long Ncensored;
    375   psVector *offsets = psVectorAlloc(N,PS_TYPE_F32);
     383  psVector *offsets = psVectorAlloc(N,PS_TYPE_S32);
    376384  psImage  *Dcensored = psMMCensorData(D,&Ncensored,offsets);
    377 
    378   psVector *tempModes = psVectorAlloc(N - Ncensored,PS_TYPE_F32);
    379   psImage  *tempP     = psImageAlloc(m,N - Ncensored,PS_TYPE_F32);
    380   bool success = psMMGMMUncensored(Dcensored,
    381                                    dim,
    382                                    N - Ncensored,
    383                                    tempModes,
    384                                    means,
    385                                    sigma,
    386                                    pi,
    387                                    tempP,
    388                                    m,
    389                                    iterations,
    390                                    V);
     385  bool success;
    391386  if (Ncensored == 0) { // We can directly return the modes and means calculated
    392     if (modes) {
    393       psFree(modes);
    394     }
    395     if (P) {
    396       psFree(P);
    397     }
    398     modes = psMemIncrRefCounter(tempModes);
    399     P     = psMemIncrRefCounter(tempP);
     387    success = psMMGMMUncensored(Dcensored,
     388                                dim,
     389                                N,
     390                                modes,
     391                                means,
     392                                sigma,
     393                                pi,
     394                                P,
     395                                m,
     396                                iterations,
     397                                V);
    400398  }
    401399  else {
     400    psVector *tempModes = psVectorAlloc(N - Ncensored,PS_TYPE_F32);
     401    psImage  *tempP     = psImageAlloc(m,N - Ncensored,PS_TYPE_F32);
     402
     403    success = psMMGMMUncensored(Dcensored,
     404                                dim,
     405                                N,
     406                                tempModes,
     407                                means,
     408                                sigma,
     409                                pi,
     410                                tempP,
     411                                m,
     412                                iterations,
     413                                V);
     414     
     415   
    402416    if (!modes) {
    403417      modes = psVectorAlloc(N,PS_TYPE_F32);
     
    415429      }
    416430    }
     431    psFree(tempModes);
     432    psFree(tempP);
    417433  }
    418434  psFree(offsets);
    419435  psFree(Dcensored);
    420   psFree(tempModes);
    421   psFree(tempP);
    422436  return(success);
    423437}
Note: See TracChangeset for help on using the changeset viewer.