Permalink
Browse files

fixed ordering of labels in group_classes, by applying identical patc…

…h as Fabian's

patch for libsvm.
  • Loading branch information...
1 parent cfd7ffe commit e038a8f632b3bf7ce6edf24d29fd01073d2e3c8a @yamins81 committed Jan 31, 2011
Showing with 40 additions and 3 deletions.
  1. +40 −3 scikits/learn/svm/src/liblinear/linear.cpp
View
43 scikits/learn/svm/src/liblinear/linear.cpp
@@ -1,3 +1,10 @@
+/*
+ Modified 2011:
+
+ - Make labels sorted in group_classes, Dan Yamins.
+
+ */
+
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
@@ -1689,12 +1696,11 @@ static void group_classes(const problem *prob, int *nr_class_ret, int **label_re
int *label = Malloc(int,max_nr_class);
int *count = Malloc(int,max_nr_class);
int *data_label = Malloc(int,l);
- int i;
+ int i,j, this_label, this_count;
for(i=0;i<l;i++)
{
- int this_label = prob->y[i];
- int j;
+ this_label = (int)prob->y[i];
for(j=0;j<nr_class;j++)
{
if(this_label == label[j])
@@ -1718,6 +1724,37 @@ static void group_classes(const problem *prob, int *nr_class_ret, int **label_re
}
}
+ /* START MOD: Sort labels and apply to array count --dyamins */
+
+ for(j=1; j<nr_class; j++)
+ {
+ i = j-1;
+ this_label = label[j];
+ this_count = count[j];
+ while(i>=0 && label[i] > this_label)
+ {
+ label[i+1] = label[i];
+ count[i+1] = count[i];
+ i--;
+ }
+ label[i+1] = this_label;
+ count[i+1] = this_count;
+ }
+
+ for (i=0; i <l; i++)
+ {
+ j = 0;
+ this_label = (int)prob->y[i];
+ while(this_label != label[j])
+ {
+ j++;
+ }
+ data_label[i] = j;
+
+ }
+
+ /* END MOD */
+
int *start = Malloc(int,nr_class);
start[0] = 0;
for(i=1;i<nr_class;i++)

0 comments on commit e038a8f

Please sign in to comment.