summaryrefslogtreecommitdiffstats
path: root/ml/SamplesBuffer.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-02-06 16:11:34 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-02-06 16:11:34 +0000
commitd079b656b4719739b2247dcd9d46e9bec793095a (patch)
treed2c950c70a776bcf697c963151c5bd959f8a9f03 /ml/SamplesBuffer.cc
parentReleasing debian version 1.37.1-2. (diff)
downloadnetdata-d079b656b4719739b2247dcd9d46e9bec793095a.tar.xz
netdata-d079b656b4719739b2247dcd9d46e9bec793095a.zip
Merging upstream version 1.38.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--ml/SamplesBuffer.cc63
1 files changed, 48 insertions, 15 deletions
diff --git a/ml/SamplesBuffer.cc b/ml/SamplesBuffer.cc
index d276c6e0..359b60c2 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);
+ }
}