2022-07-05 19:02:59 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#ifndef utils_h
|
|
|
|
#define utils_h
|
|
|
|
|
|
|
|
#include <Eigen/Dense>
|
|
|
|
#include <iostream>
|
|
|
|
|
2022-07-06 23:33:12 +08:00
|
|
|
#define DEBUG 0
|
2022-07-05 19:02:59 +08:00
|
|
|
#define INF 1e9
|
|
|
|
#define CHANNEL_NUMBER 4096
|
|
|
|
|
2022-07-06 23:33:12 +08:00
|
|
|
using namespace std;
|
2022-07-05 19:02:59 +08:00
|
|
|
using std::string;
|
|
|
|
using std::to_string;
|
|
|
|
|
2022-07-06 23:33:12 +08:00
|
|
|
double dataMax(std::vector<double> data) {
|
|
|
|
double x, m = -INF;
|
|
|
|
for (int i = 0; i < data.size(); i++) {
|
|
|
|
x = data.at(i);
|
|
|
|
m = std::max(m, x);
|
|
|
|
}
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
|
|
|
double dataAvg(std::vector<double> data) {
|
|
|
|
double m = 0;
|
|
|
|
for (int i = 0; i < data.size(); i++) m += data.at(i);
|
|
|
|
return m / data.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
double dataStd(std::vector<double> data) {
|
|
|
|
double m = 0;
|
|
|
|
double mu = dataAvg(data);
|
|
|
|
for (int i = 0; i < data.size(); i++) m += std::pow(data.at(i) - mu, 2);
|
|
|
|
return m / (data.size() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
double dataMax2D(std::vector<Eigen::Vector2d> data) {
|
2022-07-05 19:02:59 +08:00
|
|
|
double m = -INF;
|
|
|
|
for (int i = 0; i < data.size(); i++) {
|
|
|
|
Eigen::Vector2d &point = data.at(i);
|
|
|
|
m = std::max(m, point(1));
|
|
|
|
}
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
2022-07-06 23:33:12 +08:00
|
|
|
double dataAvg2D(std::vector<Eigen::Vector2d> data) {
|
2022-07-05 19:02:59 +08:00
|
|
|
int n = 0;
|
|
|
|
double m = 0;
|
|
|
|
for (int i = 0; i < data.size(); i++) {
|
|
|
|
Eigen::Vector2d &point = data.at(i);
|
|
|
|
n += point(1);
|
|
|
|
m += point(0) * point(1);
|
|
|
|
}
|
|
|
|
return m / n;
|
|
|
|
}
|
|
|
|
|
2022-07-06 23:33:12 +08:00
|
|
|
double dataStd2D(std::vector<Eigen::Vector2d> data) {
|
2022-07-05 19:02:59 +08:00
|
|
|
int n = 0;
|
|
|
|
double m = 0;
|
2022-07-06 23:33:12 +08:00
|
|
|
double mu = dataAvg2D(data);
|
2022-07-05 19:02:59 +08:00
|
|
|
for (int i = 0; i < data.size(); i++) {
|
|
|
|
Eigen::Vector2d &point = data.at(i);
|
|
|
|
n += point(1);
|
|
|
|
m += std::pow(point(0) - mu, 2) * point(1);
|
|
|
|
}
|
|
|
|
return std::sqrt(m / (n - 1));
|
|
|
|
}
|
|
|
|
|
2022-07-06 23:33:12 +08:00
|
|
|
double dataMax2DInd(std::vector<Eigen::Vector2d> data) {
|
|
|
|
double x = 0, m = -INF;
|
|
|
|
for (int i = 0; i < data.size(); i++) {
|
|
|
|
Eigen::Vector2d &point = data.at(i);
|
|
|
|
if (point(1) > m) {
|
|
|
|
x = point(0);
|
|
|
|
m = point(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
double dataStd2DSQRT(std::vector<Eigen::Vector2d> data) { return std::sqrt(dataMax2D(data)); }
|
|
|
|
|
2022-07-05 19:02:59 +08:00
|
|
|
string rmString(string str, string substr) {
|
|
|
|
int pos;
|
|
|
|
int len = substr.length();
|
|
|
|
while (true) {
|
|
|
|
pos = str.find(substr);
|
|
|
|
if (pos < 0) break;
|
|
|
|
str.erase(pos, len);
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|