Merge pull request #720 from taka-no-me:drop_sort

This commit is contained in:
Andrey Kamaev
2013-04-01 15:14:45 +04:00
committed by OpenCV Buildbot
20 changed files with 144 additions and 577 deletions
+9 -9
View File
@@ -351,9 +351,12 @@ CvBoostTree::find_split_ord_class( CvDTreeNode* node, int vi, float init_quality
return split;
}
#define CV_CMP_NUM_PTR(a,b) (*(a) < *(b))
static CV_IMPLEMENT_QSORT_EX( icvSortDblPtr, double*, CV_CMP_NUM_PTR, int )
template<typename T>
class LessThanPtr
{
public:
bool operator()(T* a, T* b) const { return *a < *b; }
};
CvDTreeSplit*
CvBoostTree::find_split_cat_class( CvDTreeNode* node, int vi, float init_quality, CvDTreeSplit* _split, uchar* _ext_buf )
@@ -412,7 +415,7 @@ CvBoostTree::find_split_cat_class( CvDTreeNode* node, int vi, float init_quality
// sort rows of c_jk by increasing c_j,1
// (i.e. by the weight of samples in j-th category that belong to class 1)
icvSortDblPtr( dbl_ptr, mi, 0 );
std::sort(dbl_ptr, dbl_ptr + mi, LessThanPtr<double>());
for( subset_i = 0; subset_i < mi-1; subset_i++ )
{
@@ -594,7 +597,7 @@ CvBoostTree::find_split_cat_reg( CvDTreeNode* node, int vi, float init_quality,
sum_ptr[i] = sum + i;
}
icvSortDblPtr( sum_ptr, mi, 0 );
std::sort(sum_ptr, sum_ptr + mi, LessThanPtr<double>());
// revert back to unnormalized sums
// (there should be a very little loss in accuracy)
@@ -1421,9 +1424,6 @@ CvBoost::update_weights( CvBoostTree* tree )
}
static CV_IMPLEMENT_QSORT_EX( icvSort_64f, double, CV_LT, int )
void
CvBoost::trim_weights()
{
@@ -1440,7 +1440,7 @@ CvBoost::trim_weights()
// use weak_eval as temporary buffer for sorted weights
cvCopy( weights, weak_eval );
icvSort_64f( weak_eval->data.db, count, 0 );
std::sort(weak_eval->data.db, weak_eval->data.db + count);
// as weight trimming occurs immediately after updating the weights,
// where they are renormalized, we assume that the weight sum = 1.
+13 -8
View File
@@ -44,13 +44,18 @@ static const float ord_nan = FLT_MAX*0.5f;
static const int min_block_size = 1 << 16;
static const int block_size_delta = 1 << 10;
#define CV_CMP_NUM_PTR(a,b) (*(a) < *(b))
static CV_IMPLEMENT_QSORT_EX( icvSortIntPtr, int*, CV_CMP_NUM_PTR, int )
template<typename T>
class LessThanPtr
{
public:
bool operator()(T* a, T* b) const { return *a < *b; }
};
#define CV_CMP_PAIRS(a,b) (*((a).i) < *((b).i))
static CV_IMPLEMENT_QSORT_EX( icvSortPairs, CvPair16u32s, CV_CMP_PAIRS, int )
///
class LessThanPairs
{
public:
bool operator()(const CvPair16u32s& a, const CvPair16u32s& b) const { return *a.i < *b.i; }
};
void CvERTreeTrainData::set_data( const CvMat* _train_data, int _tflag,
const CvMat* _responses, const CvMat* _var_idx, const CvMat* _sample_idx,
@@ -353,7 +358,7 @@ void CvERTreeTrainData::set_data( const CvMat* _train_data, int _tflag,
if (is_buf_16u)
{
icvSortPairs( pair16u32s_ptr, sample_count, 0 );
std::sort(pair16u32s_ptr, pair16u32s_ptr + sample_count, LessThanPairs());
// count the categories
for( i = 1; i < num_valid; i++ )
if (*pair16u32s_ptr[i].i != *pair16u32s_ptr[i-1].i)
@@ -361,7 +366,7 @@ void CvERTreeTrainData::set_data( const CvMat* _train_data, int _tflag,
}
else
{
icvSortIntPtr( int_ptr, sample_count, 0 );
std::sort(int_ptr, int_ptr + sample_count, LessThanPtr<int>());
// count the categories
for( i = 1; i < num_valid; i++ )
c_count += *int_ptr[i] != *int_ptr[i-1];
+4 -7
View File
@@ -5,9 +5,6 @@
#define pCvSeq CvSeq*
#define pCvDTreeNode CvDTreeNode*
#define CV_CMP_FLOAT(a,b) ((a) < (b))
static CV_IMPLEMENT_QSORT_EX( icvSortFloat, float, CV_CMP_FLOAT, float)
//===========================================================================
//----------------------------- CvGBTreesParams -----------------------------
//===========================================================================
@@ -285,7 +282,7 @@ CvGBTrees::train( const CvMat* _train_data, int _tflag,
} break;
default: CV_Error(CV_StsUnmatchedFormats, "_sample_idx should be a 32sC1, 8sC1 or 8uC1 vector.");
}
icvSortFloat(sample_idx->data.fl, sample_idx_len, 0);
std::sort(sample_idx->data.fl, sample_idx->data.fl + sample_idx_len);
}
else
{
@@ -470,7 +467,7 @@ void CvGBTrees::find_gradient(const int k)
int idx = *(sample_data + subsample_data[i]*s_step);
residuals[i] = fabs(resp_data[idx] - current_data[idx]);
}
icvSortFloat(residuals, n, 0.0f);
std::sort(residuals, residuals + n);
delta = residuals[int(ceil(n*alpha))];
@@ -693,7 +690,7 @@ float CvGBTrees::find_optimal_value( const CvMat* _Idx )
float* residuals = new float[n];
for (int i=0; i<n; ++i, ++idx)
residuals[i] = (resp_data[*idx] - cur_data[*idx]);
icvSortFloat(residuals, n, 0.0f);
std::sort(residuals, residuals + n);
if (n % 2)
gamma = residuals[n/2];
else gamma = (residuals[n/2-1] + residuals[n/2]) / 2.0f;
@@ -705,7 +702,7 @@ float CvGBTrees::find_optimal_value( const CvMat* _Idx )
float* residuals = new float[n];
for (int i=0; i<n; ++i, ++idx)
residuals[i] = (resp_data[*idx] - cur_data[*idx]);
icvSortFloat(residuals, n, 0.0f);
std::sort(residuals, residuals + n);
int n_half = n >> 1;
float r_median = (n == n_half<<1) ?
+25 -14
View File
@@ -120,16 +120,27 @@ bool CvDTreeTrainData::set_params( const CvDTreeParams& _params )
return ok;
}
#define CV_CMP_NUM_PTR(a,b) (*(a) < *(b))
static CV_IMPLEMENT_QSORT_EX( icvSortIntPtr, int*, CV_CMP_NUM_PTR, int )
static CV_IMPLEMENT_QSORT_EX( icvSortDblPtr, double*, CV_CMP_NUM_PTR, int )
template<typename T>
class LessThanPtr
{
public:
bool operator()(T* a, T* b) const { return *a < *b; }
};
#define CV_CMP_NUM_IDX(i,j) (aux[i] < aux[j])
static CV_IMPLEMENT_QSORT_EX( icvSortIntAux, int, CV_CMP_NUM_IDX, const float* )
static CV_IMPLEMENT_QSORT_EX( icvSortUShAux, unsigned short, CV_CMP_NUM_IDX, const float* )
template<typename T, typename Idx>
class LessThanIdx
{
public:
LessThanIdx( const T* _arr ) : arr(_arr) {}
bool operator()(Idx a, Idx b) const { return arr[a] < arr[b]; }
const T* arr;
};
#define CV_CMP_PAIRS(a,b) (*((a).i) < *((b).i))
static CV_IMPLEMENT_QSORT_EX( icvSortPairs, CvPair16u32s, CV_CMP_PAIRS, int )
class LessThanPairs
{
public:
bool operator()(const CvPair16u32s& a, const CvPair16u32s& b) const { return *a.i < *b.i; }
};
void CvDTreeTrainData::set_data( const CvMat* _train_data, int _tflag,
const CvMat* _responses, const CvMat* _var_idx, const CvMat* _sample_idx,
@@ -461,7 +472,7 @@ void CvDTreeTrainData::set_data( const CvMat* _train_data, int _tflag,
c_count = num_valid > 0;
if (is_buf_16u)
{
icvSortPairs( pair16u32s_ptr, sample_count, 0 );
std::sort(pair16u32s_ptr, pair16u32s_ptr + sample_count, LessThanPairs());
// count the categories
for( i = 1; i < num_valid; i++ )
if (*pair16u32s_ptr[i].i != *pair16u32s_ptr[i-1].i)
@@ -469,7 +480,7 @@ void CvDTreeTrainData::set_data( const CvMat* _train_data, int _tflag,
}
else
{
icvSortIntPtr( int_ptr, sample_count, 0 );
std::sort(int_ptr, int_ptr + sample_count, LessThanPtr<int>());
// count the categories
for( i = 1; i < num_valid; i++ )
c_count += *int_ptr[i] != *int_ptr[i-1];
@@ -561,9 +572,9 @@ void CvDTreeTrainData::set_data( const CvMat* _train_data, int _tflag,
}
if (is_buf_16u)
icvSortUShAux( udst, sample_count, _fdst);
std::sort(udst, udst + sample_count, LessThanIdx<float, unsigned short>(_fdst));
else
icvSortIntAux( idst, sample_count, _fdst );
std::sort(idst, idst + sample_count, LessThanIdx<float, int>(_fdst));
}
if( vi < var_count )
@@ -2239,7 +2250,7 @@ CvDTreeSplit* CvDTree::find_split_cat_class( CvDTreeNode* node, int vi, float in
int_ptr = (int**)(c_weights + _mi);
for( j = 0; j < mi; j++ )
int_ptr[j] = cjk + j*2 + 1;
icvSortIntPtr( int_ptr, mi, 0 );
std::sort(int_ptr, int_ptr + mi, LessThanPtr<int>());
subset_i = 0;
subset_n = mi;
}
@@ -2466,7 +2477,7 @@ CvDTreeSplit* CvDTree::find_split_cat_reg( CvDTreeNode* node, int vi, float init
sum_ptr[i] = sum + i;
}
icvSortDblPtr( sum_ptr, mi, 0 );
std::sort(sum_ptr, sum_ptr + mi, LessThanPtr<double>());
// revert back to unnormalized sums
// (there should be a very little loss of accuracy)