-
Notifications
You must be signed in to change notification settings - Fork 0
/
featurevector.cpp
161 lines (141 loc) · 3.59 KB
/
featurevector.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
#include "featurevector.h"
#include <cmath>
FeatureVector::FeatureVector() {
for (auto it=begin(); it!=end(); ++it) {
*it = 0.0;
}
}
FeatureVector FeatureVector::operator+(FeatureVector const & other) const {
FeatureVector sum;
for (int i=0; i<10; ++i) {
sum[i] = operator[](i) + other[i];
}
return sum;
}
FeatureVector & FeatureVector::operator+=(FeatureVector const & other) {
for (int i=0; i<10; ++i) {
operator[](i) += other[i];
}
return *this;
}
FeatureVector FeatureVector::operator-(FeatureVector const & other) const {
FeatureVector diff;
for (int i=0; i<10; ++i) {
diff[i] = operator[](i) - other[i];
}
return diff;
}
FeatureVector & FeatureVector::operator-=(FeatureVector const & other) {
for (int i=0; i<10; ++i) {
operator[](i) -= other[i];
}
return *this;
}
FeatureVector FeatureVector::operator*(double a) const {
FeatureVector prod;
for (int i=0; i<10; ++i) {
prod[i] = operator[](i) * a;
}
return prod;
}
FeatureVector FeatureVector::operator*(FeatureVector const & other) const {
FeatureVector prod;
for (int i=0; i<10; ++i) {
prod[i] = operator[](i) * other[i];
}
return prod;
}
FeatureVector & FeatureVector::operator*=(double a) {
for (auto it=begin(); it!=end(); ++it) {
*it *= a;
}
return *this;
}
FeatureVector & FeatureVector::operator*=(FeatureVector const & other) {
for (int i=0; i<10; ++i) {
operator[](i) *= other[i];
}
return *this;
}
FeatureVector FeatureVector::operator/(double a) const {
FeatureVector quot;
for (int i=0; i<10; ++i) {
quot[i] = operator[](i) / a;
}
return quot;
}
FeatureVector FeatureVector::operator/(FeatureVector const & other) const {
FeatureVector quot;
for (int i=0; i<10; ++i) {
quot[i] = operator[](i) / other[i];
}
return quot;
}
FeatureVector & FeatureVector::operator/=(double a) {
for (auto it=begin(); it!=end(); ++it) {
*it /= a;
}
return *this;
}
FeatureVector & FeatureVector::operator/=(FeatureVector const & other) {
for (int i=0; i<10; ++i) {
operator[](i) /= other[i];
}
return *this;
}
FeatureVector FeatureVector::compwiseMin(FeatureVector const & other) const {
FeatureVector min;
for (int i=0; i<10; ++i) {
min[i] = std::min(operator[](i), other[i]);
}
return min;
}
void FeatureVector::setCompwiseMin(FeatureVector const & other) {
*this = compwiseMin(other);
}
FeatureVector FeatureVector::compwiseMax(FeatureVector const & other) const {
FeatureVector max;
for (int i=0; i<10; ++i) {
max[i] = std::max(operator[](i), other[i]);
}
return max;
}
void FeatureVector::setCompwiseMax(FeatureVector const & other) {
*this = compwiseMax(other);
}
double FeatureVector::magnitude() const {
return sqrt(magnitudeSquared());
}
double FeatureVector::magnitudeSquared() const {
double magSqared = 0.0;
for (auto it=begin(); it!=end(); ++it) {
magSqared += *it * *it;
}
return magSqared;
}
QString FeatureVector::toString(unsigned short id) {
switch (id) {
case SIZE:
return QString("Size");
case SPATIALSD:
return QString("Spatial SD");
case COMPACTNESS:
return QString("Compactness");
case LIGHTNESS:
return QString("Lightness");
case GREENRED:
return QString("Green-Red");
case YELLOWBLUE:
return QString("Yellow-Blue");
case CROMA:
return QString("Croma");
case HUE:
return QString("Hue");
case COLORSD:
return QString("Color SD");
case ANGLE:
return QString("Angle");
default:
return QString("Unknown");
}
}