/**
* @file RTBMeanPostImprovement.h
* @brief regression tree splitting criteria by Taylor and Jones, 1996
* @author Sven Sickert
* @date 07/23/2013

*/
#ifndef RTBMEANPOSTIMPROVEMENTINCLUDE
#define RTBMEANPOSTIMPROVEMENTINCLUDE

#include <vector>

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

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


namespace OBJREC {

/** regression tree splitting criteria by Taylor and Jones, 1996 */
class RTBMeanPostImprovement : public RegressionTreeBuilder
{
  
  protected:
    int random_split_tests;
    int random_features;
    int max_depth;
    int min_examples;
    double minimum_improvement;
    
    bool auto_bandwith;
    
    /** save indices in leaves */
    bool save_indices;
    
    RegressionNode *buildRecursive ( const NICE::VVector & x,
          const NICE::Vector & y,
          std::vector<int> & selection,
          int depth);
    
    double gaussianVal( const double input, 
          const double bandwidth );

    bool improvementLeftRight ( const std::vector< std::pair< double, int > > values,
          const NICE::Vector & y,
          double threshold,
          std::vector<double> & empDist_left,
          std::vector<double> & empDist_right,
          int & count_left,
          int & count_right,
          double& h,
          double& p );

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

#endif