-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calculation.h
executable file
·49 lines (35 loc) · 1.32 KB
/
Calculation.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifndef FASTMCD2_CALCULATION_H
#define FASTMCD2_CALCULATION_H
#include "matrix.h"
#include "Cholesky.h"
#include <vector>
#include <algorithm>
using namespace std;
// Template for most essential calculation functions in whole process
// T can be replaced by all the type of numbers to reduce dependencies of code
template <typename T> class Calculations {
private:
QSMatrix<T> data;
public:
Calculations(QSMatrix<T> d) {data = d;};
~Calculations() {};
vector<T> mean_col(QSMatrix<T> &m);
QSMatrix<T> covariance(vector<T> &mean, QSMatrix<T> &m);
QSMatrix<T> transposeMultiply(vector<T> &v);
vector<T> mahDistance(vector<T> &mean, QSMatrix<T> &cov);
T mahProduct(vector<T> ¢ered, QSMatrix<T> &inversecov);
QSMatrix<T> Cstep(QSMatrix<T> &Hold, int h);
T median(vector<T> &v);
// Sort vector value and get sorted index
static vector<size_t> sort_indexes(const vector<T> &v) {
// initialize original index locations
vector<size_t> idx(v.size());
for (size_t i = 0; i != idx.size(); ++i) idx[i] = i;
// sort indexes based on comparing values in v
sort(idx.begin(), idx.end(),
[&v](size_t i1, size_t i2) {return v[i1] < v[i2];});
return idx;
}
};
#include "Calculation.cpp"
#endif //FASTMCD2_CALCULATION_H