@@ -144,43 +144,55 @@ double ratio(double numerator, double denominator, double zeroDividedByZero) {
144
144
return numerator / denominator;
145
145
}
146
146
147
+ // Functions to compute influence based on different criteria
147
148
// ! \brief Computes the value of summed statistics on the set difference.
148
149
class CValueDifference {
149
150
public:
150
151
// ! Features.
151
- void operator ()(const TDouble2Vec& v,
152
+ bool operator ()(const TDouble2Vec& v,
152
153
double n,
153
154
const TDouble1Vec& vi,
154
155
double ni,
155
156
maths::CModelProbabilityParams& params,
156
157
TDouble2Vec& difference) const {
158
+ if (n < ni) {
159
+ return false ;
160
+ }
161
+
157
162
for (std::size_t i = 0u ; i < v.size (); ++i) {
158
163
difference[i] = v[i] - vi[i];
159
164
}
160
165
params.addBucketEmpty ({n == ni});
166
+
167
+ return true ;
161
168
}
162
169
163
170
// ! Correlates.
164
- void operator ()(const TDouble2Vec& v,
171
+ bool operator ()(const TDouble2Vec& v,
165
172
const TDouble2Vec& n,
166
173
const TDouble1Vec& vi,
167
174
const TDouble1Vec& ni,
168
175
maths::CModelProbabilityParams& params,
169
176
TDouble2Vec& difference) const {
177
+ if (n < ni) {
178
+ return false ;
179
+ }
170
180
TBool2Vec bucketEmpty (2 );
171
181
for (std::size_t i = 0u ; i < v.size (); ++i) {
172
182
bucketEmpty[i] = ((n[i] - ni[i]) == 0 );
173
183
difference[i] = v[i] - vi[i];
174
184
}
175
185
params.addBucketEmpty (bucketEmpty);
186
+
187
+ return true ;
176
188
}
177
189
};
178
190
179
191
// ! \brief Computes the value of min, max, dc, etc on the set intersection.
180
192
class CValueIntersection {
181
193
public:
182
194
// ! Features.
183
- void operator ()(const TDouble2Vec& /* v*/ ,
195
+ bool operator ()(const TDouble2Vec& /* v*/ ,
184
196
double /* n*/ ,
185
197
const TDouble1Vec& vi,
186
198
double ni,
@@ -190,34 +202,50 @@ class CValueIntersection {
190
202
intersection[i] = vi[i];
191
203
}
192
204
params.addBucketEmpty ({ni == 0 });
205
+
206
+ return true ;
193
207
}
194
208
195
209
// ! Correlates.
196
- void operator ()(const TDouble2Vec& /* v*/ ,
210
+ bool operator ()(const TDouble2Vec& /* v*/ ,
197
211
const TDouble2Vec& /* n*/ ,
198
212
const TDouble1Vec& vi,
199
213
const TDouble1Vec& ni,
200
214
maths::CModelProbabilityParams& params,
201
215
TDouble2Vec& intersection) const {
216
+
202
217
TBool2Vec bucketEmpty (2 );
203
218
for (std::size_t i = 0u ; i < vi.size (); ++i) {
204
219
bucketEmpty[i] = (ni[i] == 0 );
205
220
intersection[i] = vi[i];
206
221
}
207
222
params.addBucketEmpty (bucketEmpty);
223
+
224
+ return true ;
208
225
}
209
226
};
210
227
211
228
// ! \brief Computes the value of the mean statistic on a set difference.
212
229
class CMeanDifference {
213
230
public:
214
231
// ! Features.
215
- void operator ()(const TDouble2Vec& v,
232
+ // !
233
+ // ! \param[in] v overall mean
234
+ // ! \param[in] n overall count
235
+ // ! \param[in] vi influencer mean
236
+ // ! \param[in] ni influencer count
237
+ // ! \param[out] params model parameters to be updated
238
+ // ! \param[out] difference computed mean difference
239
+ bool operator ()(const TDouble2Vec& v,
216
240
double n,
217
241
const TDouble1Vec& vi,
218
242
double ni,
219
243
maths::CModelProbabilityParams& params,
220
244
TDouble2Vec& difference) const {
245
+ if (n <= ni) {
246
+ return false ;
247
+ }
248
+
221
249
for (std::size_t d = 0u ; d < v.size (); ++d) {
222
250
difference[d] = maths::CBasicStatistics::mean (
223
251
maths::CBasicStatistics::accumulator (n, v[d]) -
@@ -226,15 +254,21 @@ class CMeanDifference {
226
254
maths_t::multiplyCountVarianceScale (TDouble2Vec (v.size (), n / (n - ni)),
227
255
params.weights ()[0 ]);
228
256
params.addBucketEmpty ({n == ni});
257
+
258
+ return true ;
229
259
}
230
260
231
261
// ! Correlates.
232
- void operator ()(const TDouble2Vec& v,
262
+ bool operator ()(const TDouble2Vec& v,
233
263
const TDouble2Vec& n,
234
264
const TDouble1Vec& vi,
235
265
const TDouble1Vec& ni,
236
266
maths::CModelProbabilityParams& params,
237
267
TDouble2Vec& difference) const {
268
+ if (n <= ni) {
269
+ return false ;
270
+ }
271
+
238
272
TBool2Vec bucketEmpty (2 );
239
273
for (std::size_t d = 0u ; d < 2 ; ++d) {
240
274
bucketEmpty[d] = ((n[d] - ni[d]) == 0 );
@@ -246,19 +280,31 @@ class CMeanDifference {
246
280
TDouble2Vec{n[0 ] / (n[0 ] - ni[0 ]), n[1 ] / (n[1 ] - ni[1 ])},
247
281
params.weights ()[0 ]);
248
282
params.addBucketEmpty (bucketEmpty);
283
+
284
+ return true ;
249
285
}
250
286
};
251
287
252
288
// ! \brief Computes the value of the variance statistic on a set difference.
253
289
class CVarianceDifference {
254
290
public:
255
291
// ! Features.
256
- void operator ()(const TDouble1Vec& v,
292
+ // !
293
+ // ! \param[in] v overall variance and mean
294
+ // ! \param[in] n overall count
295
+ // ! \param[in] vi influencer variance and mean
296
+ // ! \param[in] ni influencer count
297
+ // ! \param[out] params model parameters to be updated
298
+ // ! \param[out] difference computed mean difference
299
+ bool operator ()(const TDouble1Vec& v,
257
300
double n,
258
301
const TDouble1Vec& vi,
259
302
double ni,
260
303
maths::CModelProbabilityParams& params,
261
304
TDouble2Vec& difference) const {
305
+ if (n < ni) {
306
+ return false ;
307
+ }
262
308
std::size_t dimension = v.size () / 2 ;
263
309
for (std::size_t d = 0u ; d < dimension; ++d) {
264
310
difference[d] = maths::CBasicStatistics::maximumLikelihoodVariance (
@@ -268,15 +314,20 @@ class CVarianceDifference {
268
314
maths_t::multiplyCountVarianceScale (TDouble2Vec (dimension, n / (n - ni)),
269
315
params.weights ()[0 ]);
270
316
params.addBucketEmpty ({n == ni});
317
+
318
+ return true ;
271
319
}
272
320
273
321
// ! Correlates.
274
- void operator ()(const TDouble2Vec& v,
322
+ bool operator ()(const TDouble2Vec& v,
275
323
const TDouble2Vec& n,
276
324
const TDouble1Vec& vi,
277
325
const TDouble1Vec& ni,
278
326
maths::CModelProbabilityParams& params,
279
327
TDouble2Vec& difference) const {
328
+ if (n < ni) {
329
+ return false ;
330
+ }
280
331
TBool2Vec bucketEmpty (2 );
281
332
for (std::size_t d = 0u ; d < 2 ; ++d) {
282
333
bucketEmpty[d] = ((n[d] - ni[d]) == 0 );
@@ -288,6 +339,8 @@ class CVarianceDifference {
288
339
maths_t::multiplyCountVarianceScale (
289
340
TDouble2Vec{n[0 ] / (n[0 ] - ni[0 ]), n[1 ] / (n[1 ] - ni[1 ])},
290
341
params.weights ()[0 ]);
342
+
343
+ return true ;
291
344
}
292
345
};
293
346
@@ -370,8 +423,14 @@ void doComputeInfluences(model_t::EFeature feature,
370
423
for (auto i = influencerValues.begin (); i != influencerValues.end (); ++i) {
371
424
params.weights (weights).updateAnomalyModel (false );
372
425
373
- computeInfluencedValue (value, count, i->second .first , i->second .second ,
374
- params, influencedValue[0 ]);
426
+ if (computeInfluencedValue (value, count, i->second .first , i->second .second ,
427
+ params, influencedValue[0 ]) == false ) {
428
+ LOG_ERROR (<< " Failed to compute influencer value (value = " << value
429
+ << " , count = " << count
430
+ << " , influencer value = " << i->second .first
431
+ << " , influencer count = " << i->second .second << " )" );
432
+ continue ;
433
+ }
375
434
376
435
double pi;
377
436
bool conditional;
0 commit comments