#ifndef PATTERN_RECOGNITION_HPP #define PATTERN_RECOGNITION_HPP template class roc_distribution { public: std::vector< boost::numeric::ublas::c_vector > roc_data; //result Value_T sample_double; boost::accumulators::accumulator_set< Value_T , boost::accumulators::stats< boost::accumulators::tag::p_square_cumulative_distribution > >acc_positive, acc_negative; roc_distribution(): sample_double(0) , acc_positive( boost::accumulators::p_square_cumulative_distribution_num_cells = 30 ,boost::accumulators::sample = sample_double) //false_positive_rate , acc_negative( boost::accumulators::p_square_cumulative_distribution_num_cells = 30 ,boost::accumulators::sample = sample_double) //true_negative_rate {} void operator()(Value_T &val, bool positive_or_negative ) { if(positive_or_negative) { acc_positive(val);//false_positive_rate } else { acc_negative(val);//true_negative_rate } } void get_result() { typedef boost::iterator_range< std::vector >::iterator > histogram_type; histogram_type histogram_positive = accumulators::p_square_cumulative_distribution(acc_positive);//false_positive_rate histogram_type histogram_negative = accumulators::p_square_cumulative_distribution(acc_negative);//true_negative_rate histogram_type::iterator hit_pos=histogram_positive.begin(),hit_neg=histogram_negative.begin(); boost::numeric::ublas::c_vector tmp_vec; Value_T vp=0.0, vn=0.0; Value_T h; do { if( hit_pos != histogram_positive.end() && hit_neg != histogram_negative.end() ) { if( hit_pos->first < hit_neg->first ) { h= hit_pos->first; vp= hit_pos->second; hit_pos++; }else if(hit_neg->first < hit_pos->first ) { h= hit_neg->first; vn= hit_neg->second; hit_neg++; } }else{ if( hit_neg != histogram_negative.end() ) { h= hit_neg->first; vn= hit_neg->second; hit_neg++; }else if(hit_pos != histogram_positive.end() ) { h= hit_pos->first; vp= hit_pos->second; hit_pos++; } } tmp_vec[0]=h; tmp_vec[1]=1-vp; //true_positive_rate tmp_vec[2]=1-vn; //false_negative_rate roc_data.push_back(tmp_vec); }while( hit_pos != histogram_positive.end() || hit_neg != histogram_negative.end() ); } }; #endif /* PATTERN_RECOGNITION_HPP */