fixed many warnings from GCC 4.6.1
[profile/ivi/opencv.git] / modules / ml / src / rtrees.cpp
index 79ae665..61614c2 100644 (file)
@@ -190,6 +190,26 @@ void CvForestTree::read( CvFileStorage* _fs, CvFileNode* _node,
 //////////////////////////////////////////////////////////////////////////////////////////
 //                                  Random trees                                        //
 //////////////////////////////////////////////////////////////////////////////////////////
+CvRTParams::CvRTParams() : CvDTreeParams( 5, 10, 0, false, 10, 0, false, false, 0 ),
+    calc_var_importance(false), nactive_vars(0)
+{
+    term_crit = cvTermCriteria( CV_TERMCRIT_ITER+CV_TERMCRIT_EPS, 50, 0.1 );
+}
+
+CvRTParams::CvRTParams( int _max_depth, int _min_sample_count,
+                        float _regression_accuracy, bool _use_surrogates,
+                        int _max_categories, const float* _priors, bool _calc_var_importance,
+                        int _nactive_vars, int max_num_of_trees_in_the_forest,
+                        float forest_accuracy, int termcrit_type ) :
+    CvDTreeParams( _max_depth, _min_sample_count, _regression_accuracy,
+                   _use_surrogates, _max_categories, 0,
+                   false, false, _priors ),
+    calc_var_importance(_calc_var_importance),
+    nactive_vars(_nactive_vars)
+{
+    term_crit = cvTermCriteria(termcrit_type,
+        max_num_of_trees_in_the_forest, forest_accuracy);
+}
 
 CvRTrees::CvRTrees()
 {
@@ -677,28 +697,18 @@ float CvRTrees::predict( const CvMat* sample, const CvMat* missing ) const
 
 float CvRTrees::predict_prob( const CvMat* sample, const CvMat* missing) const
 {
-    double result = -1;
-    int k;
-       
        if( nclasses == 2 ) //classification
     {
-        int max_nvotes = 0;
         cv::AutoBuffer<int> _votes(nclasses);
         int* votes = _votes;
         memset( votes, 0, sizeof(*votes)*nclasses );
-        for( k = 0; k < ntrees; k++ )
+        for( int k = 0; k < ntrees; k++ )
         {
             CvDTreeNode* predicted_node = trees[k]->predict( sample, missing );
-            int nvotes;
             int class_idx = predicted_node->class_idx;
             CV_Assert( 0 <= class_idx && class_idx < nclasses );
                        
-            nvotes = ++votes[class_idx];
-            if( nvotes > max_nvotes )
-            {
-                max_nvotes = nvotes;
-                result = predicted_node->value;
-            }
+            ++votes[class_idx];
         }
                
                return float(votes[1])/ntrees;
@@ -793,11 +803,16 @@ void CvRTrees::read( CvFileStorage* fs, CvFileNode* fnode )
     active_var_mask = cvCreateMat( 1, var_count, CV_8UC1 );
     {
         // initialize active variables mask
-        CvMat submask1, submask2;
-        cvGetCols( active_var_mask, &submask1, 0, nactive_vars );
-        cvGetCols( active_var_mask, &submask2, nactive_vars, var_count );
+        CvMat submask1;
+               cvGetCols( active_var_mask, &submask1, 0, nactive_vars );
         cvSet( &submask1, cvScalar(1) );
-        cvZero( &submask2 );
+
+               if( nactive_vars < var_count )
+               {
+                       CvMat submask2;
+                       cvGetCols( active_var_mask, &submask2, nactive_vars, var_count );
+                       cvZero( &submask2 );
+               }
     }
 }