diff --git a/lib/LatAnalyze/Physics/DataFilter.hpp b/lib/LatAnalyze/Physics/DataFilter.hpp index 9bc45df..16a1d0b 100644 --- a/lib/LatAnalyze/Physics/DataFilter.hpp +++ b/lib/LatAnalyze/Physics/DataFilter.hpp @@ -54,6 +54,9 @@ private: ******************************************************************************/ class LaplaceDataFilter: public DataFilter { +public: + template + using ObjectiveFunction = std::function &)>; public: // constructor LaplaceDataFilter(const bool downsample = false); @@ -63,10 +66,11 @@ public: template void operator()(StatArray &out, const StatArray &in, const double lambda = 0.); - // correlation optimisation + // metric optimisation template - double optimiseCdr(const StatArray &data, Minimizer &min, - const unsigned int nPass = 3); + double optimiseFunction(const StatArray &data, + ObjectiveFunction &fn, + Minimizer &min, const unsigned int nPass = 3); }; /****************************************************************************** @@ -98,28 +102,26 @@ void LaplaceDataFilter::operator()(StatArray &out, // correlation optimisation /////////////////////////////////////////////////// template -double LaplaceDataFilter::optimiseCdr(const StatArray &data, - Minimizer &min, const unsigned int nPass) +double LaplaceDataFilter::optimiseFunction(const StatArray &data, + ObjectiveFunction &fn, + Minimizer &min, + const unsigned int nPass) { StatArray fdata(data.size()); DVec init(1); double reg, prec; - DoubleFunction cdr([&data, &fdata, this](const double *x) + DoubleFunction fnReg([&data, &fdata, &fn, this](const double *x) { double res; (*this)(fdata, data, x[0]); - res = Math::cdr(fdata.correlationMatrix()); + res = fn(fdata); return res; }, 1); - min.setLowLimit(0., -0.1); - min.setHighLimit(0., 100000.); - init(0) = 0.1; - min.setInit(init); prec = 0.1; min.setPrecision(prec); - reg = min(cdr)(0); + reg = min(fnReg)(0); for (unsigned int pass = 0; pass < nPass; pass++) { min.setLowLimit(0., (1.-10.*prec)*reg); @@ -128,7 +130,7 @@ double LaplaceDataFilter::optimiseCdr(const StatArray &data, min.setInit(init); prec *= 0.1; min.setPrecision(prec); - reg = min(cdr)(0); + reg = min(fnReg)(0); } return reg;