Changeset 35623
- Timestamp:
- Jun 3, 2013, 2:05:58 PM (13 years ago)
- Location:
- branches/eam_branches/ipp-20130509/psLib
- Files:
-
- 3 edited
-
src/math/psMinimizeLMM.c (modified) (11 diffs)
-
src/math/psMinimizeLMM.h (modified) (1 diff)
-
test/math/tap_psMinimizeLMM_Trail.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20130509/psLib/src/math/psMinimizeLMM.c
r35617 r35623 365 365 366 366 /****************************************************************************** 367 psMinimizeLMChi2(): wrapper to call either _Old or _Alt 368 *****************************************************************************/ 369 bool psMinimizeLMChi2( 370 psMinimization *min, 371 psImage *covar, 372 psVector *params, 373 psMinConstraint *constraint, 374 const psArray *x, 375 const psVector *y, 376 const psVector *yWt, 377 psMinimizeLMChi2Func func) 378 { 379 bool status = psMinimizeLMChi2_Alt( 380 min, 381 covar, 382 params, 383 constraint, 384 x, 385 y, 386 yWt, 387 func); 388 return status; 389 } 390 391 /****************************************************************************** 367 392 psMinimizeLMChi2(): This routine will take an procedure which calculates an 368 393 arbitrary function and it's derivative and minimize the chi-squared match … … 373 398 XXX Make an F64 version? 374 399 *****************************************************************************/ 375 bool psMinimizeLMChi2 (400 bool psMinimizeLMChi2_Old( 376 401 psMinimization *min, 377 402 psImage *covar, … … 510 535 psF32 rho = (min->value - Chisq) / dLinear; 511 536 512 psTrace("psLib.math", 5, "last chisq: %f, new chisq %f, delta: %f, dLinear: %f, rho: %f, lambda: % f, nDOF: %d\n", min->value, Chisq, min->lastDelta, dLinear, rho, lambda, nDOF);513 514 psTrace("psLib.math.dLinear", 5, "last chisq: %f, new chisq %f, delta: %f, dLinear: %f, rho: %f, lambda: % f\n", min->value, Chisq, min->lastDelta, dLinear, rho, lambda);537 psTrace("psLib.math", 5, "last chisq: %f, new chisq %f, delta: %f, dLinear: %f, rho: %f, lambda: %g, nDOF: %d\n", min->value, Chisq, min->lastDelta, dLinear, rho, lambda, nDOF); 538 539 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); 515 540 516 541 // dump some useful info if trace is defined … … 662 687 psF32 Chisq = 0.0; 663 688 psF32 lambda = 0.001; 689 psF32 nu = 2.0; 664 690 psF32 dLinear = 0.0; 665 691 … … 706 732 min->iter ++; 707 733 if (min->iter >= min->maxIter) break; 708 lambda *= 10.0; 734 // lambda *= 10.0; 735 lambda *= 2.0; 709 736 continue; 710 737 } … … 732 759 // dParDelta = Beta[i]^2 : change (squared) in parameter i 733 760 float rParSigma = 0.0; 734 for (int j = 0; j < Beta->n; j++) { 735 rParSigma += PS_SQR(Beta->data.F32[j]) / Alpha->data.F32[j][j]; 761 // for (int j = 0; j < Beta->n; j++) { 762 // rParSigma += PS_SQR(Beta->data.F32[j]) / Alpha->data.F32[j][j]; 763 // } 764 for (int j = 0, J = 0; j < Params->n; j++) { 765 if (paramMask && (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[j])) { 766 continue; 767 } 768 // fprintf (stderr, "del: %f - %f vs %f : %f\n", Params->data.F32[j], params->data.F32[j], sqrt(Alpha->data.F32[J][J]), PS_SQR(Params->data.F32[j] - params->data.F32[j]) / Alpha->data.F32[J][J]); 769 rParSigma += PS_SQR(Params->data.F32[j] - params->data.F32[j]) / Alpha->data.F32[J][J]; 770 J++; 736 771 } 737 772 rParSigma = sqrt(rParSigma); 738 773 psTrace("psLib.math", 5, "rParSigma: %f, Niter: %d\n", rParSigma, min->iter); 774 fprintf (stderr, "rParSigma: %f, Niter: %d\n", rParSigma, min->iter); 739 775 740 776 // calculate Chisq for new guess, update Alpha & Beta … … 743 779 min->iter ++; 744 780 if (min->iter >= min->maxIter) break; 745 lambda *= 10.0; 781 // lambda *= 10.0; 782 lambda *= 2.0; 746 783 continue; 747 784 } … … 753 790 psF32 rho = (min->value - Chisq) / dLinear; 754 791 755 psTrace("psLib.math", 5, "last chisq: %f, new chisq %f, delta: %f, dLinear: %f, rho: %f, lambda: % f, nDOF: %d\n", min->value, Chisq, min->lastDelta, dLinear, rho, lambda, nDOF);756 757 psTrace("psLib.math.dLinear", 5, "last chisq: %f, new chisq %f, delta: %f, dLinear: %f, rho: %f, lambda: % f\n", min->value, Chisq, min->lastDelta, dLinear, rho, lambda);792 psTrace("psLib.math", 5, "last chisq: %f, new chisq %f, delta: %f, dLinear: %f, rho: %f, lambda: %g, nDOF: %d\n", min->value, Chisq, min->lastDelta, dLinear, rho, lambda, nDOF); 793 794 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); 758 795 759 796 // dump some useful info if trace is defined … … 767 804 768 805 // rho is positive if the new chisq is smaller; allow for some insignificant change (slight negative rho) 806 807 // XXX the old version of lambda changes: 769 808 // XXX : Madsen gives suggestion for better use of rho 809 # if (0) 770 810 if (rho >= -1e-6) { 771 811 min->value = Chisq; … … 777 817 lambda *= 10.0; 778 818 } 819 # endif 820 821 // rho is positive if the new chisq is smaller 822 if (rho >= -1e-6) { 823 min->value = Chisq; 824 alpha = psImageCopy(alpha, Alpha, PS_TYPE_F32); 825 beta = psVectorCopy(beta, Beta, PS_TYPE_F32); 826 params = psVectorCopy(params, Params, PS_TYPE_F32); 827 } 828 829 # if (0) 830 // adjust the gain ratio (lambda) based on rho 831 if (rho < 0.25) { 832 lambda *= 2.0; 833 } 834 if (rho > 0.75) { 835 lambda *= 0.333; 836 } 837 # else 838 if (rho > 0.0) { 839 lambda *= PS_MAX(0.33, (1.0 - pow(2.0*rho - 1.0, 3.0))); 840 nu = 2.0; 841 } else { 842 lambda *= nu; 843 nu *= 2.0; 844 } 845 # endif 779 846 min->iter++; 780 847 … … 831 898 832 899 // if the last improvement was at least as good as maxTol, accept the fit: 900 // XXX : maybe re-work this to use rParSigma & maxTol 833 901 if (min->lastDelta <= min->maxTol) { 834 902 psTrace("psLib.math", 6, "---- end (true) ----\n"); -
branches/eam_branches/ipp-20130509/psLib/src/math/psMinimizeLMM.h
r35617 r35623 134 134 ); 135 135 136 /** Minimizes a specified function based on the Levenberg-Marquardt method. 137 * 138 * @return bool: True if successful. 139 */ 140 bool psMinimizeLMChi2_Old( 141 psMinimization *min, ///< Minimization specification 142 psImage *covar, ///< Covariance matrix 143 psVector *params, ///< "Best Guess" for the parameters that minimize func 144 psMinConstraint *constraint, ///< Constraints on the parameters 145 const psArray *x, ///< Measurement ordinates of multiple vectors 146 const psVector *y, ///< Measurement coordinates 147 const psVector *yWt, ///< Errors in the measurement coordinates 148 psMinimizeLMChi2Func func ///< Specified function 149 ); 150 136 151 /** Minimizes a specified function based on the Levenberg-Marquardt method 137 152 Uses alternative convergence criterion. -
branches/eam_branches/ipp-20130509/psLib/test/math/tap_psMinimizeLMM_Trail.c
r35618 r35623 501 501 502 502 # if (1) 503 psTraceSetLevel ("psLib.math.psMinimizeLMChi2_Alt", 5);503 // psTraceSetLevel ("psLib.math.psMinimizeLMChi2_Alt", 5); 504 504 bool tmpBool = psMinimizeLMChi2_Alt(min, NULL, params, NULL, ordinates, coordinates, errors, (psMinimizeLMChi2Func)fitFunc); 505 505 # else
Note:
See TracChangeset
for help on using the changeset viewer.
