Explorar o código

changed name for oblique tree builder using least-squares

Sven Sickert %!s(int64=10) %!d(string=hai) anos
pai
achega
52d081182f

+ 22 - 18
classifier/fpclassifier/randomforest/DTBOblique.cpp → classifier/fpclassifier/randomforest/DTBObliqueLS.cpp

@@ -1,5 +1,5 @@
 /**
- * @file DTBOblique.cpp
+ * @file DTBObliqueLS.cpp
  * @brief random oblique decision tree
  * @author Sven Sickert
  * @date 10/15/2014
@@ -8,7 +8,7 @@
 #include <iostream>
 #include <time.h>
 
-#include "DTBOblique.h"
+#include "DTBObliqueLS.h"
 #include "vislearning/features/fpfeatures/ConvolutionFeature.h"
 
 #include "core/vector/Algorithms.h"
@@ -21,7 +21,7 @@ using namespace OBJREC;
 using namespace std;
 using namespace NICE;
 
-DTBOblique::DTBOblique ( const Config *conf, string section )
+DTBObliqueLS::DTBObliqueLS ( const Config *conf, string section )
 {
     saveIndices = conf->gB( section, "save_indices", false);
     useShannonEntropy = conf->gB( section, "use_shannon_entropy", false );
@@ -39,12 +39,12 @@ DTBOblique::DTBOblique ( const Config *conf, string section )
 
 }
 
-DTBOblique::~DTBOblique()
+DTBObliqueLS::~DTBObliqueLS()
 {
 
 }
 
-bool DTBOblique::entropyLeftRight (
+bool DTBObliqueLS::entropyLeftRight (
         const FeatureValuesUnsorted & values,
         double threshold,
         double* stat_left,
@@ -94,7 +94,7 @@ bool DTBOblique::entropyLeftRight (
     return true;
 }
 
-bool DTBOblique::adaptDataAndLabelForMultiClass (
+bool DTBObliqueLS::adaptDataAndLabelForMultiClass (
         const int posClass,
         const int negClass,
         NICE::Matrix & X,
@@ -146,7 +146,7 @@ bool DTBOblique::adaptDataAndLabelForMultiClass (
 }
 
 /** refresh data matrix X and label vector y */
-void DTBOblique::getDataAndLabel(
+void DTBObliqueLS::getDataAndLabel(
         const FeaturePool &fp,
         const Examples &examples,
         const std::vector<int> &examples_selection,
@@ -184,7 +184,7 @@ void DTBOblique::getDataAndLabel(
 
 }
 
-void DTBOblique::regularizeDataMatrix(
+void DTBObliqueLS::regularizeDataMatrix(
         const NICE::Matrix &X,
         NICE::Matrix &XTXreg,
         const int regOption,
@@ -255,13 +255,13 @@ void DTBOblique::regularizeDataMatrix(
 
         // no regularization
         default:
-            std::cerr << "DTBOblique::regularizeDataMatrix: No regularization applied!"
+            std::cerr << "DTBObliqueLS::regularizeDataMatrix: No regularization applied!"
                       << std::endl;
             break;
     }
 }
 
-void DTBOblique::findBestSplitThreshold (
+void DTBObliqueLS::findBestSplitThreshold (
         FeatureValuesUnsorted &values,
         SplitInfo &bestSplitInfo,
         const NICE::Vector &beta,
@@ -274,7 +274,7 @@ void DTBOblique::findBestSplitThreshold (
     double maxValue = (max_element ( values.begin(), values.end() ))->first;
 
     if ( maxValue - minValue < 1e-7 )
-        std::cerr << "DTBOblique: Difference between min and max of features values to small!"
+        std::cerr << "DTBObliqueLS: Difference between min and max of features values to small!"
                   << " [" << minValue << "," << maxValue << "]" << std::endl;
 
     // get best thresholds using complete search
@@ -331,7 +331,7 @@ void DTBOblique::findBestSplitThreshold (
 }
 
 /** recursive building method */
-DecisionNode *DTBOblique::buildRecursive(
+DecisionNode *DTBObliqueLS::buildRecursive(
         const FeaturePool & fp,
         const Examples & examples,
         std::vector<int> & examples_selection,
@@ -343,7 +343,7 @@ DecisionNode *DTBOblique::buildRecursive(
 {
 
 #ifdef DEBUGTREE
-    std::cerr << "DTBOblique: Examples: " << (int)examples_selection.size()
+    std::cerr << "DTBObliqueLS: Examples: " << (int)examples_selection.size()
               << ", Depth: " << (int)depth << ", Entropy: " << e << std::endl;
 #endif
 
@@ -358,7 +358,7 @@ DecisionNode *DTBOblique::buildRecursive(
 
     {
 #ifdef DEBUGTREE
-        std::cerr << "DTBOblique: Stopping criteria applied!" << std::endl;
+        std::cerr << "DTBObliqueLS: Stopping criteria applied!" << std::endl;
 #endif
         node->trainExamplesIndices = examples_selection;
         return node;
@@ -427,6 +427,10 @@ DecisionNode *DTBOblique::buildRecursive(
             gotInnerIteration = true;
         }
     }
+//    f->setRandomParameterVector();
+//    beta = f->getParameterVector();
+//    f->calcFeatureValues( examples, examples_selection, values);
+//    findBestSplitThreshold ( values, bestSplitInfo, beta, e, maxClassNo );
 
     // supress strange behaviour for values near zero (8.88178e-16)
     if (bestSplitInfo.entropyLeft < 1.0e-10 ) bestSplitInfo.entropyLeft = 0.0;
@@ -436,7 +440,7 @@ DecisionNode *DTBOblique::buildRecursive(
     if ( bestSplitInfo.informationGain < minimumInformationGain )
     {
 #ifdef DEBUGTREE
-        std::cerr << "DTBOblique: Minimum information gain reached!" << std::endl;
+        std::cerr << "DTBObliqueLS: Minimum information gain reached!" << std::endl;
 #endif
         delete [] bestSplitInfo.distLeft;
         delete [] bestSplitInfo.distRight;
@@ -469,7 +473,7 @@ DecisionNode *DTBOblique::buildRecursive(
 #ifdef DEBUGTREE
 //    node->f->store( std::cerr );
 //    std::cerr << std::endl;
-    std::cerr << "DTBOblique: Information Gain: " << bestSplitInfo.informationGain
+    std::cerr << "DTBObliqueLS: Information Gain: " << bestSplitInfo.informationGain
               << ", Left Entropy: " <<  bestSplitInfo.entropyLeft << ", Right Entropy: "
               << bestSplitInfo.entropyRight << std::endl;
 #endif
@@ -485,7 +489,7 @@ DecisionNode *DTBOblique::buildRecursive(
         if ( r != 0 )
             distribution_right_sparse[k] = r;
 //#ifdef DEBUGTREE
-//        std::cerr << "DTBOblique: Split of Class " << k << " ("
+//        std::cerr << "DTBObliqueLS: Split of Class " << k << " ("
 //                  << l << " <-> " << r << ") " << std::endl;
 //#endif
     }
@@ -524,7 +528,7 @@ DecisionNode *DTBOblique::buildRecursive(
 }
 
 /** initial building method */
-DecisionNode *DTBOblique::build ( const FeaturePool & fp,
+DecisionNode *DTBObliqueLS::build ( const FeaturePool & fp,
                                         const Examples & examples,
                                         int maxClassNo )
 {

+ 7 - 7
classifier/fpclassifier/randomforest/DTBOblique.h → classifier/fpclassifier/randomforest/DTBObliqueLS.h

@@ -1,12 +1,12 @@
 /**
- * @file DTBOblique.h
+ * @file DTBObliqueLS.h
  * @brief oblique decision tree
  * @author Sven Sickert
  * @date 10/15/2014
 
 */
-#ifndef DTBOBLIQUEINCLUDE
-#define DTBOBLIQUEINCLUDE
+#ifndef DTBOBLIQUELSINCLUDE
+#define DTBOBLIQUELSINCLUDE
 
 #include "core/vector/VectorT.h"
 #include "core/vector/MatrixT.h"
@@ -29,7 +29,7 @@ struct SplitInfo {
 };
 
 /** random oblique decision tree */
-class DTBOblique : public DecisionTreeBuilder
+class DTBObliqueLS : public DecisionTreeBuilder
 {
   protected:
 
@@ -183,11 +183,11 @@ class DTBOblique : public DecisionTreeBuilder
   public:
 
     /** simple constructor */
-    DTBOblique ( const NICE::Config *conf,
-                       std::string section = "DTBOblique" );
+    DTBObliqueLS ( const NICE::Config *conf,
+                       std::string section = "DTBObliqueLS" );
 
     /** simple destructor */
-    virtual ~DTBOblique();
+    virtual ~DTBObliqueLS();
 
     /**
      * @brief initial building method

+ 3 - 3
classifier/fpclassifier/randomforest/FPCRandomForests.cpp

@@ -19,7 +19,7 @@
 #include "vislearning/classifier/fpclassifier/randomforest/DTBStandard.h"
 #include "vislearning/classifier/fpclassifier/randomforest/DTBRandom.h"
 #include "vislearning/classifier/fpclassifier/randomforest/DTBClusterRandom.h"
-#include "vislearning/classifier/fpclassifier/randomforest/DTBOblique.h"
+#include "vislearning/classifier/fpclassifier/randomforest/DTBObliqueLS.h"
 #include "vislearning/cbaselib/FeaturePool.h"
 
 using namespace OBJREC;
@@ -65,8 +65,8 @@ FPCRandomForests::FPCRandomForests(const Config *_conf, std::string section) : c
 			builder = new DTBRandom ( conf, builder_section );
 		else if (builder_method == "cluster_random" )
 			builder = new DTBClusterRandom ( conf, builder_section );
-        else if (builder_method == "oblique" )
-            builder = new DTBOblique ( conf, builder_section );
+        else if (builder_method == "oblique_ls" )
+            builder = new DTBObliqueLS ( conf, builder_section );
 		else {
 			fprintf (stderr, "DecisionTreeBuilder %s not yet implemented !\n", builder_method.c_str() );
 			exit(-1);