-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompareData.cpp
More file actions
97 lines (88 loc) · 1.9 KB
/
CompareData.cpp
File metadata and controls
97 lines (88 loc) · 1.9 KB
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
#include "CompareData.h"
/**
25/10/2011
- Changed the way the LSF is calculated in an attempt to reduce segmentation faults.
**/
using namespace std;
Compare_Data::Compare_Data()
// Constructor sets values to 0
{
count = 0;
m = 0;
n = 0;
// Set pointers to NULL
output_content = NULL;
}
double Compare_Data::lsf(const bool d)
// Calculates least squares fitting total for two data sets
// To make sure this isn't a massive number we have divded by the numbers of points to give an LSF average.
// Outputs: float - result
{
// Clear out vector for saving differences
if (d)
{
difference.clear();
}
if (count != 0)
{
double result = 0;
for (int i = 0; i < count; i++)
{
// float diff = pow(dataOne[i]-dataTwo[i],2);
float diff = dataOne[i]-dataTwo[i];
diff *= diff;
if (d)
{
difference.push_back(diff);
}
result += diff;
}
return (double) result/count; // True use would return just result.
}
else
{
#pragma omp critical
{
output_content->push_back("Error: Total count is not defined");
}
return 0;
}
}
double Compare_Data::covariance()
// Calculates part of covariance for two data arrays
// Covariance can be defined as (M[a*b]/N)-M[a]M[b]
// This is what we are working towards here, though subtracting M[a]M[b] needs to be done afterwards
// So actually we just give the mean of a*b
// Output: float - result
{
if (count != 0)
{
double result = 0;
for (int i = 0; i < count; i++)
{
result+=dataOne[i]*dataTwo[i];
}
return (double) result/count; // True use would return just result.
}
else
{
#pragma omp critical
{
output_content->push_back("Error: Total count is not defined");
}
return 0;
}
}
vector<float> Compare_Data::getLSFDifference()
// Returns image array of numerical differences so areas for concern can be highlighted.
{
if (difference.size() > 0)
{
return difference;
}
else
{
vector<float> d(0);
return d;
}
}