From 3d8e4e1e2730fd4d9cdf86274134cc506385b10d Mon Sep 17 00:00:00 2001 From: Carl Philipp Klemm <philipp@uvos.xyz> Date: Tue, 30 Apr 2024 16:26:13 +0200 Subject: [PATCH] add multiply add and constant score functions --- basicmath.cpp | 28 ++++++++++++++++++++++++++++ eisgenerator/basicmath.h | 4 ++++ model.cpp | 8 ++++++++ 3 files changed, 40 insertions(+) diff --git a/basicmath.cpp b/basicmath.cpp index 53cab73..1c0c4f6 100644 --- a/basicmath.cpp +++ b/basicmath.cpp @@ -49,6 +49,12 @@ std::complex<fvalue> eis::absGrad(const std::vector<eis::DataPoint>& data, size_ std::abs((data[index+1].im.imag()-data[index-1].im.imag())/(data[index+1].omega-data[index-1].omega))); } +void mulitplyAdd(std::vector<eis::DataPoint>& data, fvalue mult, fvalue add) +{ + for(eis::DataPoint& point : data) + point.im = point.im*mult + add; +} + fvalue eis::grad(const std::vector<fvalue>& data, const std::vector<fvalue>& omega, size_t index) { assert(data.size() == omega.size()); @@ -197,6 +203,28 @@ fvalue eis::pearsonCorrelation(const std::vector<eis::DataPoint>& data) return sumDeltaReDeltaIm/(sqrt(sumDeltaReSq)*sqrt(sumDeltaImSq)); } + +fvalue eis::nonConstantScore(const std::vector<eis::DataPoint>& data) +{ + std::complex<fvalue> meanValue = mean(data); + + fvalue reDeviationMax = std::numeric_limits<fvalue>::min(); + fvalue imDeviationMax = std::numeric_limits<fvalue>::min(); + + for(const eis::DataPoint& point : data) + { + fvalue reDeviation = 1-(std::abs(point.im.real())/std::abs(meanValue.real())); + fvalue imDeviation = 1-(std::abs(point.im.imag())/std::abs(meanValue.imag())); + + if(reDeviationMax < reDeviation) + reDeviationMax = reDeviation; + if(imDeviationMax < imDeviation) + imDeviationMax = imDeviation; + } + + return std::min(reDeviationMax, imDeviationMax); +} + fvalue eis::nyquistAreaVariance(const std::vector<eis::DataPoint>& data, eis::DataPoint* centroid) { assert(data.size() > 2); diff --git a/eisgenerator/basicmath.h b/eisgenerator/basicmath.h index a05377a..23792e2 100644 --- a/eisgenerator/basicmath.h +++ b/eisgenerator/basicmath.h @@ -30,6 +30,8 @@ namespace eis * @{ */ + void mulitplyAdd(std::vector<eis::DataPoint>& data, fvalue mult, fvalue add); + /** * @brief Calculates the element wise absolute gradient at the given point of the data given. * @@ -117,6 +119,8 @@ namespace eis */ fvalue pearsonCorrelation(const std::vector<eis::DataPoint>& data); + fvalue nonConstantScore(const std::vector<eis::DataPoint>& data); + /** * @brief Calculates the variance of the distance of the data from a centroid in the nyquist plane. * diff --git a/model.cpp b/model.cpp index c172bff..6dedc7d 100644 --- a/model.cpp +++ b/model.cpp @@ -576,6 +576,14 @@ std::vector<size_t> Model::getRecommendedParamIndices(eis::Range omegaRange, dou continue; } + fvalue nonConstantess = std::abs(pearsonCorrelation(data)); + if(nonConstantess < 0.1) + { + eis::Log(eis::Log::DEBUG)<<"skipping output for step "<<i + <<" as data is too constant: "<<nonConstantess; + continue; + } + std::vector<std::vector<eis::DataPoint>>::iterator search; if(threaded) { -- GitLab