- Timestamp:
- Jan 11, 2015, 2:05:35 PM (12 years ago)
- Location:
- branches/eam_branches/ipp-20140904
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
psLib/src/math/psMinimizePolyFit.c (modified) (5 diffs, 1 prop)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20140904
- Property svn:mergeinfo changed
-
branches/eam_branches/ipp-20140904/psLib/src/math/psMinimizePolyFit.c
- Property svn:mergeinfo set to
r36296 r37804 700 700 701 701 // Define values that may be used by PS_POLYNOMIAL_ORD form. 702 // these scaling values put the dynamic range of the data into some vaguely sensible location 702 703 bool scale = false; 704 bool median_zero = false; 703 705 double median = 0.0; 704 706 double sigma = 1.0; 705 psVector *sorted = NULL; 706 psVector *z64 = NULL; 707 707 708 708 switch (poly->type) { 709 709 case PS_POLYNOMIAL_ORD: 710 710 if ((f64->n < 10000)&&(poly->nX > 1)) { 711 711 scale = true; 712 sorted = psVectorSort(NULL,x64); 712 713 // generate a subset of the unmasked values: 714 psVector *tmp = psVectorAllocEmpty (x64->n, PS_TYPE_F64); 715 for (int itmp = 0; itmp < x64->n; itmp++) { 716 if (mask && (mask->data.PS_TYPE_VECTOR_MASK_DATA[itmp] && maskValue)) continue; 717 psVectorAppend (tmp, x64->data.F64[itmp]); 718 } 719 psVector *sorted = psVectorSort(NULL,tmp); 713 720 median = sorted->data.F64[sorted->n / 2]; 714 721 // CZW: I'm not bothering to scale this because it doesn't really matter. 715 722 sigma = (sorted->data.F64[3 * sorted->n / 4] - sorted->data.F64[sorted->n / 4]); 716 723 psFree(sorted); 724 psFree(tmp); 717 725 718 726 if ((!isfinite(median))|| … … 721 729 sigma = 1.0; 722 730 } 723 if ((median == 0.0)&&(sigma == 1.0)) { 724 scale = false; 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)||(fabs(sigma) <= 1e-10)) { 736 // Don't bother scaling if sigma is unity (it's already scaled) or if the sigma calculation has gone wrong. 737 scale = false; 738 } 725 739 } 740 726 741 // I can't see a way to not clobber x if it's already F64, so make a copy.x 727 z64 = psVectorCopy(NULL,x64,PS_TYPE_F64);742 psVector *z64 = psVectorCopy(NULL,x64,PS_TYPE_F64); 728 743 psBinaryOp(z64,z64,"-",psScalarAlloc(median,PS_TYPE_F64)); 729 744 psBinaryOp(z64,z64,"/",psScalarAlloc(sigma,PS_TYPE_F64)); … … 733 748 #endif 734 749 735 736 750 result = VectorFitPolynomial1DOrd(poly, mask, maskValue, f64, fErr64, z64); 737 751 psFree(z64); // Done with this. … … 758 772 #endif 759 773 } 774 760 775 for (psS32 i = 0; i <= poly->nX; i++) { 761 776 poly->coeff[i] = 0.0; 762 777 poly->coeffErr[i] = 0.0; 763 764 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++) { 765 784 #if (CZW) 766 printf(" %d %d %f %f %f %f => %f\n",767 i,j,Zcoeff[j],768 pow(1.0 / sigma,j) * pow(-1,j - i),769 pow(median,j - i),770 1.0 * psBinomialCoeff(j,i),771 Zcoeff[j] * pow(1.0 / sigma,j) * pow(-1,j -i) * pow(median,j - i) * 1.0 * psBinomialCoeff(j,i)772 );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 ); 773 792 #endif 774 poly->coeff[i] += Zcoeff[j] * pow(1.0 / sigma,j) * pow(-1,j - i) * pow(median,j - i) * psBinomialCoeff(j,i); 775 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]); 776 797 } 777 poly->coeffErr[i] = sqrt(poly->coeffErr[i]);778 798 #if (CZW) 779 799 printf("poly1d: unscaled parameters: %d %f %f\n", … … 784 804 psFree(ZcoeffErr); 785 805 786 } 806 } // End scaling block. 787 807 788 808 break;
Note:
See TracChangeset
for help on using the changeset viewer.
