summaryrefslogtreecommitdiffstats
path: root/ml/SamplesBuffer.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-02-06 16:11:30 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-02-06 16:11:30 +0000
commitaa2fe8ccbfcb117efa207d10229eeeac5d0f97c7 (patch)
tree941cbdd387b41c1a81587c20a6df9f0e5e0ff7ab /ml/SamplesBuffer.cc
parentAdding upstream version 1.37.1. (diff)
downloadnetdata-aa2fe8ccbfcb117efa207d10229eeeac5d0f97c7.tar.xz
netdata-aa2fe8ccbfcb117efa207d10229eeeac5d0f97c7.zip
Adding upstream version 1.38.0.upstream/1.38.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ml/SamplesBuffer.cc')
-rw-r--r--ml/SamplesBuffer.cc63
1 files changed, 48 insertions, 15 deletions
diff --git a/ml/SamplesBuffer.cc b/ml/SamplesBuffer.cc
index d276c6e09..359b60c23 100644
--- a/ml/SamplesBuffer.cc
+++ b/ml/SamplesBuffer.cc
@@ -54,12 +54,12 @@ void SamplesBuffer::diffSamples() {
void SamplesBuffer::smoothSamples() {
// Holds the mean value of each window
- CalculatedNumber *AccCNs = new CalculatedNumber[NumDimsPerSample]();
- Sample Acc(AccCNs, NumDimsPerSample);
+ CalculatedNumber AccCNs[1] = { 0 };
+ Sample Acc(AccCNs, 1);
// Used to avoid clobbering the accumulator when moving the window
- CalculatedNumber *TmpCNs = new CalculatedNumber[NumDimsPerSample]();
- Sample Tmp(TmpCNs, NumDimsPerSample);
+ CalculatedNumber TmpCNs[1] = { 0 };
+ Sample Tmp(TmpCNs, 1);
CalculatedNumber Factor = (CalculatedNumber) 1 / SmoothN;
@@ -88,9 +88,6 @@ void SamplesBuffer::smoothSamples() {
Acc.copy(Tmp);
Acc.scale(Factor);
}
-
- delete[] AccCNs;
- delete[] TmpCNs;
}
void SamplesBuffer::lagSamples() {
@@ -103,31 +100,30 @@ void SamplesBuffer::lagSamples() {
}
}
-std::vector<DSample> SamplesBuffer::preprocess() {
+void SamplesBuffer::preprocess(std::vector<DSample> &Samples) {
assert(Preprocessed == false);
- std::vector<DSample> DSamples;
size_t OutN = NumSamples;
// Diff
if (DiffN >= OutN)
- return DSamples;
+ return;
OutN -= DiffN;
diffSamples();
// Smooth
if (SmoothN == 0 || SmoothN > OutN)
- return DSamples;
+ return;
OutN -= (SmoothN - 1);
smoothSamples();
// Lag
if (LagN >= OutN)
- return DSamples;
+ return;
OutN -= LagN;
lagSamples();
- DSamples.reserve(OutN);
+ Samples.reserve(OutN);
Preprocessed = true;
uint32_t MaxMT = std::numeric_limits<uint32_t>::max();
@@ -143,8 +139,45 @@ std::vector<DSample> SamplesBuffer::preprocess() {
const Sample PS = getPreprocessedSample(Idx);
PS.initDSample(DS);
- DSamples.push_back(DS);
+ Samples.push_back(std::move(DS));
}
+}
+
+void SamplesBuffer::preprocess(DSample &Feature) {
+ assert(Preprocessed == false);
+
+ size_t OutN = NumSamples;
+
+ // Diff
+ if (DiffN >= OutN)
+ return;
+ OutN -= DiffN;
+ diffSamples();
- return DSamples;
+ // Smooth
+ if (SmoothN == 0 || SmoothN > OutN)
+ return;
+ OutN -= (SmoothN - 1);
+ smoothSamples();
+
+ // Lag
+ if (LagN >= OutN)
+ return;
+ OutN -= LagN;
+ lagSamples();
+
+ Preprocessed = true;
+
+ uint32_t MaxMT = std::numeric_limits<uint32_t>::max();
+ uint32_t CutOff = static_cast<double>(MaxMT) * SamplingRatio;
+
+ for (size_t Idx = NumSamples - OutN; Idx != NumSamples; Idx++) {
+ if (RandNums[Idx] > CutOff)
+ continue;
+
+ Feature.set_size(NumDimsPerSample * (LagN + 1));
+
+ const Sample PS = getPreprocessedSample(Idx);
+ PS.initDSample(Feature);
+ }
}