-
Notifications
You must be signed in to change notification settings - Fork 0
/
SStatics.h
66 lines (54 loc) · 1.65 KB
/
SStatics.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
/* SWTL SStatics.h
* Brief: Provides some basic statics templates and functions.
* Copyright (c) SHEN WeiHong 2016.
* Version 1.000
*/
#ifndef STATICS_H_INCLUDED
#define STATICS_H_INCLUDED
#include<cmath>
#include"SNumeric.h"
template<class Iter1, class Iter2> class LeastSquaredMethod
{
public:
LeastSquaredMethod(Iter1 xIterFirst, Iter1 xIterLast, Iter2 yIterFirst){
Iter2 yIter=yIterFirst;
averX=0;
averY=0;
xSD=0;
ySD=0;
double sumXTY=0, sumXSQ=0, sumYSQ=0;
N=0;
double sumDxDy=0;
for(Iter1 xIter=xIterFirst;xIter!=xIterLast;++xIter){
averX+=*xIter;
averY+=*yIter;
N++;
sumXTY+=(*xIter)*(*yIter);
sumXSQ+=(*xIter)*(*xIter);
sumYSQ+=(*yIter)*(*yIter);
++yIter;
}
coeA=(N*sumXTY-averX*averY)/(-averX*averX+N*sumXSQ);
averX/=(double)N;
averY/=(double)N;
yIter=yIterFirst;
xSD=pow(sumXSQ/N-averX*averX,.5);
ySD=pow(sumYSQ/N-averY*averY,.5);
coeCorre=(sumXTY/N-averX*averY)/xSD/ySD;
xSD*=pow(N/(N-1),.5);
xSD*=pow(N/(N-1),.5);
}
double coeCorre;
double averX;
double averY;
double coeA;
double coeB;
double xSD;
double ySD;
int N;
};
double Gauss(double x);
double GaussRand();
double ChiSquareDistribution(int freeDegree, double x);
double MTCL_ChiSquareDistribution(int freeDegree, double x);
#endif // STATICS_H_INCLUDED