/**
* @file RTBMinDist.h
* @brief random regression tree; split criterion is to minimize mean distance of all examples of an inner node
* @author Frank Prüfer
* @date 09/17/2013

*/
#ifndef RTBMINDISTINCLUDE
#define RTBMINDISTINCLUDE

#include <vector>

#include "core/vector/VectorT.h"
#include "core/vector/VVector.h"

#include "core/basics/Config.h"
#include "RegressionTreeBuilder.h"


namespace OBJREC {

/** random regression tree */
class RTBMinDist : public RegressionTreeBuilder
{
  
  protected:
    int random_split_tests;
    int random_features;
    int max_depth;
    int min_examples;
    double minimum_distance_reduction;
    
    RegressionNode *buildRecursive ( const NICE::VVector & x,
          const NICE::Vector & y,
          std::vector<int> & selection,
          int depth);

    void computeDistanceToPrototype ( const std::vector<double> &fvalues,
                                      const int &countEx,
                                      double &dist);

    bool averageDistanceLeftRight ( const std::vector< std::pair< double, int > > values,
          double threshold,
          double & avg_dist_left,
          double & avg_dist_right,
          int & count_left,
          int & count_right );

  public:
    
    /** simple constructor */
    RTBMinDist( const NICE::Config *conf, std::string section = "RTBMinDist" );
    
    /** simple destructor */
    virtual ~RTBMinDist();
    
    RegressionNode *build ( const NICE::VVector & x,
          const NICE::Vector & y );
    
};
  
  
} // namespace

#endif 
 
