From a654785ac31d3d773f89e9782548f365d25b7bd2 Mon Sep 17 00:00:00 2001 From: Josh Bendavid Date: Fri, 18 Sep 2015 19:51:30 +0200 Subject: [PATCH 1/2] more robust protection against infinite loops --- RecoLocalCalo/EcalRecAlgos/src/PulseChiSqSNNLS.cc | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/RecoLocalCalo/EcalRecAlgos/src/PulseChiSqSNNLS.cc b/RecoLocalCalo/EcalRecAlgos/src/PulseChiSqSNNLS.cc index 114c2aa4c9a7c..259cfcc1bed6b 100644 --- a/RecoLocalCalo/EcalRecAlgos/src/PulseChiSqSNNLS.cc +++ b/RecoLocalCalo/EcalRecAlgos/src/PulseChiSqSNNLS.cc @@ -302,6 +302,7 @@ bool PulseChiSqSNNLS::NNLS() { int iter = 0; Index idxwmax = 0; double wmax = 0.0; + double threshold = 1e-11; //work = PulseVector::zeros(); while (true) { //can only perform this step if solution is guaranteed viable @@ -316,7 +317,12 @@ bool PulseChiSqSNNLS::NNLS() { wmax = updatework.tail(nActive).maxCoeff(&idxwmax); //convergence - if (wmax<1e-11 || (idxwmax==idxwmaxprev && wmax==wmaxprev)) break; + if (wmax=500) { + edm::LogWarning("PulseChiSqSNNLS::NNLS()") << "Max Iterations reached at iter " << iter << std::endl; + } //unconstrain parameter Index idxp = _nP + idxwmax; @@ -384,6 +390,12 @@ bool PulseChiSqSNNLS::NNLS() { --_nP; } ++iter; + + //adaptive convergence threshold to avoid infinite loops but still + //ensure best value is used + if (iter%50==0) { + threshold *= 10.; + } } return true; From 690d7da8f47ca590b580163ea872f76faa844dd3 Mon Sep 17 00:00:00 2001 From: Josh Bendavid Date: Fri, 18 Sep 2015 20:32:29 +0200 Subject: [PATCH 2/2] add missing break statement to final protection --- RecoLocalCalo/EcalRecAlgos/src/PulseChiSqSNNLS.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/RecoLocalCalo/EcalRecAlgos/src/PulseChiSqSNNLS.cc b/RecoLocalCalo/EcalRecAlgos/src/PulseChiSqSNNLS.cc index 259cfcc1bed6b..62162524d2212 100644 --- a/RecoLocalCalo/EcalRecAlgos/src/PulseChiSqSNNLS.cc +++ b/RecoLocalCalo/EcalRecAlgos/src/PulseChiSqSNNLS.cc @@ -322,6 +322,7 @@ bool PulseChiSqSNNLS::NNLS() { //worst case protection if (iter>=500) { edm::LogWarning("PulseChiSqSNNLS::NNLS()") << "Max Iterations reached at iter " << iter << std::endl; + break; } //unconstrain parameter