Skip to content

Commit 11b747d

Browse files
committed
fix a bug when there are only two classes
1 parent 6787a23 commit 11b747d

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

mascot/svmProblem.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,6 @@ void svmProblem::groupClasses() {
2121
count.push_back(1);
2222
}
2323
}
24-
start.push_back(0);
25-
for (int i = 1; i < count.size(); ++i) {
26-
start.push_back(start[i - 1] + count[i - 1]);
27-
}
28-
vector<int> _start(start);
29-
perm = vector<int>(v_nLabels.size());
30-
for (int i = 0; i < v_nLabels.size(); ++i) {
31-
perm[_start[dataLabel[i]]] = i;
32-
_start[dataLabel[i]]++;
33-
}
3424

3525
// Labels are ordered by their first occurrence in the training set.
3626
// However, for two-class sets with -1/+1 labels and -1 appears first,
@@ -49,6 +39,17 @@ void svmProblem::groupClasses() {
4939
dataLabel[i] = 0;
5040
}
5141
}
42+
43+
start.push_back(0);
44+
for (int i = 1; i < count.size(); ++i) {
45+
start.push_back(start[i - 1] + count[i - 1]);
46+
}
47+
vector<int> _start(start);
48+
perm = vector<int>(v_nLabels.size());
49+
for (int i = 0; i < v_nLabels.size(); ++i) {
50+
perm[_start[dataLabel[i]]] = i;
51+
_start[dataLabel[i]]++;
52+
}
5253
}
5354

5455
svmProblem svmProblem::getSubProblem(int i, int j) const {

0 commit comments

Comments
 (0)