43 lines
933 B
C++
43 lines
933 B
C++
#ifndef __utils__
|
|
#define __utils__
|
|
|
|
#include <cmath>
|
|
#include <vector>
|
|
|
|
template <typename T>
|
|
std::vector<T> cutArrs(std::vector<T> &Arrs, int begin, int end) {
|
|
std::vector<T> result;
|
|
result.assign(Arrs.begin() + begin, Arrs.begin() + end);
|
|
return result;
|
|
}
|
|
|
|
template <typename T>
|
|
double average(T x, int len) {
|
|
double sum = 0;
|
|
for (int i = 0; i < len; i++) sum += x[i];
|
|
return sum / len;
|
|
}
|
|
|
|
template <typename T>
|
|
double variance(T x, int len) {
|
|
double sum = 0;
|
|
double avg = average(x, len);
|
|
for (int i = 0; i < len; i++) sum += pow(x[i] - avg, 2);
|
|
return sum / len;
|
|
}
|
|
|
|
template <typename T>
|
|
double standardDev(T x, int len) {
|
|
double var = variance(x, len);
|
|
return sqrt(var);
|
|
}
|
|
|
|
template <typename T>
|
|
double maxBias(T x, int len) {
|
|
double res = -1;
|
|
double avg = average(x, len);
|
|
for (int i = 0; i < len; i++) res = std::max(res, abs(avg - x[i]));
|
|
return res;
|
|
}
|
|
|
|
#endif |