Easy Support Vector Machine

Dependents:   WeatherPredictor

Revision:
2:c4a5251cee32
Parent:
1:1a0d5152d50b
Child:
4:01a20b89db32
--- a/MCSVM.cpp	Wed Jan 28 15:22:10 2015 +0000
+++ b/MCSVM.cpp	Sun Feb 15 09:27:08 2015 +0000
@@ -89,6 +89,10 @@
   // 単位ステップ関数による決定的識別
   float net;
   int* result_label_count = new int[n_class];
+  
+  // 元のラベルを退避
+  int* tmp_label = new int[n_sample];
+  memcpy(tmp_label,label, sizeof(int) * n_sample);
 
   int tmp_ci, tmp_cj;
   memset(result_label_count, 0, sizeof(int) * n_class);
@@ -127,8 +131,10 @@
       argmax = i;
     }
   }
-
-  delete [] result_label_count;
+    // 元のラベルを復帰
+  memcpy(this->label, tmp_label, sizeof(int) * n_sample);
+  delete [] tmp_label; delete [] result_label_count;
+  
   return argmax;
 
 }
@@ -140,7 +146,13 @@
   float prob;
   float* result_label_prob = new float[n_class];
   int tmp_ci, tmp_cj;
+
   memset(result_label_prob, 0, sizeof(float) * n_class);
+  
+  // 元のラベルを退避
+  int* tmp_label = new int[n_sample];
+  memcpy(tmp_label,label, sizeof(int) * n_sample);
+  
   for (int ci = 0; ci < n_class; ci++) {
     for (int cj = ci + 1; cj < n_class; cj++) {
 
@@ -174,8 +186,11 @@
       max = result_label_prob[i];
     }
   }
-
-  delete [] result_label_prob;
+  
+  // 元のラベルを復帰
+  memcpy(this->label, tmp_label, sizeof(int) * n_sample);
+  delete [] tmp_label; delete [] result_label_prob;
+  
   // 平均確率を返す.
   return (max / (n_class-1));
 
@@ -196,6 +211,6 @@
         return;
     }
     int nC2 = n_class * (n_class - 1)/2;
-    memcpy(mc_alpha, mcalpha_data, sizeof(float) * n_sample * (n_class * (n_class - 1) / 2));
+    memcpy(mc_alpha, mcalpha_data, sizeof(float) * n_sample * nC2);
     status = SVM_SET_ALPHA;
 }