-
Notifications
You must be signed in to change notification settings - Fork 0
/
approximator2.cpp
168 lines (158 loc) · 5.29 KB
/
approximator2.cpp
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
//---------------------------------------------------------------------------
#include "approximator2.h"
//---------------------------------------------------------------------------
double Approximator2::GetParameter(const vector<point3d> &data, const string &operation)
{
double result = 0;
const int n = data.size();
for (auto index = data.begin(); index != data.end(); ++index)
{
if (operation == "AV_X1")
{
result += index->x;
}
if (operation == "AV_X2")
{
result += index->y;
}
if (operation == "AV_Y")
{
result += index->z;
}
if (operation == "SUM_X1X2")
{
const double sx1 = GetParameter(data, "AV_X1");
const double sx2 = GetParameter(data, "AV_X2");
const double v1 = index->x - sx1;
const double v2 = index->y - sx2;
result += v1 * v2;
}
if (operation == "SUM_X1Y")
{
const double sx1 = GetParameter(data, "AV_X1");
const double sy = GetParameter(data, "AV_Y");
const double v1 = index->x - sx1;
const double v2 = index->z - sy;
result += v1 * v2;
}
if (operation == "SUM_X2Y")
{
const double sx2 = GetParameter(data, "AV_X2");
const double sy = GetParameter(data, "AV_Y");
const double v1 = index->y - sx2;
const double v2 = index->z - sy;
result += v1 * v2;
}
if (operation == "SUM_X12")
{
const double sx1 = GetParameter(data, "AV_X1");
result += pow(index->x - sx1, 2);
}
if (operation == "SUM_X22")
{
const double sx2 = GetParameter(data, "AV_X2");
result += pow(index->y - sx2, 2);
}
if (operation == "SIGMA_X")
{
const double b = GetB(data);
const double b2 = GetB2(data);
const double sx1 = GetParameter(data, "AV_X1");
const double sx2 = GetParameter(data, "AV_X2");
const double v1 = (b / b2) * (index->x - sx1);
const double v2 = (b2 / b) * (index->y - sx2);
const double s = v1 + v2;
result += pow(s, 2);
}
if (operation == "SIGMA_Y")
{
const double sy = GetParameter(data, "AV_Y");
result += pow(index->z - sy, 2);
}
if (operation == "SIGMA_XY")
{
const double b = GetB(data);
const double b2 = GetB2(data);
const double sx1 = GetParameter(data, "AV_X1");
const double sx2 = GetParameter(data, "AV_X2");
const double sy = GetParameter(data, "AV_Y");
const double v1 = (b / b2) * (index->x - sx1);
const double v2 = (b2 / b) * (index->y - sx2);
const double s = v1 + v2;
result += s * (index->z - sy);
}
}
if (operation == "SIGMA_X" || operation == "SIGMA_Y" || operation == "SIGMA_XY")
{
result /= n;
result = sqrt(abs(result));
}
return result;
}
double Approximator2::GetA(const vector<point3d> &data)
{
const double sx1 = GetParameter(data, "AV_X1");
const double sx2 = GetParameter(data, "AV_X2");
const double sy = GetParameter(data, "AV_Y");
const double b = GetB(data);
const double b2 = GetB2(data);
return sy - b2 * sx1 - b * sx2;
}
double Approximator2::GetB(const vector<point3d> &data)
{
const double sx1x2 = GetParameter(data, "SUM_X1X2");
const double sx1y = GetParameter(data, "SUM_X1Y");
const double sx2y = GetParameter(data, "SUM_X2Y");
const double sx12 = GetParameter(data, "SUM_X12");
const double sx22 = GetParameter(data, "SUM_X22");
double result = sx12 * sx2y - sx1x2 * sx1y;
result /= (sx12 * sx22 - pow(sx1x2, 2));
return result;
}
double Approximator2::GetB2(const vector<point3d> &data)
{
const double sx1x2 = GetParameter(data, "SUM_X1X2");
const double sx1y = GetParameter(data, "SUM_X1Y");
const double sx2y = GetParameter(data, "SUM_X2Y");
const double sx12 = GetParameter(data, "SUM_X12");
const double sx22 = GetParameter(data, "SUM_X22");
double result = sx1y * sx22 - sx2y * sx1x2;
result /= (sx12 * sx22 - pow(sx1x2, 2));
return result;
}
double Approximator2::Delta(const vector<point3d> &data1, const vector<point3d> &data2)
{
double result = 0;
const int n = data1.size();
for (int index = 0; index < n; index++)
{
if (data1[index].z != 0)
{
result += 100 * abs(data1[index].z - data2[index].z) / data1[index].z;
}
}
result /= n;
return result;
}
double Approximator2::Sigma(const vector<point3d> &data)
{
double result = 0;
const int n = data.size();
const double a = GetA(data);
const double b = GetB(data);
const double b2 = GetB2(data);
for (const auto& index : data)
{
result += pow(index.z - a - b * index.x - b2 * index.y, 2);
}
result /= n;
result = sqrt(abs(result));
return result;
}
double Approximator2::Correlation(const vector<point3d> &data)
{
double result = pow(GetParameter(data, "SIGMA_XY"), 2);
result /= GetParameter(data, "SIGMA_X");
result /= GetParameter(data, "SIGMA_Y");
return result;
}