-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstats.h
67 lines (56 loc) · 1.03 KB
/
stats.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
double sum(vector<double> a)
{
double s = 0;
for (int i = 0; i < a.size(); i++)
{
s += a[i];
}
return s;
}
double mean(vector<double> a)
{
return sum(a) / a.size();
}
double sqsum(vector<double> a)
{
double s = 0;
for (int i = 0; i < a.size(); i++)
{
s += pow(a[i], 2);
}
return s;
}
double stdev(vector<double> nums)
{
double N = nums.size();
return pow(sqsum(nums) / N - pow(sum(nums) / N, 2), 0.5);
}
vector<double> operator-(vector<double> a, double b)
{
vector<double> retvect;
for (int i = 0; i < a.size(); i++)
{
retvect.push_back(a[i] - b);
}
return retvect;
}
vector<double> operator*(vector<double> a, vector<double> b)
{
vector<double> retvect;
for (int i = 0; i < a.size() ; i++)
{
retvect.push_back(a[i] * b[i]);
}
return retvect;
}
double pearsoncoeff(vector<double> X, vector<double> Y)
{
return sum((X - mean(X))*(Y - mean(Y))) / (X.size()*stdev(X)* stdev(Y));
}