Changeset 5049 for trunk/psphot/src/psMinimize.c
- Timestamp:
- Sep 13, 2005, 4:06:55 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/psphot/src/psMinimize.c (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psMinimize.c
r5048 r5049 3 3 4 4 // XXX EAM : this file contains my alternate implementations of psMinimizeLMChi2 5 6 5 // XXX EAM this implementation of MinLM includes limits on params & dparams 6 7 7 psBool psMinimizeLMChi2_EAM(psMinimization *min, 8 8 psImage *covar, … … 11 11 const psArray *x, 12 12 const psVector *y, 13 const psVector *y Err,13 const psVector *yWt, 14 14 psMinimizeLMChi2Func func) 15 15 { … … 60 60 // the user provides the error or NULL. we need to convert 61 61 // to appropriate weights 62 dy = psVectorAlloc (y->n, PS_TYPE_F32); 63 if (yErr != NULL) { 64 for (int i = 0; i < dy->n; i++) { 65 if (yErr->data.F32[i] == 0.0) { 66 dy->data.F32[i] = 1.0; 67 // mask this? bad pixel, obviously... 68 } else { 69 dy->data.F32[i] = 1.0 / PS_SQR (yErr->data.F32[i]); 70 } 71 } 62 if (yWt != NULL) { 63 dy = (psVector *) yWt; 72 64 } else { 73 for (int i = 0; i < dy->n; i++) { 74 dy->data.F32[i] = 1.0; 75 } 65 dy = psVectorAlloc (y->n, PS_TYPE_F32); 66 psVectorInit (dy, 1.0); 67 // for (int i = 0; i < dy->n; i++) { 68 // dy->data.F32[i] = 1.0; 69 // } 76 70 } 77 71 … … 82 76 return (false); 83 77 } 84 # ifndef PS_NO_TRACE78 # ifndef PS_NO_TRACE 85 79 // dump some useful info if trace is defined 86 80 if (psTraceGetLevel (".psLib.dataManip.psMinimizeLMChi2") >= 5) { … … 92 86 p_psVectorPrintRow (psTraceGetDestination(), Params, "params guess"); 93 87 } 94 # endif /* PS_NO_TRACE */88 # endif /* PS_NO_TRACE */ 95 89 96 90 // iterate until the tolerance is reached, or give up … … 103 97 psF64 dLinear = p_psMinLM_dLinear (Beta, beta, lambda); 104 98 105 # ifndef PS_NO_TRACE99 # ifndef PS_NO_TRACE 106 100 // dump some useful info if trace is defined 107 101 if (psTraceGetLevel (".psLib.dataManip.psMinimizeLMChi2") >= 5) { … … 113 107 p_psVectorPrintRow (psTraceGetDestination(), Params, "params guess"); 114 108 } 115 # endif /* PS_NO_TRACE */109 # endif /* PS_NO_TRACE */ 116 110 117 111 // calculate Chisq for new guess, update Alpha & Beta … … 125 119 126 120 psTrace (".psLib.dataManip.psMinimizeLMChi2", 4, "last chisq: %f, new chisq %f, delta: %f, rho: %f\n", min->value, Chisq, min->lastDelta, rho); 127 # ifndef PS_NO_TRACE121 # ifndef PS_NO_TRACE 128 122 // dump some useful info if trace is defined 129 123 if (psTraceGetLevel (".psLib.dataManip.psMinimizeLMChi2") >= 5) { … … 132 126 p_psVectorPrint (psTraceGetDestination(), Params, "params guess"); 133 127 } 134 # endif /* PS_NO_TRACE */128 # endif /* PS_NO_TRACE */ 135 129 136 130 /* if (Chisq < min->value) { */ … … 151 145 // construct & return the covariance matrix (if requested) 152 146 if (covar != NULL) { 153 p_psMinLM_GuessABP_EAM (covar, Beta, Params, alpha, beta, params, paramMask, beta_lim, param_min, param_max, 0.0);147 p_psMinLM_GuessABP_EAM (covar, Beta, Params, alpha, beta, params, paramMask, beta_lim, param_min, param_max, 0.0); 154 148 } 155 149 … … 160 154 psFree (Beta); 161 155 psFree (Params); 162 psFree (dy); 156 if (yWt == NULL) { 157 psFree (dy); 158 } 163 159 164 160 if (min->iter == min->maxIter) { 165 return (false);161 return (false); 166 162 } 167 163 return (true); … … 182 178 { 183 179 184 # define USE_LU_DECOMP 1185 # if (USE_LU_DECOMP)180 # define USE_LU_DECOMP 1 181 # if (USE_LU_DECOMP) 186 182 psVector *LUv = NULL; 187 183 psImage *LUm = NULL; … … 205 201 Alpha = psMatrixInvert (Alpha, A, &det); 206 202 207 # else203 # else 208 204 // gauss-jordan version 209 205 psTrace (".psLib.dataManip.psMinLM_GuessABP", 5, "using Gauss-J version"); … … 218 214 219 215 psGaussJordan (Alpha, Beta); 220 # endif216 # endif 221 217 222 218 // apply Beta to get new Params values … … 241 237 } 242 238 243 # if (USE_LU_DECOMP)239 # if (USE_LU_DECOMP) 244 240 psFree (A); 245 241 psFree (LUm); 246 242 psFree (LUv); 247 # endif243 # endif 248 244 249 245 return true; 250 246 } 251 247 248 bool psMinimizeGaussNewtonDelta_EAM (psVector *delta, 249 const psVector *params, 250 const psVector *paramMask, 251 const psArray *x, 252 const psVector *y, 253 const psVector *yWt, 254 psMinimizeLMChi2Func func) 255 { 256 257 // allocate internal arrays (current vs Guess) 258 psImage *alpha = psImageAlloc (params->n, params->n, PS_TYPE_F64); 259 psImage *Alpha = psImageAlloc (params->n, params->n, PS_TYPE_F64); 260 psVector *beta = psVectorAlloc (params->n, PS_TYPE_F64); 261 psVector *Params = psVectorAlloc (params->n, PS_TYPE_F64); 262 psVector *dy = NULL; 263 264 // the user provides the error or NULL. we need to convert 265 // to appropriate weights 266 if (yWt != NULL) { 267 dy = (psVector *) yWt; 268 } else { 269 dy = psVectorAlloc (y->n, PS_TYPE_F32); 270 psVectorInit (dy, 1.0); 271 // for (int i = 0; i < dy->n; i++) { 272 // dy->data.F32[i] = 1.0; 273 // } 274 } 275 276 p_psMinLM_SetABX (alpha, beta, params, paramMask, x, y, dy, func); 277 p_psMinLM_GuessABP (Alpha, delta, Params, alpha, beta, params, paramMask, 0.0); 278 279 psFree (alpha); 280 psFree (Alpha); 281 psFree (beta); 282 psFree (Params); 283 if (yWt == NULL) { 284 psFree (dy); 285 } 286 return (true); 287 } 288 289
Note:
See TracChangeset
for help on using the changeset viewer.
