Skip to content

Commit 33db7ba

Browse files
authored
[6.5][ML] Fixes potentials for SIGSEGV in multivariate probability calculation (#172)
Backport of #170.
1 parent a061835 commit 33db7ba

File tree

6 files changed

+216
-157
lines changed

6 files changed

+216
-157
lines changed

docs/CHANGELOG.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Persist and restore was missing some of the trend model state ({pull}#99[#99])
4848
Stop zero variance data generating a log error in the forecast confidence interval calculation ({pull}#107[#107])
4949
Fix corner case failing to calculate lgamma values and the correspoinding log errors ({pull}#126[#126])
5050
Influence count per bucket for metric population analyses was wrong and lead to wrong influencer scoring ({pull}#150[#150])
51+
Fix a possible SIGSEGV for jobs with multivariate by fields enabled which would lead to the job failing ({pull}#170[#170])
5152

5253
=== Regressions
5354

include/maths/CTimeSeriesModel.h

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,23 @@ class MATHS_EXPORT CUnivariateTimeSeriesModel : public CModel {
247247

248248
//! Reinitialize state after detecting a new component of the trend
249249
//! decomposition.
250-
void reinitializeStateGivenNewComponent(void);
250+
void reinitializeStateGivenNewComponent();
251+
252+
//! Compute the probability for uncorrelated series.
253+
bool uncorrelatedProbability(const CModelProbabilityParams& params,
254+
const TTime2Vec1Vec& time,
255+
const TDouble2Vec1Vec& value,
256+
double& probability,
257+
TTail2Vec& tail) const;
258+
259+
//! Compute the probability for correlated series.
260+
bool correlatedProbability(const CModelProbabilityParams& params,
261+
const TTime2Vec1Vec& time,
262+
const TDouble2Vec1Vec& value,
263+
double& probability,
264+
TTail2Vec& tail,
265+
bool& conditional,
266+
TSize1Vec& mostAnomalousCorrelate) const;
251267

252268
//! Get the models for the correlations and the models of the correlated
253269
//! time series.
@@ -458,9 +474,12 @@ class MATHS_EXPORT CTimeSeriesCorrelations {
458474
//! Add the time series identified by \p id.
459475
void addTimeSeries(std::size_t id, const CUnivariateTimeSeriesModel& model);
460476

461-
//! Remove the correlates of \p id.
477+
//! Remove the time series identified by \p id.
462478
void removeTimeSeries(std::size_t id);
463479

480+
//! Clear all correlation information for time series identified \p id.
481+
void clearCorrelationModels(std::size_t id);
482+
464483
//! Add a sample for the time series identified by \p id.
465484
void addSamples(std::size_t id,
466485
const CModelAddSamplesParams& params,

lib/maths/CMultimodalPrior.cc

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ bool CMultimodalPrior::acceptRestoreTraverser(const SDistributionRestoreParams&
139139
this->numberSamples(numberSamples))
140140
} while (traverser.next());
141141

142-
if (m_Clusterer) {
142+
if (m_Clusterer != nullptr) {
143143
// Register the split and merge callbacks.
144144
m_Clusterer->splitFunc(CModeSplitCallback(*this));
145145
m_Clusterer->mergeFunc(CModeMergeCallback(*this));
@@ -150,11 +150,13 @@ bool CMultimodalPrior::acceptRestoreTraverser(const SDistributionRestoreParams&
150150

151151
CMultimodalPrior::CMultimodalPrior(const CMultimodalPrior& other)
152152
: CPrior(other.dataType(), other.decayRate()),
153-
m_Clusterer(other.m_Clusterer->clone()),
154-
m_SeedPrior(other.m_SeedPrior->clone()) {
153+
m_Clusterer(other.m_Clusterer != nullptr ? other.m_Clusterer->clone() : nullptr),
154+
m_SeedPrior(other.m_SeedPrior != nullptr ? other.m_SeedPrior->clone() : nullptr) {
155155
// Register the split and merge callbacks.
156-
m_Clusterer->splitFunc(CModeSplitCallback(*this));
157-
m_Clusterer->mergeFunc(CModeMergeCallback(*this));
156+
if (m_Clusterer != nullptr) {
157+
m_Clusterer->splitFunc(CModeSplitCallback(*this));
158+
m_Clusterer->mergeFunc(CModeMergeCallback(*this));
159+
}
158160

159161
// Clone all the modes up front so we can implement strong exception safety.
160162
TModeVec modes;
@@ -182,10 +184,14 @@ void CMultimodalPrior::swap(CMultimodalPrior& other) {
182184
// The call backs for split and merge should point to the
183185
// appropriate priors (we don't swap the "this" pointers
184186
// after all). So we need to refresh them after swapping.
185-
m_Clusterer->splitFunc(CModeSplitCallback(*this));
186-
m_Clusterer->mergeFunc(CModeMergeCallback(*this));
187-
other.m_Clusterer->splitFunc(CModeSplitCallback(other));
188-
other.m_Clusterer->mergeFunc(CModeMergeCallback(other));
187+
if (m_Clusterer != nullptr) {
188+
m_Clusterer->splitFunc(CModeSplitCallback(*this));
189+
m_Clusterer->mergeFunc(CModeMergeCallback(*this));
190+
}
191+
if (other.m_Clusterer != nullptr) {
192+
other.m_Clusterer->splitFunc(CModeSplitCallback(other));
193+
other.m_Clusterer->mergeFunc(CModeMergeCallback(other));
194+
}
189195

190196
std::swap(m_SeedPrior, other.m_SeedPrior);
191197
m_Modes.swap(other.m_Modes);

lib/maths/CMultivariateOneOfNPrior.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <maths/Constants.h>
2424

2525
#include <boost/bind.hpp>
26+
#include <boost/make_unique.hpp>
2627
#include <boost/numeric/conversion/bounds.hpp>
2728
#include <boost/ref.hpp>
2829

@@ -438,7 +439,7 @@ CMultivariateOneOfNPrior::univariate(const TSize10Vec& marginalize,
438439
models[i].first *= std::exp(weights[i] - maxWeight[0]) / Z;
439440
}
440441

441-
return {TUnivariatePriorPtr(new COneOfNPrior(models, this->dataType(), this->decayRate())),
442+
return {boost::make_unique<COneOfNPrior>(models, this->dataType(), this->decayRate()),
442443
maxWeight.count() > 0 ? maxWeight[0] : 0.0};
443444
}
444445

@@ -471,8 +472,8 @@ CMultivariateOneOfNPrior::bivariate(const TSize10Vec& marginalize,
471472
models[i].first *= std::exp(weights[i] - maxWeight[0]) / Z;
472473
}
473474

474-
return {TPriorPtr(new CMultivariateOneOfNPrior(2, models, this->dataType(),
475-
this->decayRate())),
475+
return {boost::make_unique<CMultivariateOneOfNPrior>(2, models, this->dataType(),
476+
this->decayRate()),
476477
maxWeight.count() > 0 ? maxWeight[0] : 0.0};
477478
}
478479

0 commit comments

Comments
 (0)