mirror of
https://github.com/aportelli/LatAnalyze.git
synced 2024-11-10 00:45:36 +00:00
CDR & NSDR
This commit is contained in:
parent
c73b609ac5
commit
1604b4712f
@ -18,6 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <LatAnalyze/Core/Math.hpp>
|
#include <LatAnalyze/Core/Math.hpp>
|
||||||
|
#include <LatAnalyze/Numerical/GslFFT.hpp>
|
||||||
#include <LatAnalyze/includes.hpp>
|
#include <LatAnalyze/includes.hpp>
|
||||||
#include <gsl/gsl_cdf.h>
|
#include <gsl/gsl_cdf.h>
|
||||||
|
|
||||||
@ -48,16 +49,42 @@ DMat MATH_NAMESPACE::corrToVar(const DMat &corr, const DVec &varDiag)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
double MATH_NAMESPACE::svdDynamicRange(const DMat &mat)
|
double MATH_NAMESPACE::conditionNumber(const DMat &mat)
|
||||||
{
|
{
|
||||||
DVec s = mat.singularValues();
|
DVec s = mat.singularValues();
|
||||||
|
|
||||||
return s.maxCoeff()/s.minCoeff();
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
|
@ -73,8 +73,9 @@ namespace MATH_NAMESPACE
|
|||||||
DMat corrToVar(const DMat &corr, const DVec &varDiag);
|
DMat corrToVar(const DMat &corr, const DVec &varDiag);
|
||||||
|
|
||||||
// matrix SVD dynamic range
|
// matrix SVD dynamic range
|
||||||
double svdDynamicRange(const DMat &mat);
|
double conditionNumber(const DMat &mat);
|
||||||
double svdDynamicRangeDb(const DMat &mat);
|
double cdr(const DMat &mat);
|
||||||
|
double nsdr(const DMat &mat);
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
constexpr double pi = 3.1415926535897932384626433832795028841970;
|
constexpr double pi = 3.1415926535897932384626433832795028841970;
|
||||||
|
@ -343,7 +343,7 @@ SampleFitResult XYSampleData::fit(std::vector<Minimizer *> &minimizer,
|
|||||||
result.nPar_ = sampleResult.getNPar();
|
result.nPar_ = sampleResult.getNPar();
|
||||||
result.nDof_ = sampleResult.nDof_;
|
result.nDof_ = sampleResult.nDof_;
|
||||||
result.parName_ = sampleResult.parName_;
|
result.parName_ = sampleResult.parName_;
|
||||||
result.corrRangeDb_ = Math::svdDynamicRangeDb(getFitCorrMat());
|
result.corrRangeDb_ = Math::cdr(getFitCorrMat());
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -358,7 +358,7 @@ FitResult XYStatData::fit(vector<Minimizer *> &minimizer, const DVec &init,
|
|||||||
result = (*m)(chi2);
|
result = (*m)(chi2);
|
||||||
totalInit = result;
|
totalInit = result;
|
||||||
}
|
}
|
||||||
result.corrRangeDb_ = Math::svdDynamicRangeDb(getFitCorrMat());
|
result.corrRangeDb_ = Math::cdr(getFitCorrMat());
|
||||||
result.chi2_ = chi2(result);
|
result.chi2_ = chi2(result);
|
||||||
result.nPar_ = nPar;
|
result.nPar_ = nPar;
|
||||||
result.nDof_ = layout.totalYSize - nPar;
|
result.nDof_ = layout.totalYSize - nPar;
|
||||||
|
@ -68,7 +68,7 @@ int main(int argc, char *argv[])
|
|||||||
var = sample.varianceMatrix();
|
var = sample.varianceMatrix();
|
||||||
corr = sample.correlationMatrix();
|
corr = sample.correlationMatrix();
|
||||||
|
|
||||||
cout << "dynamic range " << Math::svdDynamicRangeDb(corr) << " dB" << endl;
|
cout << "dynamic range " << Math::cdr(corr) << " dB" << endl;
|
||||||
p << PlotCorrMatrix(corr);
|
p << PlotCorrMatrix(corr);
|
||||||
p.display();
|
p.display();
|
||||||
if (!outVarName.empty())
|
if (!outVarName.empty())
|
||||||
|
Loading…
Reference in New Issue
Block a user