1 #ifndef NPSTAT_LORPEWEIGHTSLOCALCONVERGENCE_HH_
2 #define NPSTAT_LORPEWEIGHTSLOCALCONVERGENCE_HH_
23 const double i_normPower,
24 const bool i_useDensity)
26 normPower_(i_normPower),
27 checkConVergenceForDensity_(i_useDensity)
30 assert(normPower_ > 0.0);
33 inline double tol()
const {
return tol_;}
34 inline double normPower()
const {
return normPower_;}
35 inline bool checkingConVergenceForDensity()
const
36 {
return checkConVergenceForDensity_;}
39 inline bool converged(
const Lorpe& lorpe,
40 const double* previousWeights,
41 const double* currentWeights,
42 const double* previousBg,
43 const double* currentBg)
const
45 if (checkConVergenceForDensity_)
46 return locallyConverged(lorpe, previousBg, currentBg);
48 return locallyConverged(lorpe, previousWeights, currentWeights);
53 inline bool locallyConverged(
const Lorpe& lorpe,
54 const double* previous,
55 const double* current)
const
60 const auto& sample = lorpe.coords();
61 const unsigned long sampleSize = sample.size();
63 long double sum = 0.0L, wsum = 0.0L;
65 for (
unsigned long i=0; i<sampleSize; ++i)
67 const double w = lorpe.cvLocalizingWeight(sample[i].first);
72 const double ac = std::abs(current[i]);
73 const double ap = std::abs(previous[i]);
74 const double d = std::abs(current[i] - previous[i])*2.0/(ac + ap + 1.0);
75 if (normPower_ == 1.0)
77 else if (normPower_ == 2.0)
80 p = std::pow(d, normPower_);
86 const double weightedDiff = sum/wsum;
87 const double norm = std::pow(weightedDiff, 1.0/normPower_);
93 bool checkConVergenceForDensity_;
Definition: LOrPEWeightsLocalConvergence.hh:20
Definition: AbsArrayProjector.hh:14