Changeset 2228 for trunk/psLib/src/math/psStats.c
- Timestamp:
- Oct 28, 2004, 12:47:00 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/math/psStats.c (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/math/psStats.c
r2227 r2228 9 9 * @author GLG, MHPCC 10 10 * 11 * @version $Revision: 1. 79$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-10-28 00:46:04$13 n*11 * @version $Revision: 1.80 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-10-28 22:46:57 $ 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 15 15 */ … … 123 123 default: 124 124 return false; 125 }126 }127 128 /*****************************************************************************129 p_psVectorPrint(myVector, maskVector, maskVal, stats): a private internal130 function that simply prints a vector to STDOUT. Used primarily for131 debugging.132 *****************************************************************************/133 134 void p_psVectorPrint(psVector* myVector, psVector* maskVector, psU32 maskVal, psStats* stats)135 {136 psS32 i = 0; // Loop index variable.137 138 for (i = 0; i < myVector->n; i++) {139 if (maskVector != NULL)140 printf("Element %d is %f (mask is %d)\n", i, myVector->data.F32[i], maskVector->data.U8[i]);141 else142 printf("Element %d is %f\n", i, myVector->data.F32[i]);143 125 } 144 126 } … … 428 410 // Allocate temporary vectors for the data. 429 411 unsortedVector = psVectorAlloc(nValues, PS_TYPE_F32); 430 unsortedVector->n = unsortedVector->nalloc;431 432 412 sortedVector = psVectorAlloc(nValues, PS_TYPE_F32); 433 sortedVector->n = sortedVector->nalloc;434 413 435 414 // Determine if we must only use data points within a min/max range. … … 579 558 // Allocate temporary vectors for the data. 580 559 unsortedVector = psVectorAlloc(nValues, PS_TYPE_F32); 581 unsortedVector->n = unsortedVector->nalloc;582 560 sortedVector = psVectorAlloc(nValues, PS_TYPE_F32); 583 sortedVector->n = sortedVector->nalloc;584 561 585 562 // Determine if we must only use data points within a min/max range. … … 817 794 p_psNormalizeVectorF32(myData): this is a private function which normalizes the 818 795 elements of a vector to a range between 0.0 and 1.0. 796 797 XXX: how about an arbitrary p_psNormalizeVectorF32(myData, min, max)? 819 798 *****************************************************************************/ 820 799 void p_psNormalizeVectorF32(psVector* myData) … … 847 826 elements of a vector to a range between -1.0 and 1.0. 848 827 XXX: 0-1 or -1:1? 828 829 XXX: how about an arbitrary p_psNormalizeVectorF64(myData, min, max)? 849 830 *****************************************************************************/ 850 831 void p_psNormalizeVectorF64(psVector* myData) … … 876 857 } 877 858 859 // XXX: how about an arbitrary p_psNormalizeVector(myData, min, max)? 878 860 void p_psNormalizeVector(psVector* myData) 879 861 { … … 885 867 psError(__func__, "Unalowable data type.\n"); 886 868 } 887 }888 889 /*****************************************************************************890 p_psGaussian(myData, myParams): an internal function, used by robust stats,891 intended to compute the Gaussian with a specified sigma/mean, at the892 specified data point.893 *****************************************************************************/894 float p_psGaussian(const psVector* restrict myData,895 const psVector* restrict myParams)896 {897 float x = myData->data.F32[0];898 float mean = myParams->data.F32[0];899 float stdev = myParams->data.F32[1];900 float tmp = exp(-((x - mean) * (x - mean)) / (2.0 * stdev * stdev));901 902 tmp /= ((float)sqrt(2.0 * M_PI * (stdev * stdev)));903 904 // printf("p_psGaussian((%.2f), %.2f, %.2f) is %.2f\n", x, mean, stdev, tmp);905 return (tmp);906 }907 908 /*****************************************************************************909 p_psGaussianDeriv(myData, myParams, whichParam): an internal function, which910 calculates the specified partial derivative of the above Gaussian function.911 *****************************************************************************/912 float p_psGaussianDeriv(const psVector* restrict myData,913 const psVector* restrict myParams, psS32 whichParam)914 {915 float x = myData->data.F32[0];916 float mean = myParams->data.F32[0];917 float stdev = myParams->data.F32[1];918 float tmp = 0.0;919 920 if (whichParam == 0) {921 // Return the derivative w.r.t. the mean.922 tmp = (x - mean) * p_psGaussian(myData, myParams);923 tmp /= (stdev * stdev);924 } else if (whichParam == 1) {925 // Return the derivative w.r.t. the stdev.926 tmp = (x - mean) * (x - mean) * p_psGaussian(myData, myParams);927 tmp /= (stdev * stdev * stdev);928 }929 printf("p_psGaussianDeriv((%.2f), %.2f, %.2f, (%d)) is %.2f\n", x, mean, stdev, whichParam, tmp);930 931 return (tmp);932 }933 934 /*****************************************************************************935 p_psQuadratic(myData, myParams): an internal function, used by robust stats,936 intended to compute a quadratic, with the specified parameters, at the937 specified data point.938 *****************************************************************************/939 float p_psQuadratic(const psVector* restrict myParams, const psVector* restrict myCoords)940 {941 float x = myCoords->data.F32[0];942 float A = myParams->data.F32[0];943 float B = myParams->data.F32[1];944 float C = myParams->data.F32[2];945 float tmp = 0.0;946 947 tmp = (A * x * x) + (B * x) + C;948 return (tmp);949 }950 951 /*****************************************************************************952 p_psQuadraticDeriv(myData, myParams, whichParam): an internal function, which953 calculates the specified partial derivative of the above quadratic function.954 *****************************************************************************/955 float p_psQuadraticDeriv(const psVector* restrict myParams,956 const psVector* restrict myCoords, psS32 whichParamDeriv)957 {958 float x = myCoords->data.F32[0];959 float tmp = 0.0;960 961 if (whichParamDeriv == 0) {962 tmp = x * x;963 } else if (whichParamDeriv == 1) {964 tmp = x;965 } else if (whichParamDeriv == 2) {966 tmp = 1.0;967 }968 969 return (tmp);970 869 } 971 870 … … 1022 921 and i+1 is used for x[i]). It then determines for what value x does that 1023 922 quadratic f(x) = yVal (the input parameter). 1024 1025 // XXX: Use static variables.1026 923 *****************************************************************************/ 1027 924 float fitQuadraticSearchForYThenReturnX(psVector *xVec, … … 1030 927 float yVal) 1031 928 { 1032 // static psVector* x = NULL; 1033 // static psVector* y = NULL; 1034 // static psVector* yErr = NULL; 1035 psVector* x = psVectorAlloc(3, PS_TYPE_F64); 1036 psVector* y = psVectorAlloc(3, PS_TYPE_F64); 1037 psVector* yErr = psVectorAlloc(3, PS_TYPE_F64); 1038 1039 /* 1040 if (x == NULL) { 1041 x = psVectorAlloc(3, PS_TYPE_F64); 1042 p_psMemSetPersistent(x, true); 1043 } 1044 if (y == NULL) { 1045 y = psVectorAlloc(3, PS_TYPE_F64); 1046 p_psMemSetPersistent(y, true); 1047 } 1048 if (yErr == NULL) { 1049 yErr = psVectorAlloc(3, PS_TYPE_F64); 1050 p_psMemSetPersistent(yErr, true); 1051 } 1052 */ 1053 psPolynomial1D* myPoly = psPolynomial1DAlloc(2, PS_POLYNOMIAL_ORD); 929 PS_VECTOR_DECLARE_ALLOC_STATIC(x, 3, PS_TYPE_F64); 930 PS_VECTOR_DECLARE_ALLOC_STATIC(y, 3, PS_TYPE_F64); 931 PS_VECTOR_DECLARE_ALLOC_STATIC(yErr, 3, PS_TYPE_F64); 932 static psPolynomial1D* myPoly = NULL; 933 934 if (myPoly == NULL) { 935 myPoly = psPolynomial1DAlloc(2, PS_POLYNOMIAL_ORD); 936 p_psMemSetPersistent(myPoly, true); 937 } 1054 938 float tmpFloat; 1055 939 … … 1090 974 } 1091 975 1092 psFree(x);1093 psFree(y);1094 psFree(yErr);1095 psFree(myPoly);1096 976 return(tmpFloat); 1097 977 } … … 1475 1355 1476 1356 /****************************************************************************** 1477 psHistogramAllocGen ric(bounds): allocate a non-uniform histogram structure1357 psHistogramAllocGeneric(bounds): allocate a non-uniform histogram structure 1478 1358 with the specifed bounds. 1479 1359
Note:
See TracChangeset
for help on using the changeset viewer.
