Skip to content

Commit

Permalink
Merge commit '05d4582ec85e0695cb1176ca6d75f73d87400a19'
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomei committed Jan 28, 2025
2 parents 3535b07 + 05d4582 commit 108b7cb
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 29 deletions.
10 changes: 5 additions & 5 deletions agrolib/mathFunctions/basicMath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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;
}
}

Expand Down
6 changes: 3 additions & 3 deletions agrolib/mathFunctions/commonConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
58 changes: 37 additions & 21 deletions agrolib/mathFunctions/furtherMathFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ double lapseRatePiecewise_three_noSlope(double x, std::vector <double>& 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
*/

Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -1263,8 +1262,7 @@ namespace interpolation
return sqrt(MSE);
}

/*
*
/*!
*
* MARQUARDT FUNCTIONS
* in the following order:
Expand All @@ -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<double>&),
int nrMinima,
std::vector <double>& parametersMin, std::vector <double>& parametersMax,
Expand Down Expand Up @@ -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<double>&),
int nrMinima,
std::vector <double>& parametersMin, std::vector <double>& parametersMax,
Expand Down Expand Up @@ -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::function<double(double, std::vector<double>&)>>&, std::vector<double>& , std::vector <std::vector <double>>&),
std::vector<std::function<double(double, std::vector<double>&)>>& myFunc,
std::vector <std::vector <double>>& parametersMin, std::vector <std::vector <double>>& parametersMax,
Expand Down Expand Up @@ -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::function<double(double, std::vector<double>&)>>&, std::vector<double>& , std::vector <std::vector <double>>&),
std::vector<std::function<double(double, std::vector<double>&)>>& myFunc,
std::vector <std::vector <double>>& parametersMin, std::vector <std::vector <double>>& parametersMax,
Expand All @@ -1500,6 +1505,7 @@ namespace interpolation
nrParameters[i]= int(parameters[i].size());
nrParametersTotal += nrParameters[i];
}

std::vector <std::vector <double>> bestParameters(parameters.size());
std::vector <std::vector <int>> correspondenceTag(2,std::vector<int>(nrParametersTotal));
int counterTag = 0;
Expand Down Expand Up @@ -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::function<double(double, std::vector<double>&)>>&, std::vector<double>& , std::vector <std::vector <double>>&),
std::vector<std::function<double (double, std::vector<double> &)> >& myFunc,
std::vector<std::vector<double> > &parametersMin, std::vector<std::vector<double> > &parametersMax,
Expand Down Expand Up @@ -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::function<double(double, std::vector<double>&)>>&, std::vector<double>& , std::vector <std::vector <double>>&),
std::vector<std::function<double (double, std::vector<double> &)> >& myFunc,
std::vector<std::vector<double> > &parametersMin, std::vector<std::vector<double> > &parametersMax,
Expand Down Expand Up @@ -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<double>&),
std::vector<double> &parametersMin, std::vector<double> &parametersMax,
std::vector<double> &parameters, std::vector<double> &parametersDelta,
Expand Down Expand Up @@ -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<double>&),
std::vector<double> &parametersMin, std::vector<double> &parametersMax,
std::vector<double> &parameters, std::vector<double> &parametersDelta,
Expand Down

0 comments on commit 108b7cb

Please sign in to comment.