1
0
mirror of https://github.com/aportelli/LatAnalyze.git synced 2025-06-20 08:16:55 +01:00

2 Commits

Author SHA1 Message Date
3bf3e15def ask for C++17 support 2024-03-11 13:40:42 +09:00
79ca0069c5 less rigid filter optimisation 2024-03-11 13:40:21 +09:00
2 changed files with 17 additions and 15 deletions

View File

@ -13,7 +13,7 @@ include(FindPackageMessage)
include(GNUInstallDirs)
# C++ compile flags
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_EXTENSIONS OFF)
check_cxx_compiler_flag("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE)
@ -29,7 +29,7 @@ set(CMAKE_CXX_FLAGS_RELWITHDEBINFO
"-O3 -g -DNDEBUG ${MARCH_FLAG} ${MTUNE_FLAG}")
set(gcc_like_cxx "$<COMPILE_LANG_AND_ID:CXX,ARMClang,AppleClang,Clang,GNU,LCC>")
add_library(compiler_flags INTERFACE)
target_compile_features(compiler_flags INTERFACE cxx_std_14)
target_compile_features(compiler_flags INTERFACE cxx_std_17)
target_compile_options(
compiler_flags
INTERFACE "$<${gcc_like_cxx}:-Wall;-Wextra;-Wshadow;-Wformat=2;-Wunused>")

View File

@ -54,6 +54,9 @@ private:
******************************************************************************/
class LaplaceDataFilter: public DataFilter
{
public:
template <typename MatType, Index o>
using ObjectiveFunction = std::function<double(const StatArray<MatType, o> &)>;
public:
// constructor
LaplaceDataFilter(const bool downsample = false);
@ -63,10 +66,11 @@ public:
template <typename MatType, Index o>
void operator()(StatArray<MatType, o> &out, const StatArray<MatType, o> &in,
const double lambda = 0.);
// correlation optimisation
// metric optimisation
template <typename MatType, Index o>
double optimiseCdr(const StatArray<MatType, o> &data, Minimizer &min,
const unsigned int nPass = 3);
double optimiseFunction(const StatArray<MatType, o> &data,
ObjectiveFunction<MatType, o> &fn,
Minimizer &min, const unsigned int nPass = 3);
};
/******************************************************************************
@ -98,28 +102,26 @@ void LaplaceDataFilter::operator()(StatArray<MatType, o> &out,
// correlation optimisation ///////////////////////////////////////////////////
template <typename MatType, Index o>
double LaplaceDataFilter::optimiseCdr(const StatArray<MatType, o> &data,
Minimizer &min, const unsigned int nPass)
double LaplaceDataFilter::optimiseFunction(const StatArray<MatType, o> &data,
ObjectiveFunction<MatType, o> &fn,
Minimizer &min,
const unsigned int nPass)
{
StatArray<MatType, o> 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<MatType, o> &data,
min.setInit(init);
prec *= 0.1;
min.setPrecision(prec);
reg = min(cdr)(0);
reg = min(fnReg)(0);
}
return reg;