Jelajahi Sumber

DTBOblique: fix in implementation of regularization

Sven Sickert 10 tahun lalu
induk
melakukan
0945f0fa9e

+ 9 - 1
classifier/fpclassifier/randomforest/DTBOblique.cpp

@@ -239,9 +239,17 @@ void DTBOblique::regularizeDataMatrix(
             q[0] = 1.0;
             q[0] = 1.0;
             NICE::Matrix Q;
             NICE::Matrix Q;
             Q.tensorProduct(q,q);
             Q.tensorProduct(q,q);
-            R.multiply(XTXreg,Q);
+            //R.multiply(XTXreg,Q);
+            // element-wise multiplication
+            R.resize(dim,dim);
             for ( int r = 0; r < dim; r++ )
             for ( int r = 0; r < dim; r++ )
+            {
+                for ( int c = 0; c < dim; c++ )
+                    R(r,c) = XTXreg(r,c) * Q(r,c);
+
                 R(r,r) = q[r] * XTXreg(r,r);
                 R(r,r) = q[r] * XTXreg(r,r);
+            }
+
             XTXreg = R;
             XTXreg = R;
             break;
             break;
         }
         }

+ 26 - 52
features/fpfeatures/ConvolutionFeature.cpp

@@ -125,12 +125,11 @@ NICE::Vector ConvolutionFeature::getFeatureVector( const Example *example ) cons
     NICE::MultiChannelImageT<double> * imgD = NULL;
     NICE::MultiChannelImageT<double> * imgD = NULL;
     imgD = & example->ce->getDChannel( CachedExample::D_EOH );
     imgD = & example->ce->getDChannel( CachedExample::D_EOH );
 
 
-    int xsize, ysize, x, y;
-
+    int xsize, ysize;
     example->ce->getImageSize( xsize, ysize );
     example->ce->getImageSize( xsize, ysize );
-    x = example->x;
-    y = example->y;
 
 
+    const int x = example->x;
+    const int y = example->y;
     const int halfwsx = std::floor ( window_size_x / 2 );
     const int halfwsx = std::floor ( window_size_x / 2 );
     const int halfwsy = std::floor ( window_size_y / 2 );
     const int halfwsy = std::floor ( window_size_y / 2 );
     const int step = window_size_x*window_size_y;
     const int step = window_size_x*window_size_y;
@@ -207,59 +206,34 @@ double ConvolutionFeature::val ( const Example *example ) const
     NICE::MultiChannelImageT<double> * imgD = NULL;
     NICE::MultiChannelImageT<double> * imgD = NULL;
     imgD = & example->ce->getDChannel( CachedExample::D_EOH );
     imgD = & example->ce->getDChannel( CachedExample::D_EOH );
 
 
-    int xsize, ysize, x, y;
-
+    int xsize, ysize;
     example->ce->getImageSize( xsize, ysize );
     example->ce->getImageSize( xsize, ysize );
-    x = example->x;
-    y = example->y;
-
-    const int colorStep = window_size_x*window_size_y;
-    const int scalingSteps = 1;
 
 
-    int halfwsx = std::floor ( window_size_x / 2 );
-    int halfwsy = std::floor ( window_size_y / 2 );
-    int wScale = 1;
+    const int x = example->x;
+    const int y = example->y;
+    const int halfwsx = std::floor ( window_size_x / 2 );
+    const int halfwsy = std::floor ( window_size_y / 2 );
+    const int step = window_size_x*window_size_y;
 
 
-    for ( int s = 0; s < scalingSteps; s++ )
-    {
-        for ( int c = 0; c < numChannels; c++ )
+    int k = 1;
+    for ( int v = -halfwsy; v <= halfwsy; v++ )
+        for ( int u = -halfwsx; u <= halfwsx; u++, k++ )
         {
         {
-            int paramIdx = 1;
-            int pxIdx = 0;
-            for ( int v = -halfwsy; v <= halfwsy; v++ )
-                for ( int u = -halfwsx; u <= halfwsx; u++, pxIdx++ )
-                {
-                    if (pxIdx % wScale == 0) paramIdx++;
-
-                    int colorShift = paramIdx + c*colorStep;
-                    int uu = u;
-                    int vv = v;
-
-                    if (x+u < 0 || x+u >= xsize) uu=-u;
-                    if (y+v < 0 || y+v >= ysize) vv=-v;
-
-                    if ( x+uu > 0
-                         && x+uu < xsize
-                         && y+vv > 0
-                         && y+vv < ysize
-                         && paramIdx < beta->size() )
-                    {
-                        val1 += imgD->get(x+uu,y+vv,c)
-                                * beta->operator [](colorShift)
-                                / wScale * wScale;
-                    }
-
-                }
-        }
-
-        // increase scaling
-        halfwsx *= 3;
-        halfwsy *= 3;
-        wScale *= 3;
-    }
+            int uu = u;
+            int vv = v;
+            if (x+u < 0 || x+u >= xsize) uu=-u;
+            if (y+v < 0 || y+v >= ysize) vv=-v;
 
 
-    // normalize scaling
-    val1 /= (double)scalingSteps;
+            if ( x+uu > 0
+                 && x+uu < xsize
+                 && y+vv > 0
+                 && y+vv < ysize
+                 && k < beta->size() )
+            {
+                for ( int c = 0; c < numChannels; c++ )
+                    val1 += imgD->get(x+uu,y+vv,c) * beta->operator [](k + c*step);
+            }
+        }
 
 
     if (useSpatialPriors)
     if (useSpatialPriors)
     {
     {