diff --git a/mathFunctions/basicMath.cpp b/mathFunctions/basicMath.cpp index 450dc42b7..f3c936c3d 100644 --- a/mathFunctions/basicMath.cpp +++ b/mathFunctions/basicMath.cpp @@ -456,11 +456,11 @@ // remove nodata list.erase(std::remove(list.begin(), list.end(), float(NODATA)), list.end()); - // sort - std::sort(list.begin(), list.end()); - // check on data presence if (list.size() < MINIMUM_PERCENTILE_DATA) return NODATA; + + // sort + std::sort(list.begin(), list.end()); } float nrValuesF = float(list.size()); @@ -475,13 +475,13 @@ if (isEqual(value, list[i])) { float rank = float(i + 1) / nrValuesF; - return rank * 100; + return rank * 100.f; } if (i < lastIndex && list[i] < value && list[i+1] > value) { float rank = float(i + 1) / nrValuesF; rank += (value - list[i]) / (list[i+1] - list[i]) / nrValuesF; - return rank * 100; + return rank * 100.f; } } diff --git a/mathFunctions/commonConstants.h b/mathFunctions/commonConstants.h index 579ee44c2..57d82f31d 100644 --- a/mathFunctions/commonConstants.h +++ b/mathFunctions/commonConstants.h @@ -223,16 +223,16 @@ // --------------------MATH--------------------- #ifndef PI - #define PI 3.141592653589793238462643383 + #define PI 3.1415926535898 #endif #ifndef EPSILON - #define EPSILON 0.0000001 + #define EPSILON 0.000001 #endif #define EULER 2.718281828459 #define DEG_TO_RAD 0.0174532925 #define RAD_TO_DEG 57.2957795 #define SQRT_2 1.41421356237 - #define GOLDEN_SECTION 1.6180339887498948482 + #define GOLDEN_SECTION 1.6180339887499 #define MINIMUM_PERCENTILE_DATA 3 diff --git a/mathFunctions/furtherMathFunctions.cpp b/mathFunctions/furtherMathFunctions.cpp index 2bc50e14b..fbb8660a1 100644 --- a/mathFunctions/furtherMathFunctions.cpp +++ b/mathFunctions/furtherMathFunctions.cpp @@ -99,13 +99,13 @@ double lapseRatePiecewise_three_noSlope(double x, std::vector & par) } } -/* +/*! * The following three functions are only used for the height proxy when the multiple detrending check is enabled. * One function among these three (lapseRatePiecewise_two, _three and _three_free) is selected by the user and used to * look for the fitting parameters with the Marquardt algorithm. -*/ + */ -/* +/*! * functions for MARQUARDT use */ @@ -275,7 +275,6 @@ double harmonicsFourierGeneral(double x, double* par,int nrPar) } - namespace integration { /*! this is a set for function integrations by means of the Simpson */ @@ -1263,8 +1262,7 @@ namespace interpolation return sqrt(MSE); } - /* - * + /*! * * MARQUARDT FUNCTIONS * in the following order: @@ -1274,14 +1272,14 @@ namespace interpolation * */ - /* - * - * BEST FITTING MARQUARDT - * + /*! + * BEST FITTING MARQUARDT */ - // bestFittingMarquardt for ELEVATION fitting with WEIGHTS (local detrending) + /*! bestFittingMarquardt for ELEVATION + * fitting with WEIGHTS (local detrending) + */ double bestFittingMarquardt_nDimension(double (*func)(double, std::vector&), int nrMinima, std::vector & parametersMin, std::vector & parametersMax, @@ -1351,8 +1349,10 @@ namespace interpolation return bestR2; } - // bestFittingMarquardt for ELEVATION fitting with NO weights (glocal and multiple detrending) + /*! bestFittingMarquardt for ELEVATION + * fitting with NO weights (glocal and multiple detrending) + */ double bestFittingMarquardt_nDimension(double (*func)(double, std::vector&), int nrMinima, std::vector & parametersMin, std::vector & parametersMax, @@ -1430,11 +1430,14 @@ namespace interpolation parametersDelta,maxIterationsNr, myEpsilon,x,y); } + return bestR2; } - //bestFittingMarquardt for linear proxies (all but elevation proxy), with WEIGHTS (all multiple detrending options) + /*! bestFittingMarquardt for linear proxies (all but elevation proxy) + * with WEIGHTS (all multiple detrending options) + */ int bestFittingMarquardt_nDimension(double (*func)(std::vector&)>>&, std::vector& , std::vector >&), std::vector&)>>& myFunc, std::vector >& parametersMin, std::vector >& parametersMax, @@ -1477,13 +1480,15 @@ namespace interpolation { ySim[i]= func(myFunc,x[i], parameters); } - double R2 = computeWeighted_R2(y,ySim,weights); + //double R2 = computeWeighted_R2(y,ySim,weights); return 1; } - //bestFittingMarquardt for linear proxies (all but elevation proxy), with NO weights (currently unused) + /*! bestFittingMarquardt for linear proxies (all but elevation proxy) + * with NO weights (currently unused) + */ int bestFittingMarquardt_nDimension(double (*func)(std::vector&)>>&, std::vector& , std::vector >&), std::vector&)>>& myFunc, std::vector >& parametersMin, std::vector >& parametersMax, @@ -1500,6 +1505,7 @@ namespace interpolation nrParameters[i]= int(parameters[i].size()); nrParametersTotal += nrParameters[i]; } + std::vector > bestParameters(parameters.size()); std::vector > correspondenceTag(2,std::vector(nrParametersTotal)); int counterTag = 0; @@ -1530,14 +1536,15 @@ namespace interpolation return 1; } - /* + /*! * * FITTING MARQUARDT * */ - //fittingMarquardt called in bestFittingMarquardt, with least squares function. currently unused - + /*! fittingMarquardt called in bestFittingMarquardt + * with least squares function. currently unused + */ bool fittingMarquardt_nDimension_withSquares(double (*func)(std::vector&)>>&, std::vector& , std::vector >&), std::vector &)> >& myFunc, std::vector > ¶metersMin, std::vector > ¶metersMax, @@ -1631,8 +1638,11 @@ namespace interpolation return (fabs(diffSSE) <= myEpsilon); } - //fittingMarquardt called in bestFittingMarquardt for linear proxies (all but elevation proxy), with WEIGHTS (all multiple detrending options) + /*! + * fittingMarquardt called in bestFittingMarquardt for linear proxies (all but elevation proxy) + * with WEIGHTS (all multiple detrending options) + */ bool fittingMarquardt_nDimension(double (*func)(std::vector&)>>&, std::vector& , std::vector >&), std::vector &)> >& myFunc, std::vector > ¶metersMin, std::vector > ¶metersMax, @@ -1841,8 +1851,11 @@ namespace interpolation return (fabs(diffSSE) <= myEpsilon); } - //fittingMarquardt (called inside bestFittingMarquardt) without least squares function, for ELEVATION only, with WEIGHTS (local detrending) + /*! + * fittingMarquardt (called inside bestFittingMarquardt) without least squares function + * for ELEVATION only, with WEIGHTS (local detrending) + */ bool fittingMarquardt_nDimension(double (*func) (double, std::vector&), std::vector ¶metersMin, std::vector ¶metersMax, std::vector ¶meters, std::vector ¶metersDelta, @@ -2009,8 +2022,11 @@ namespace interpolation return (fabs(diffSSE) <= myEpsilon); } - //fittingMarquardt (called inside bestFittingMarquardt) without least squares function, for ELEVATION only, with NO WEIGHTS (multiple and glocal detrending) + /*! + * fittingMarquardt (called inside bestFittingMarquardt) without least squares function + * for ELEVATION only, with NO WEIGHTS (multiple and glocal detrending) + */ bool fittingMarquardt_nDimension(double (*func) (double, std::vector&), std::vector ¶metersMin, std::vector ¶metersMax, std::vector ¶meters, std::vector ¶metersDelta,