/**
* @file RegressionTreeBuilder.cpp
* @brief build regression trees
* @author Sven Sicker
* @date 06/19/2013

*/
#include <iostream>

#include <vislearning/regression/randomforest/RegressionTreeBuilder.h>

using namespace OBJREC;

using namespace std;

using namespace NICE;

RegressionTreeBuilder::RegressionTreeBuilder ()
{
}

RegressionTreeBuilder::~RegressionTreeBuilder ()
{
}

void RegressionTreeBuilder::build (
          RegressionTree& tree, 
          const NICE::VVector & x,
          const NICE::Vector & y )
{
  RegressionNode *root = build ( x, y );
  tree.setRoot( root );
  
  int depth, count;
  tree.statistics( depth, count );
  fprintf (stderr, "RegressionTree: maximum depth = %d, number of nodes = %d\n", depth, count );
}

void RegressionTreeBuilder::collectFeatureValues (
          const NICE::VVector & x,
          const std::vector< int > & selection,
          const int f,
          vector< pair< double, int > >& values )
{
  for (int i = 0; i < (int)selection.size(); i++)
  {
    pair< double, int > curr;
    double value = x[ selection[i] ][f];
    curr.first = value;
    curr.second = selection[i];
    values.push_back( curr );
  }
}