Changeset 37515
- Timestamp:
- Oct 21, 2014, 2:51:52 PM (12 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/math/psMinimizePolyFit.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/math/psMinimizePolyFit.c
r37510 r37515 702 702 // these scaling values put the dynamic range of the data into some vaguely sensible location 703 703 bool scale = false; 704 bool median_zero = false; 704 705 double median = 0.0; 705 706 double sigma = 1.0; … … 728 729 sigma = 1.0; 729 730 } 730 if ((median == 0.0)&&(sigma == 1.0)) { 731 scale = false; 732 } 733 734 if (median == 0.0) { 735 if (sigma <= 0.0) { 736 scale = false; // Try with what we started with. 737 } 738 else { 739 median = 0.1 * sigma; 731 if (fabs(median) < 1e-10) { 732 // CZW 2014-10-21: This median is small and close to zero. This can cause issues with the 733 // scaling, 734 median_zero = true; 735 if ((sigma == 1.0)||(sigma <= 0.0)) { 736 // Don't bother scaling if sigma is unity (it's already scaled) or if the sigma calculation has gone wrong. 737 scale = false; 740 738 } 741 739 } … … 774 772 #endif 775 773 } 774 776 775 for (psS32 i = 0; i <= poly->nX; i++) { 777 776 poly->coeff[i] = 0.0; 778 777 poly->coeffErr[i] = 0.0; 779 780 for (psS32 j = 0; j <= poly->nX; j++) { 778 if (median_zero) { // If the median is zero, the obtained solution just needs to be scaled by the sigma values. 779 poly->coeff[i] = Zcoeff[i] * pow(1.0 / sigma,i); 780 poly->coeffErr[i] = ZcoeffErr[i] * pow(1.0 / sigma,i); 781 } 782 else { // Otherwise, do the correct transformations by expanding the (x-m)/s terms. 783 for (psS32 j = 0; j <= poly->nX; j++) { 781 784 #if (CZW) 782 printf(" %d %d %f %f %f %f => %f\n",783 i,j,Zcoeff[j],784 pow(1.0 / sigma,j) * pow(-1,j - i),785 pow(median,j - i),786 1.0 * psBinomialCoeff(j,i),787 Zcoeff[j] * pow(1.0 / sigma,j) * pow(-1,j -i) * pow(median,j - i) * 1.0 * psBinomialCoeff(j,i)788 );785 printf(" %d %d %f %f %f %f => %f\n", 786 i,j,Zcoeff[j], 787 pow(1.0 / sigma,j) * pow(-1,j - i), 788 pow(median,j - i), 789 1.0 * psBinomialCoeff(j,i), 790 Zcoeff[j] * pow(1.0 / sigma,j) * pow(-1,j -i) * pow(median,j - i) * 1.0 * psBinomialCoeff(j,i) 791 ); 789 792 #endif 790 poly->coeff[i] += Zcoeff[j] * pow(1.0 / sigma,j) * pow(-1,j - i) * pow(median,j - i) * psBinomialCoeff(j,i); 791 poly->coeffErr[i] += pow(ZcoeffErr[j] * pow(1.0 / sigma,j) * pow(-1,j - i) * pow(median,j - 1) * psBinomialCoeff(j,i),2); 793 poly->coeff[i] += Zcoeff[j] * pow(1.0 / sigma,j) * pow(-1,j - i) * pow(median,j - i) * psBinomialCoeff(j,i); 794 poly->coeffErr[i] += pow(ZcoeffErr[j] * pow(1.0 / sigma,j) * pow(-1,j - i) * pow(median,j - 1) * psBinomialCoeff(j,i),2); 795 } 796 poly->coeffErr[i] = sqrt(poly->coeffErr[i]); 792 797 } 793 poly->coeffErr[i] = sqrt(poly->coeffErr[i]);794 798 #if (CZW) 795 799 printf("poly1d: unscaled parameters: %d %f %f\n", … … 800 804 psFree(ZcoeffErr); 801 805 802 } 806 } // End scaling block. 803 807 804 808 break;
Note:
See TracChangeset
for help on using the changeset viewer.
