1
0
mirror of https://github.com/aportelli/LatAnalyze.git synced 2024-11-10 00:45:36 +00:00

CDR & NSDR

This commit is contained in:
Antonin Portelli 2024-01-12 14:21:39 +01:00
parent c73b609ac5
commit 1604b4712f
5 changed files with 36 additions and 8 deletions

View File

@ -18,6 +18,7 @@
*/
#include <LatAnalyze/Core/Math.hpp>
#include <LatAnalyze/Numerical/GslFFT.hpp>
#include <LatAnalyze/includes.hpp>
#include <gsl/gsl_cdf.h>
@ -48,16 +49,42 @@ DMat MATH_NAMESPACE::corrToVar(const DMat &corr, const DVec &varDiag)
return res;
}
double MATH_NAMESPACE::svdDynamicRange(const DMat &mat)
double MATH_NAMESPACE::conditionNumber(const DMat &mat)
{
DVec s = mat.singularValues();
return s.maxCoeff()/s.minCoeff();
}
double MATH_NAMESPACE::svdDynamicRangeDb(const DMat &mat)
double MATH_NAMESPACE::cdr(const DMat &mat)
{
return 10.*log10(svdDynamicRange(mat));
return 10.*log10(conditionNumber(mat));
}
template <typename FFT>
double nsdr(const DMat &m)
{
Index n = m.rows();
FFT fft(n);
CMat buf(n, 1);
FOR_VEC(buf, i)
{
buf(i) = 0.;
for (Index j = 0; j < n; ++j)
{
buf(i) += m(j, (i+j) % n);
}
buf(i) /= n;
}
fft(buf, FFT::Forward);
return 10.*log10(buf.real().maxCoeff()/buf.real().minCoeff());
}
double MATH_NAMESPACE::nsdr(const DMat &mat)
{
return ::nsdr<GslFFT>(mat);
}
/******************************************************************************

View File

@ -73,8 +73,9 @@ namespace MATH_NAMESPACE
DMat corrToVar(const DMat &corr, const DVec &varDiag);
// matrix SVD dynamic range
double svdDynamicRange(const DMat &mat);
double svdDynamicRangeDb(const DMat &mat);
double conditionNumber(const DMat &mat);
double cdr(const DMat &mat);
double nsdr(const DMat &mat);
// Constants
constexpr double pi = 3.1415926535897932384626433832795028841970;

View File

@ -343,7 +343,7 @@ SampleFitResult XYSampleData::fit(std::vector<Minimizer *> &minimizer,
result.nPar_ = sampleResult.getNPar();
result.nDof_ = sampleResult.nDof_;
result.parName_ = sampleResult.parName_;
result.corrRangeDb_ = Math::svdDynamicRangeDb(getFitCorrMat());
result.corrRangeDb_ = Math::cdr(getFitCorrMat());
return result;
}

View File

@ -358,7 +358,7 @@ FitResult XYStatData::fit(vector<Minimizer *> &minimizer, const DVec &init,
result = (*m)(chi2);
totalInit = result;
}
result.corrRangeDb_ = Math::svdDynamicRangeDb(getFitCorrMat());
result.corrRangeDb_ = Math::cdr(getFitCorrMat());
result.chi2_ = chi2(result);
result.nPar_ = nPar;
result.nDof_ = layout.totalYSize - nPar;

View File

@ -68,7 +68,7 @@ int main(int argc, char *argv[])
var = sample.varianceMatrix();
corr = sample.correlationMatrix();
cout << "dynamic range " << Math::svdDynamicRangeDb(corr) << " dB" << endl;
cout << "dynamic range " << Math::cdr(corr) << " dB" << endl;
p << PlotCorrMatrix(corr);
p.display();
if (!outVarName.empty())