Diff of /src/multi_class.cc [r78] .. [r79]  Maximize  Restore

Switch to side-by-side view

--- a/src/multi_class.cc
+++ b/src/multi_class.cc
@@ -66,7 +66,7 @@
   }
 
   template <class real, class cls_t>
-  int classifier_obj<real, cls_t>::ltran(real **mat, dim_ta d1, dim_ta d2, int flag) {return 0;}
+  int classifier_obj<real, cls_t>::ltran(real **mat, real *b, dim_ta d1, dim_ta d2, int flag) {return 0;}
 
   template <class real, class cls_t>
   int classifier_obj<real, cls_t>::max_depth(int cur) {return 1;}
@@ -136,7 +136,7 @@
 
   //if flag, then border vectors are stored un-normalized
   template <class real, class cls_t>
-  int agf2class<real, cls_t>::ltran(real **mat1, dim_ta d1, dim_ta d2, int flag) {
+  int agf2class<real, cls_t>::ltran(real **mat1, real *b1, dim_ta d1, dim_ta d2, int flag) {
     int err2=0;
 
     real **brd2;
@@ -144,6 +144,7 @@
 
     //err2=read_stats(normfile, ave, std, D);
     mat=mat1;
+    b=b1;
   
     if (flag) {
       if (d1!=this->D) {
@@ -155,12 +156,12 @@
       //features as before normalization:
       D1=d2;
 
-      //normalise all the variables:
-      /*for (nel_ta i=0; i<n; i++) {
+      //apply constant factor:
+      for (nel_ta i=0; i<n; i++) {
         for (dim_ta j=0; j<D1; j++) {
-          brd[i][j]=brd[i][j]-ave[j];
+          brd[i][j]=brd[i][j]-b[j];
         }
-      }*/
+      }
 
       brd2=matrix_mult(brd, mat, n, this->D, D1);
       grd2=matrix_mult(grd, mat, n, this->D, D1);
@@ -189,8 +190,16 @@
     cls_t cls;
 
     if (mat!=NULL) {
-      //for (dim_ta i=0; i<D0; i++) x[i]=x[i]-ave[i];
-      xtran=left_vec_mult(x, mat, this->D, D1);
+      real tmp;
+      //for (dim_ta i=0; i<this->D; i++) x[i]=x[i]-b[i];
+      //this whole business with the linear transformation matrix is way fucking
+      //more trouble than it's worth...
+      for (dim_ta j=0; j<D1; j++) xtran[j]=0;
+      for (dim_ta i=0; i<this->D; i++) {
+        tmp=x[i]-b[i];
+        for (dim_ta j=0; j<D1; j++) xtran[j]=xtran[j]+tmp*mat[j][i];
+      }
+      //xtran=left_vec_mult(x, mat, this->D, D1);
     } else {
       xtran=x;
     }
@@ -348,10 +357,10 @@
   }
 
   template <class real, class cls_t, class twoclass_t>
-  int multiclass<real, cls_t, twoclass_t>::ltran(real **mat, dim_ta d1, dim_ta d2, int flag) {
+  int multiclass<real, cls_t, twoclass_t>::ltran(real **mat, real *b, dim_ta d1, dim_ta d2, int flag) {
     int err=0;
     for (int i=0; i<nmodel; i++) {
-      err=twoclass[i]->ltran(mat, d1, d2, flag);
+      err=twoclass[i]->ltran(mat, b, d1, d2, flag);
       if (err!=0) {
         fprintf(stderr, "multiclass::ltran: an error occured transforming partition #%d\n", i);
         return err;
@@ -568,16 +577,16 @@
   }
 
   template <class real, class cls_t, class twoclass_t>
-  int multiclass_hier<real, cls_t, twoclass_t>::ltran(real **mat, dim_ta d1, dim_ta d2, int flag) {
+  int multiclass_hier<real, cls_t, twoclass_t>::ltran(real **mat, real *b, dim_ta d1, dim_ta d2, int flag) {
     int err=0;
 
-    err=classifier->ltran(mat, d1, d2, flag);
+    err=classifier->ltran(mat, b, d1, d2, flag);
     if (err!=0) {
       fprintf(stderr, "multiclass_hier::ltran: an error occurred transforming partition classifier\n");
       return err;
     }
     for (int i=0; i<classifier->n_class(); i++) {
-      err=children[i]->ltran(mat, d1, d2, flag);
+      err=children[i]->ltran(mat, b, d1, d2, flag);
       if (err!=0) {
         fprintf(stderr, "multiclass_hier::ltran: an error occurred transforming child #%d\n", i);
         return err;