Skip to content
Snippets Groups Projects
Commit 2f67ef5c authored by Federico Lolli's avatar Federico Lolli
Browse files

[SFD] fixed eigen bugs (incorrect operators used)

parent d3ad713d
No related branches found
No related tags found
1 merge request!224Draft: Sensor Fault Detection
......@@ -22,8 +22,6 @@
// ======= Sensor Fault Detection Model (SFDAscent) =======
#pragma once
#include "SFDAscent.h"
#include <algorithms/FFT.h>
......@@ -48,17 +46,17 @@ SFDAscent::FeaturesVec SFDAscent::getFeatures(const VectorIn& input)
u = data.mean();
x0 = data - u * VectorIn::Ones();
var = x0.squaredNorm() / lenChunk;
s2 = x0.pow(2).mean();
m4 = x0.pow(4).mean();
s2 = x0.array().pow(2).mean();
m4 = x0.array().pow(4).mean();
rfourier = FFT32::fft(data); // TODO: fix complex -> float
rfourier = FFT32::fft(data).real(); // TODO: fix complex -> float
rfmean = rfourier.mean();
rfvar = (rfourier - rfmean * VectorIn::Ones()).squaredNorm() / lenChunk;
features(0) = delta;
features(1) = var;
features(2) = m4 / std::pow(s2, 2);
features(3) = data.pow(5).mean();
features(3) = data.array().pow(5).mean();
features(4) = rfvar;
features(5) = rfourier.cwiseAbs().sum();
......
......@@ -37,13 +37,13 @@ public:
static constexpr int numFeatures = 6;
static constexpr int lenChunk = 32;
using SVM = SVM<numFeatures>;
using SVMn = SVM<numFeatures>;
using FeaturesVec = Eigen::Vector<float, numFeatures>;
using VectorIn = Eigen::Vector<float, lenChunk>;
struct SFDAConfig
{
SVM::SVMConfig modelParameters;
SVMn::SVMConfig modelParameters;
};
SFDAscent(const SFDAConfig& config);
......@@ -51,7 +51,7 @@ public:
bool classify(const VectorIn& input);
private:
SVM svm;
SVMn svm;
FeaturesVec getFeatures(const VectorIn& input);
};
......
......@@ -22,8 +22,6 @@
// ======= Sensor Fault Detection Model (SFDAscent) =======
#pragma once
#include "SFDDescent.h"
namespace Boardcore
......@@ -47,9 +45,9 @@ SFDDescent::FeaturesVec SFDDescent::getFeatures(const VectorIn& input)
data(i) = (input(i) - min) / (std::max(delta, 1e-25f) * 2) - 1;
u = data.mean();
x0 = data - u * VectorIn::Ones();
s2 = x0.pow(2).mean();
m3 = x0.pow(3).mean();
m4 = x0.pow(4).mean();
s2 = x0.array().pow(2).mean();
m3 = x0.array().pow(3).mean();
m4 = x0.array().pow(4).mean();
rms = std::sqrt(s2);
features(0) = data.cwiseAbs().maxCoeff() / rms;
......
......@@ -37,13 +37,13 @@ public:
static constexpr int numFeatures = 5;
static constexpr int lenChunk = 32;
using SVM = SVM<numFeatures>;
using SVMn = SVM<numFeatures>;
using FeaturesVec = Eigen::Vector<float, numFeatures>;
using VectorIn = Eigen::Vector<float, lenChunk>;
struct SFDDConfig
{
SVM::SVMConfig modelParameters;
SVMn::SVMConfig modelParameters;
};
SFDDescent(const SFDDConfig& config);
......@@ -51,7 +51,7 @@ public:
bool classify(const VectorIn& input);
private:
SVM svm;
SVMn svm;
FeaturesVec getFeatures(const VectorIn& input);
};
......
......@@ -51,7 +51,7 @@ public:
float score(VectorD input)
{
VectorD x = input - mu;
x /= sigma;
x = x.array() / sigma.array();
return -((x / scale).dot(beta) + bias);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment