Skip to content

[ML] Don't try and correct for sample count when estimating statistic variances for anomaly detection #2677

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions include/core/CSmallVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,17 @@ class CSmallVector : public boost::container::small_vector<T, N> {
return *this;
}

std::string toDelimited(const std::string& delimiter = ", ") const {
std::string result;
for (size_type i = 0; i < this->size(); ++i) {
result += std::to_string((*this)[i]);
if (i < this->size() - 1) {
result += delimiter;
}
}
return result;
}

private:
TBase& baseRef() { return *this; }
const TBase& baseRef() const { return *this; }
Expand Down
6 changes: 6 additions & 0 deletions include/maths/common/CBasicStatisticsPersist.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <core/CHashing.h>
#include <core/CLogger.h>
#include <core/CSmallVector.h>
#include <core/CStringUtils.h>

#include <maths/common/CBasicStatistics.h>
Expand Down Expand Up @@ -99,6 +100,11 @@ template<typename T>
inline std::string typeToString(const CSymmetricMatrix<T>& value) {
return value.toDelimited();
}

template<typename T, std::size_t N>
inline std::string typeToString(const core::CSmallVector<T, N>& value) {
return value.toDelimited();
}
}

template<typename T, unsigned int ORDER>
Expand Down
8 changes: 8 additions & 0 deletions include/model/CMetricStatGatherer.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,14 @@ using TMinGatherer = CStatGatherer<TMinAccumulator, CLastTime>;
using TMaxGatherer = CStatGatherer<TMaxAccumulator, CLastTime>;
using TVarianceGatherer = CStatGatherer<TVarianceAccumulator, CMeanTime>;

template<typename STAT, typename TIME>
std::ostream& operator<<(std::ostream& os, const CStatGatherer<STAT, TIME>& statGatherer) {
os << "CStatGatherer(dim=" << statGatherer.dimension() << ", value="
<< maths::common::basic_statistics_detail::typeToString(statGatherer.value())
<< ", count=" << statGatherer.count()
<< ", varianceScale=" << statGatherer.varianceScale() << ")";
return os;
}
} // metric_stat_gatherer_detail::

//! \brief Bucket metric statistic gatherer.
Expand Down
5 changes: 5 additions & 0 deletions include/model/CMetricStatShims.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ class CSumAccumulator {
double m_Sum{0.0};
};

inline std::ostream& operator<<(std::ostream& os, const CSumAccumulator& acc) {
os << "CSumAccumulator(" << acc.toDelimited() << ")";
return os;
}

namespace metric_stat_shims {
using TDouble1Vec = core::CSmallVector<double, 1>;
using TMeanAccumulator = maths::common::CBasicStatistics::SSampleMean<double>::TAccumulator;
Expand Down