diff --git a/src/shared/algorithms/SFD/SFDAscent.cpp b/src/shared/algorithms/SFD/SFDAscent.cpp index 0ce072078faa528dc987efcd807d009e168a68a4..8842f722197175f5c80a0c8c9362e6305d56c2a8 100644 --- a/src/shared/algorithms/SFD/SFDAscent.cpp +++ b/src/shared/algorithms/SFD/SFDAscent.cpp @@ -31,11 +31,11 @@ namespace Boardcore SFDAscent::SFDAscent(const SFDAscentConfig& config) : svm(config.modelParameters) {} -SFDAscent::FeaturesVec SFDAscent::getFeatures(const VectorIn& input) +SFDAscent::FeaturesVec SFDAscent::getFeatures(const SFDVectorIn& input) { float delta, min, max, u, var, s2, m4, rfmean, rfvar; - VectorIn rfourier, x0; - VectorIn data = VectorIn::Zero(); + SFDVectorIn rfourier, x0; + SFDVectorIn data = SFDVectorIn::Zero(); FeaturesVec features = FeaturesVec::Zero(); min = input.minCoeff(); @@ -44,14 +44,14 @@ SFDAscent::FeaturesVec SFDAscent::getFeatures(const VectorIn& input) for (int i = 0; i < LEN_CHUNK; i++) data(i) = (input(i) - min) / (std::max(delta, 1e-25f) * 2) - 1; u = data.mean(); - x0 = data - u * VectorIn::Ones(); + x0 = data - u * SFDVectorIn::Ones(); var = x0.squaredNorm() / LEN_CHUNK; s2 = x0.array().pow(2).mean(); m4 = x0.array().pow(4).mean(); rfourier = FFT32::fft(data).real(); // TODO: fix complex -> float rfmean = rfourier.mean(); - rfvar = (rfourier - rfmean * VectorIn::Ones()).squaredNorm() / LEN_CHUNK; + rfvar = (rfourier - rfmean * SFDVectorIn::Ones()).squaredNorm() / LEN_CHUNK; features(0) = delta; features(1) = var; @@ -63,7 +63,7 @@ SFDAscent::FeaturesVec SFDAscent::getFeatures(const VectorIn& input) return features; } -bool SFDAscent::classify(const VectorIn& input) +bool SFDAscent::classify(const SFDVectorIn& input) { FeaturesVec features = getFeatures(input); float score = svm.score(features); diff --git a/src/shared/algorithms/SFD/SFDAscent.h b/src/shared/algorithms/SFD/SFDAscent.h index 0e3d99ce90d952a509f1753673504d0bda48132b..95f98437c244f4717581a6ad33174c2180720c0f 100644 --- a/src/shared/algorithms/SFD/SFDAscent.h +++ b/src/shared/algorithms/SFD/SFDAscent.h @@ -40,7 +40,6 @@ public: using SVMn = SVM<NUM_FEATURES>; using FeaturesVec = Eigen::Vector<float, NUM_FEATURES>; - using VectorIn = Eigen::Vector<float, LEN_CHUNK>; struct SFDAscentConfig { @@ -49,12 +48,12 @@ public: explicit SFDAscent(const SFDAscentConfig& config); - bool classify(const VectorIn& input); + bool classify(const SFDVectorIn& input); private: SVMn svm; - FeaturesVec getFeatures(const VectorIn& input); + FeaturesVec getFeatures(const SFDVectorIn& input); }; } // namespace Boardcore diff --git a/src/shared/algorithms/SFD/SFDCommon.h b/src/shared/algorithms/SFD/SFDCommon.h index 0ee8e7c7260340f78a37d4ca07a7d25e6580ca31..8c5621d438652b9de54b3d9acd727b9070bf8723 100644 --- a/src/shared/algorithms/SFD/SFDCommon.h +++ b/src/shared/algorithms/SFD/SFDCommon.h @@ -23,4 +23,13 @@ #pragma once +#include <Eigen/Core> + +namespace Boardcore +{ + static constexpr int LEN_CHUNK = 32; + +using SFDVectorIn = Eigen::Vector<float, LEN_CHUNK>; + +} // namespace Boardcore diff --git a/src/shared/algorithms/SFD/SFDDescent.cpp b/src/shared/algorithms/SFD/SFDDescent.cpp index aad11791ecba9136e5d0e4bae284cb2830301083..447d38812a3e24a1c09fbe007c5a7783451a35b7 100644 --- a/src/shared/algorithms/SFD/SFDDescent.cpp +++ b/src/shared/algorithms/SFD/SFDDescent.cpp @@ -31,11 +31,11 @@ SFDDescent::SFDDescent(const SFDDescentConfig& config) : svm(config.modelParamet { } -SFDDescent::FeaturesVec SFDDescent::getFeatures(const VectorIn& input) +SFDDescent::FeaturesVec SFDDescent::getFeatures(const SFDVectorIn& input) { float delta, min, max, u, s2, m3, m4, rms; - VectorIn rfourier, x0; - VectorIn data = VectorIn::Zero(); + SFDVectorIn rfourier, x0; + SFDVectorIn data = SFDVectorIn::Zero(); FeaturesVec features = FeaturesVec::Zero(); min = input.minCoeff(); @@ -44,7 +44,7 @@ SFDDescent::FeaturesVec SFDDescent::getFeatures(const VectorIn& input) for (int i = 0; i < LEN_CHUNK; i++) data(i) = (input(i) - min) / (std::max(delta, 1e-25f) * 2) - 1; u = data.mean(); - x0 = data - u * VectorIn::Ones(); + x0 = data - u * SFDVectorIn::Ones(); s2 = x0.array().pow(2).mean(); m3 = x0.array().pow(3).mean(); m4 = x0.array().pow(4).mean(); @@ -59,7 +59,7 @@ SFDDescent::FeaturesVec SFDDescent::getFeatures(const VectorIn& input) return features; } -bool SFDDescent::classify(const VectorIn& input) +bool SFDDescent::classify(const SFDVectorIn& input) { FeaturesVec features = getFeatures(input); float score = svm.score(features); diff --git a/src/shared/algorithms/SFD/SFDDescent.h b/src/shared/algorithms/SFD/SFDDescent.h index 90a717bce35233fd72d29d2d3dc3d3fa1837a3eb..c41a57aa3bf2d2e37573fff385429093d49e3e5a 100644 --- a/src/shared/algorithms/SFD/SFDDescent.h +++ b/src/shared/algorithms/SFD/SFDDescent.h @@ -40,7 +40,6 @@ public: using SVMn = SVM<NUM_FEATURES>; using FeaturesVec = Eigen::Vector<float, NUM_FEATURES>; - using VectorIn = Eigen::Vector<float, LEN_CHUNK>; struct SFDDescentConfig { @@ -49,12 +48,12 @@ public: explicit SFDDescent(const SFDDescentConfig& config); - bool classify(const VectorIn& input); + bool classify(const SFDVectorIn& input); private: SVMn svm; - FeaturesVec getFeatures(const VectorIn& input); + FeaturesVec getFeatures(const SFDVectorIn& input); }; } // namespace Boardcore