Warning fixes continued

This commit is contained in:
Andrey Kamaev
2012-06-09 15:00:04 +00:00
parent f6b451c607
commit f2d3b9b4a1
127 changed files with 6298 additions and 6277 deletions

View File

@@ -504,7 +504,7 @@ void CvANN_MLP::calc_activ_func_deriv( CvMat* _xf, CvMat* _df,
n *= cols;
xf -= n; df -= n;
for( i = 0; i < n; i++ )
df[i] *= xf[i];
}
@@ -517,7 +517,7 @@ void CvANN_MLP::calc_activ_func_deriv( CvMat* _xf, CvMat* _df,
xf[j] = (xf[j] + bias[j])*scale;
df[j] = -fabs(xf[j]);
}
cvExp( _df, _df );
n *= cols;
@@ -1023,9 +1023,9 @@ int CvANN_MLP::train_backprop( CvVectors x0, CvVectors u, const double* sw )
}
struct rprop_loop {
rprop_loop(const CvANN_MLP* _point, double**& _weights, int& _count, int& _ivcount, CvVectors* _x0,
rprop_loop(const CvANN_MLP* _point, double**& _weights, int& _count, int& _ivcount, CvVectors* _x0,
int& _l_count, CvMat*& _layer_sizes, int& _ovcount, int& _max_count,
CvVectors* _u, const double*& _sw, double& _inv_count, CvMat*& _dEdw, int& _dcount0, double* _E, int _buf_sz)
CvVectors* _u, const double*& _sw, double& _inv_count, CvMat*& _dEdw, int& _dcount0, double* _E, int _buf_sz)
{
point = _point;
weights = _weights;
@@ -1044,7 +1044,7 @@ struct rprop_loop {
E = _E;
buf_sz = _buf_sz;
}
const CvANN_MLP* point;
double** weights;
int count;
@@ -1062,14 +1062,14 @@ struct rprop_loop {
double* E;
int buf_sz;
void operator()( const cv::BlockedRange& range ) const
{
double* buf_ptr;
double** x = 0;
double **df = 0;
double **df = 0;
int total = 0;
for(int i = 0; i < l_count; i++ )
total += layer_sizes->data.i[i];
CvMat* buf;
@@ -1087,7 +1087,7 @@ struct rprop_loop {
for(int si = range.begin(); si < range.end(); si++ )
{
if (si % dcount0 != 0) continue;
int n1, n2, j, k;
int n1, n2, k;
double* w;
CvMat _w, _dEdw, hdr1, hdr2, ghdr1, ghdr2, _df;
CvMat *x1, *x2, *grad1, *grad2, *temp;
@@ -1100,23 +1100,23 @@ struct rprop_loop {
// grab and preprocess input data
if( x0->type == CV_32F )
{
{
for(int i = 0; i < dcount; i++ )
{
const float* x0data = x0->data.fl[si+i];
double* xdata = x[0]+i*ivcount;
for( j = 0; j < ivcount; j++ )
for(int j = 0; j < ivcount; j++ )
xdata[j] = x0data[j]*w[j*2] + w[j*2+1];
}
}
}
else
for(int i = 0; i < dcount; i++ )
{
const double* x0data = x0->data.db[si+i];
double* xdata = x[0]+i*ivcount;
for( j = 0; j < ivcount; j++ )
for(int j = 0; j < ivcount; j++ )
xdata[j] = x0data[j]*w[j*2] + w[j*2+1];
}
}
cvInitMatHeader( x1, dcount, ivcount, CV_64F, x[0] );
// forward pass, compute y[i]=w*x[i-1], x[i]=f(y[i]), df[i]=f'(y[i])
@@ -1144,7 +1144,7 @@ struct rprop_loop {
double* gdata = grad1->data.db + i*ovcount;
double sweight = sw ? sw[si+i] : inv_count, E1 = 0;
for( j = 0; j < ovcount; j++ )
for(int j = 0; j < ovcount; j++ )
{
double t = udata[j]*w[j*2] + w[j*2+1] - xdata[j];
gdata[j] = t*sweight;
@@ -1168,7 +1168,7 @@ struct rprop_loop {
}
*E += sweight*E1;
}
// backward pass, update dEdw
#ifdef HAVE_TBB
static tbb::spin_mutex mutex;
@@ -1191,10 +1191,10 @@ struct rprop_loop {
{
double* dst = _dEdw.data.db + n1*n2;
const double* src = grad1->data.db + k*n2;
for( j = 0; j < n2; j++ )
for(int j = 0; j < n2; j++ )
dst[j] += src[j];
}
if (i > 1)
cvInitMatHeader( &_w, n1, n2, CV_64F, weights[i] );
#ifdef HAVE_TBB
@@ -1215,7 +1215,7 @@ struct rprop_loop {
int CvANN_MLP::train_rprop( CvVectors x0, CvVectors u, const double* sw )
{
const int max_buf_sz = 1 << 16;
const int max_buf_size = 1 << 16;
CvMat* dw = 0;
CvMat* dEdw = 0;
CvMat* prev_dEdw_sign = 0;
@@ -1256,7 +1256,7 @@ int CvANN_MLP::train_rprop( CvVectors x0, CvVectors u, const double* sw )
cvZero( prev_dEdw_sign );
inv_count = 1./count;
dcount0 = max_buf_sz/(2*total);
dcount0 = max_buf_size/(2*total);
dcount0 = MAX( dcount0, 1 );
dcount0 = MIN( dcount0, count );
buf_sz = dcount0*(total + max_count)*2;
@@ -1297,8 +1297,8 @@ int CvANN_MLP::train_rprop( CvVectors x0, CvVectors u, const double* sw )
double E = 0;
// first, iterate through all the samples and compute dEdw
cv::parallel_for(cv::BlockedRange(0, count),
rprop_loop(this, weights, count, ivcount, &x0, l_count, layer_sizes,
cv::parallel_for(cv::BlockedRange(0, count),
rprop_loop(this, weights, count, ivcount, &x0, l_count, layer_sizes,
ovcount, max_count, &u, sw, inv_count, dEdw, dcount0, &E, buf_sz)
);
@@ -1600,8 +1600,8 @@ CvANN_MLP::CvANN_MLP( const Mat& _layer_sizes, int _activ_func,
void CvANN_MLP::create( const Mat& _layer_sizes, int _activ_func,
double _f_param1, double _f_param2 )
{
CvMat layer_sizes = _layer_sizes;
create( &layer_sizes, _activ_func, _f_param1, _f_param2 );
CvMat cvlayer_sizes = _layer_sizes;
create( &cvlayer_sizes, _activ_func, _f_param1, _f_param2 );
}
int CvANN_MLP::train( const Mat& _inputs, const Mat& _outputs,
@@ -1610,7 +1610,7 @@ int CvANN_MLP::train( const Mat& _inputs, const Mat& _outputs,
{
CvMat inputs = _inputs, outputs = _outputs, sweights = _sample_weights, sidx = _sample_idx;
return train(&inputs, &outputs, sweights.data.ptr ? &sweights : 0,
sidx.data.ptr ? &sidx : 0, _params, flags);
sidx.data.ptr ? &sidx : 0, _params, flags);
}
float CvANN_MLP::predict( const Mat& _inputs, Mat& _outputs ) const
@@ -1618,8 +1618,8 @@ float CvANN_MLP::predict( const Mat& _inputs, Mat& _outputs ) const
CV_Assert(layer_sizes != 0);
_outputs.create(_inputs.rows, layer_sizes->data.i[layer_sizes->cols-1], _inputs.type());
CvMat inputs = _inputs, outputs = _outputs;
return predict(&inputs, &outputs);
return predict(&inputs, &outputs);
}
/* End of file. */

View File

@@ -129,7 +129,7 @@ CvBoostTree::train( CvDTreeTrainData*, const CvMat* )
void
CvBoostTree::scale( double scale )
CvBoostTree::scale( double _scale )
{
CvDTreeNode* node = root;
@@ -139,7 +139,7 @@ CvBoostTree::scale( double scale )
CvDTreeNode* parent;
for(;;)
{
node->value *= scale;
node->value *= _scale;
if( !node->left )
break;
node = node->left;
@@ -501,7 +501,7 @@ CvBoostTree::find_split_ord_reg( CvDTreeNode* node, int vi, float init_quality,
int i, best_i = -1;
double L = 0, R = weights[n];
double best_val = init_quality, lsum = 0, rsum = node->value*R;
// compensate for missing values
for( i = n1; i < n; i++ )
{
@@ -590,7 +590,7 @@ CvBoostTree::find_split_cat_reg( CvDTreeNode* node, int vi, float init_quality,
{
R += counts[i];
rsum += sum[i];
sum[i] = fabs(counts[i]) > DBL_EPSILON ? sum[i]/counts[i] : 0;
sum[i] = fabs(counts[i]) > DBL_EPSILON ? sum[i]/counts[i] : 0;
sum_ptr[i] = sum + i;
}
@@ -1030,7 +1030,7 @@ CvBoost::train( const CvMat* _train_data, int _tflag,
__BEGIN__;
int i;
set_params( _params );
cvReleaseMat( &active_vars );
@@ -1057,7 +1057,7 @@ CvBoost::train( const CvMat* _train_data, int _tflag,
if ( (_params.boost_type == LOGIT) || (_params.boost_type == GENTLE) )
data->do_responses_copy();
update_weights( 0 );
for( i = 0; i < params.weak_count; i++ )
@@ -1088,7 +1088,7 @@ CvBoost::train( const CvMat* _train_data, int _tflag,
}
bool CvBoost::train( CvMLData* _data,
CvBoostParams params,
CvBoostParams _params,
bool update )
{
bool result = false;
@@ -1105,7 +1105,7 @@ bool CvBoost::train( CvMLData* _data,
const CvMat* var_idx = _data->get_var_idx();
CV_CALL( result = train( values, CV_ROW_SAMPLE, response, var_idx,
train_sidx, var_types, missing, params, update ) );
train_sidx, var_types, missing, _params, update ) );
__END__;
@@ -1258,7 +1258,7 @@ CvBoost::update_weights( CvBoostTree* tree )
// invert the subsample mask
cvXorS( subsample_mask, cvScalar(1.), subsample_mask );
data->get_vectors( subsample_mask, values, missing, 0 );
_sample = cvMat( 1, data->var_count, CV_32F );
_mask = cvMat( 1, data->var_count, CV_8U );
@@ -1458,17 +1458,17 @@ CvBoost::trim_weights()
}
const CvMat*
const CvMat*
CvBoost::get_active_vars( bool absolute_idx )
{
CvMat* mask = 0;
CvMat* inv_map = 0;
CvMat* result = 0;
CV_FUNCNAME( "CvBoost::get_active_vars" );
__BEGIN__;
if( !weak )
CV_ERROR( CV_StsError, "The boosted tree ensemble has not been trained yet" );
@@ -1478,7 +1478,7 @@ CvBoost::get_active_vars( bool absolute_idx )
int i, j, nactive_vars;
CvBoostTree* wtree;
const CvDTreeNode* node;
assert(!active_vars && !active_vars_abs);
mask = cvCreateMat( 1, data->var_count, CV_8U );
inv_map = cvCreateMat( 1, data->var_count, CV_32S );
@@ -1518,7 +1518,7 @@ CvBoost::get_active_vars( bool absolute_idx )
}
nactive_vars = cvCountNonZero(mask);
//if ( nactive_vars > 0 )
{
active_vars = cvCreateMat( 1, nactive_vars, CV_32S );
@@ -1538,7 +1538,7 @@ CvBoost::get_active_vars( bool absolute_idx )
j++;
}
}
// second pass: now compute the condensed indices
cvStartReadSeq( weak, &reader );
@@ -1638,7 +1638,7 @@ CvBoost::predict( const CvMat* _sample, const CvMat* _missing,
"floating-point vector of the same number of components as the length of input slice" );
wstep = CV_IS_MAT_CONT(weak_responses->type) ? 1 : weak_responses->step/sizeof(float);
}
int var_count = active_vars->cols;
const int* vtype = data->var_type->data.i;
const int* cmap = data->cat_map->data.i;
@@ -1738,7 +1738,7 @@ CvBoost::predict( const CvMat* _sample, const CvMat* _missing,
CvBoostTree* wtree;
const CvDTreeNode* node;
CV_READ_SEQ_ELEM( wtree, reader );
node = wtree->get_root();
while( node->left )
{
@@ -1757,14 +1757,14 @@ CvBoost::predict( const CvMat* _sample, const CvMat* _missing,
{
const int* avars = active_vars->data.i;
const uchar* m = _missing ? _missing->data.ptr : 0;
// full-featured version
for( i = 0; i < weak_count; i++ )
{
CvBoostTree* wtree;
const CvDTreeNode* node;
CV_READ_SEQ_ELEM( wtree, reader );
node = wtree->get_root();
while( node->left )
{
@@ -1841,9 +1841,9 @@ float CvBoost::calc_error( CvMLData* _data, int type, std::vector<float> *resp )
{
CvMat sample, miss;
int si = sidx ? sidx[i] : i;
cvGetRow( values, &sample, si );
if( missing )
cvGetRow( missing, &miss, si );
cvGetRow( values, &sample, si );
if( missing )
cvGetRow( missing, &miss, si );
float r = (float)predict( &sample, missing ? &miss : 0 );
if( pred_resp )
pred_resp[i] = r;
@@ -1859,15 +1859,15 @@ float CvBoost::calc_error( CvMLData* _data, int type, std::vector<float> *resp )
CvMat sample, miss;
int si = sidx ? sidx[i] : i;
cvGetRow( values, &sample, si );
if( missing )
cvGetRow( missing, &miss, si );
if( missing )
cvGetRow( missing, &miss, si );
float r = (float)predict( &sample, missing ? &miss : 0 );
if( pred_resp )
pred_resp[i] = r;
float d = r - response->data.fl[si*r_step];
err += d*d;
}
err = sample_count ? err / (float)sample_count : -FLT_MAX;
err = sample_count ? err / (float)sample_count : -FLT_MAX;
}
return err;
}
@@ -2097,10 +2097,10 @@ CvBoost::CvBoost( const Mat& _train_data, int _tflag,
default_model_name = "my_boost_tree";
active_vars = active_vars_abs = orig_response = sum_response = weak_eval =
subsample_mask = weights = subtree_weights = 0;
train( _train_data, _tflag, _responses, _var_idx, _sample_idx,
_var_type, _missing_mask, _params );
}
}
bool
@@ -2130,7 +2130,7 @@ CvBoost::predict( const Mat& _sample, const Mat& _missing,
weak_count = weak->total;
slice.start_index = 0;
}
if( !(weak_responses->data && weak_responses->type() == CV_32FC1 &&
(weak_responses->cols == 1 || weak_responses->rows == 1) &&
weak_responses->cols + weak_responses->rows - 1 == weak_count) )

View File

@@ -71,7 +71,7 @@ void CvERTreeTrainData::set_data( const CvMat* _train_data, int _tflag,
CV_FUNCNAME( "CvERTreeTrainData::set_data" );
__BEGIN__;
int sample_all = 0, r_type, cv_n;
int total_c_count = 0;
int tree_block_size, temp_block_size, max_split_size, nv_size, cv_size = 0;
@@ -79,10 +79,10 @@ void CvERTreeTrainData::set_data( const CvMat* _train_data, int _tflag,
int vi, i, size;
char err[100];
const int *sidx = 0, *vidx = 0;
if ( _params.use_surrogates )
CV_ERROR(CV_StsBadArg, "CvERTrees do not support surrogate splits");
if( _update_data && data_root )
{
CV_ERROR(CV_StsBadArg, "CvERTrees do not support data update");
@@ -143,17 +143,17 @@ void CvERTreeTrainData::set_data( const CvMat* _train_data, int _tflag,
CV_ERROR( CV_StsBadArg, "The array of _responses must be an integer or "
"floating-point vector containing as many elements as "
"the total number of samples in the training data matrix" );
is_buf_16u = false;
if ( sample_count < 65536 )
is_buf_16u = true;
if ( sample_count < 65536 )
is_buf_16u = true;
r_type = CV_VAR_CATEGORICAL;
if( _var_type )
CV_CALL( var_type0 = cvPreprocessVarType( _var_type, var_idx, var_count, &r_type ));
CV_CALL( var_type = cvCreateMat( 1, var_count+2, CV_32SC1 ));
cat_var_count = 0;
ord_var_count = -1;
@@ -182,7 +182,7 @@ void CvERTreeTrainData::set_data( const CvMat* _train_data, int _tflag,
buf_size = (work_var_count + 1)*sample_count;
shared = _shared;
buf_count = shared ? 2 : 1;
if ( is_buf_16u )
{
CV_CALL( buf = cvCreateMat( buf_count, buf_size, CV_16UC1 ));
@@ -192,13 +192,13 @@ void CvERTreeTrainData::set_data( const CvMat* _train_data, int _tflag,
{
CV_CALL( buf = cvCreateMat( buf_count, buf_size, CV_32SC1 ));
CV_CALL( int_ptr = (int**)cvAlloc( sample_count*sizeof(int_ptr[0]) ));
}
}
size = is_classifier ? cat_var_count+1 : cat_var_count;
size = !size ? 1 : size;
CV_CALL( cat_count = cvCreateMat( 1, size, CV_32SC1 ));
CV_CALL( cat_ofs = cvCreateMat( 1, size, CV_32SC1 ));
size = is_classifier ? (cat_var_count + 1)*params.max_categories : cat_var_count*params.max_categories;
size = !size ? 1 : size;
CV_CALL( cat_map = cvCreateMat( 1, size, CV_32SC1 ));
@@ -283,12 +283,12 @@ void CvERTreeTrainData::set_data( const CvMat* _train_data, int _tflag,
{
int c_count, prev_label;
int* c_map;
if (is_buf_16u)
udst = (unsigned short*)(buf->data.s + ci*sample_count);
else
idst = buf->data.i + ci*sample_count;
// copy data
for( i = 0; i < sample_count; i++ )
{
@@ -322,7 +322,7 @@ void CvERTreeTrainData::set_data( const CvMat* _train_data, int _tflag,
_idst[i] = val;
pair16u32s_ptr[i].u = udst + i;
pair16u32s_ptr[i].i = _idst + i;
}
}
else
{
idst[i] = val;
@@ -397,7 +397,7 @@ void CvERTreeTrainData::set_data( const CvMat* _train_data, int _tflag,
// replace labels for missing values with -1
for( ; i < sample_count; i++ )
*int_ptr[i] = -1;
}
}
}
else if( ci < 0 ) // process ordered variable
{
@@ -442,15 +442,15 @@ void CvERTreeTrainData::set_data( const CvMat* _train_data, int _tflag,
if( cv_n )
{
unsigned short* udst = 0;
int* idst = 0;
unsigned short* usdst = 0;
int* idst2 = 0;
if (is_buf_16u)
{
udst = (unsigned short*)(buf->data.s + (get_work_var_count()-1)*sample_count);
usdst = (unsigned short*)(buf->data.s + (get_work_var_count()-1)*sample_count);
for( i = vi = 0; i < sample_count; i++ )
{
udst[i] = (unsigned short)vi++;
usdst[i] = (unsigned short)vi++;
vi &= vi < cv_n ? -1 : 0;
}
@@ -459,15 +459,15 @@ void CvERTreeTrainData::set_data( const CvMat* _train_data, int _tflag,
int a = (*rng)(sample_count);
int b = (*rng)(sample_count);
unsigned short unsh = (unsigned short)vi;
CV_SWAP( udst[a], udst[b], unsh );
CV_SWAP( usdst[a], usdst[b], unsh );
}
}
else
{
idst = buf->data.i + (get_work_var_count()-1)*sample_count;
idst2 = buf->data.i + (get_work_var_count()-1)*sample_count;
for( i = vi = 0; i < sample_count; i++ )
{
idst[i] = vi++;
idst2[i] = vi++;
vi &= vi < cv_n ? -1 : 0;
}
@@ -475,12 +475,12 @@ void CvERTreeTrainData::set_data( const CvMat* _train_data, int _tflag,
{
int a = (*rng)(sample_count);
int b = (*rng)(sample_count);
CV_SWAP( idst[a], idst[b], vi );
CV_SWAP( idst2[a], idst2[b], vi );
}
}
}
if ( cat_map )
if ( cat_map )
cat_map->cols = MAX( total_c_count, 1 );
max_split_size = cvAlign(sizeof(CvDTreeSplit) +
@@ -532,7 +532,7 @@ void CvERTreeTrainData::get_ord_var_data( CvDTreeNode* n, int vi, float* ord_val
const float** ord_values, const int** missing, int* sample_indices_buf )
{
int vidx = var_idx ? var_idx->data.i[vi] : vi;
int node_sample_count = n->sample_count;
int node_sample_count = n->sample_count;
// may use missing_buf as buffer for sample indices!
const int* sample_indices = get_sample_indices(n, sample_indices_buf ? sample_indices_buf : missing_buf);
@@ -580,7 +580,7 @@ const int* CvERTreeTrainData::get_cat_var_data( CvDTreeNode* n, int vi, int* cat
if( !is_buf_16u )
cat_values = buf->data.i + n->buf_idx*buf->cols + ci*sample_count + n->offset;
else {
const unsigned short* short_values = (const unsigned short*)(buf->data.s + n->buf_idx*buf->cols +
const unsigned short* short_values = (const unsigned short*)(buf->data.s + n->buf_idx*buf->cols +
ci*sample_count + n->offset);
for( int i = 0; i < n->sample_count; i++ )
cat_values_buf[i] = short_values[i];
@@ -591,7 +591,7 @@ const int* CvERTreeTrainData::get_cat_var_data( CvDTreeNode* n, int vi, int* cat
void CvERTreeTrainData::get_vectors( const CvMat* _subsample_idx,
float* values, uchar* missing,
float* responses, bool get_class_idx )
float* _responses, bool get_class_idx )
{
CvMat* subsample_idx = 0;
CvMat* subsample_co = 0;
@@ -664,7 +664,7 @@ void CvERTreeTrainData::get_vectors( const CvMat* _subsample_idx,
}
// copy responses
if( responses )
if( _responses )
{
if( is_classifier )
{
@@ -675,10 +675,10 @@ void CvERTreeTrainData::get_vectors( const CvMat* _subsample_idx,
int idx = sidx ? sidx[i] : i;
int val = get_class_idx ? src[idx] :
cat_map->data.i[cat_ofs->data.i[cat_var_count]+src[idx]];
responses[i] = (float)val;
_responses[i] = (float)val;
}
}
else
else
{
float* _values_buf = (float*)(uchar*)inn_buf;
int* sample_idx_buf = (int*)(_values_buf + sample_count);
@@ -686,7 +686,7 @@ void CvERTreeTrainData::get_vectors( const CvMat* _subsample_idx,
for( i = 0; i < count; i++ )
{
int idx = sidx ? sidx[i] : i;
responses[i] = _values[idx];
_responses[i] = _values[idx];
}
}
}
@@ -700,7 +700,7 @@ void CvERTreeTrainData::get_vectors( const CvMat* _subsample_idx,
CvDTreeNode* CvERTreeTrainData::subsample_data( const CvMat* _subsample_idx )
{
CvDTreeNode* root = 0;
CV_FUNCNAME( "CvERTreeTrainData::subsample_data" );
__BEGIN__;
@@ -853,7 +853,7 @@ CvDTreeSplit* CvForestERTree::find_split_ord_class( CvDTreeNode* node, int vi, f
const float epsilon = FLT_EPSILON*2;
const float split_delta = (1 + FLT_EPSILON) * FLT_EPSILON;
int n = node->sample_count, i;
int n = node->sample_count;
int m = data->get_num_classes();
cv::AutoBuffer<uchar> inn_buf;
@@ -882,8 +882,8 @@ CvDTreeSplit* CvForestERTree::find_split_ord_class( CvDTreeNode* node, int vi, f
for (; smpi < n; smpi++)
{
float ptemp = values[smpi];
int m = missing[smpi];
if (m) continue;
int ms = missing[smpi];
if (ms) continue;
if ( ptemp < pmin)
pmin = ptemp;
if ( ptemp > pmax)
@@ -898,7 +898,7 @@ CvDTreeSplit* CvForestERTree::find_split_ord_class( CvDTreeNode* node, int vi, f
if (split_val - pmin <= FLT_EPSILON)
split_val = pmin + split_delta;
if (pmax - split_val <= FLT_EPSILON)
split_val = pmax - split_delta;
split_val = pmax - split_delta;
// calculate Gini index
if ( !priors )
@@ -906,9 +906,9 @@ CvDTreeSplit* CvForestERTree::find_split_ord_class( CvDTreeNode* node, int vi, f
cv::AutoBuffer<int> lrc(m*2);
int *lc = lrc, *rc = lc + m;
int L = 0, R = 0;
// init arrays of class instance counters on both sides of the split
for( i = 0; i < m; i++ )
for(int i = 0; i < m; i++ )
{
lc[i] = 0;
rc[i] = 0;
@@ -917,8 +917,8 @@ CvDTreeSplit* CvForestERTree::find_split_ord_class( CvDTreeNode* node, int vi, f
{
int r = responses[si];
float val = values[si];
int m = missing[si];
if (m) continue;
int ms = missing[si];
if (ms) continue;
if ( val < split_val )
{
lc[r]++;
@@ -942,9 +942,9 @@ CvDTreeSplit* CvForestERTree::find_split_ord_class( CvDTreeNode* node, int vi, f
cv::AutoBuffer<double> lrc(m*2);
double *lc = lrc, *rc = lc + m;
double L = 0, R = 0;
// init arrays of class instance counters on both sides of the split
for( i = 0; i < m; i++ )
for(int i = 0; i < m; i++ )
{
lc[i] = 0;
rc[i] = 0;
@@ -953,9 +953,9 @@ CvDTreeSplit* CvForestERTree::find_split_ord_class( CvDTreeNode* node, int vi, f
{
int r = responses[si];
float val = values[si];
int m = missing[si];
int ms = missing[si];
double p = priors[r];
if (m) continue;
if (ms) continue;
if ( val < split_val )
{
lc[r] += p;
@@ -974,7 +974,7 @@ CvDTreeSplit* CvForestERTree::find_split_ord_class( CvDTreeNode* node, int vi, f
}
best_val = (lbest_val*R + rbest_val*L) / (L*R);
}
}
CvDTreeSplit* split = 0;
@@ -995,7 +995,7 @@ CvDTreeSplit* CvForestERTree::find_split_cat_class( CvDTreeNode* node, int vi, f
{
int ci = data->get_var_type(vi);
int n = node->sample_count;
int cm = data->get_num_classes();
int cm = data->get_num_classes();
int vm = data->cat_count->data.i[ci];
double best_val = init_quality;
CvDTreeSplit *split = 0;
@@ -1009,8 +1009,8 @@ CvDTreeSplit* CvForestERTree::find_split_cat_class( CvDTreeNode* node, int vi, f
const int* labels = data->get_cat_var_data( node, vi, ext_buf );
const int* responses = data->get_class_labels( node, ext_buf + n );
const double* priors = data->have_priors ? data->priors_mult->data.db : 0;
const double* priors = data->have_priors ? data->priors_mult->data.db : 0;
// create random class mask
cv::AutoBuffer<int> valid_cidx(vm);
@@ -1078,7 +1078,7 @@ CvDTreeSplit* CvForestERTree::find_split_cat_class( CvDTreeNode* node, int vi, f
if (var_class_mask->data.ptr[mask_class_idx])
{
lc[r]++;
L++;
L++;
split->subset[var_class_idx >> 5] |= 1 << (var_class_idx & 31);
}
else
@@ -1091,7 +1091,7 @@ CvDTreeSplit* CvForestERTree::find_split_cat_class( CvDTreeNode* node, int vi, f
{
lbest_val += lc[i]*lc[i];
rbest_val += rc[i]*rc[i];
}
}
best_val = (lbest_val*R + rbest_val*L) / ((double)(L*R));
}
else
@@ -1113,11 +1113,11 @@ CvDTreeSplit* CvForestERTree::find_split_cat_class( CvDTreeNode* node, int vi, f
continue;
double p = priors[si];
int mask_class_idx = valid_cidx[var_class_idx];
if (var_class_mask->data.ptr[mask_class_idx])
{
lc[r]+=(int)p;
L+=p;
L+=p;
split->subset[var_class_idx >> 5] |= 1 << (var_class_idx & 31);
}
else
@@ -1136,8 +1136,8 @@ CvDTreeSplit* CvForestERTree::find_split_cat_class( CvDTreeNode* node, int vi, f
split->quality = (float)best_val;
cvReleaseMat(&var_class_mask);
}
}
}
}
return split;
}
@@ -1193,7 +1193,7 @@ CvDTreeSplit* CvForestERTree::find_split_ord_reg( CvDTreeNode* node, int vi, flo
if (split_val - pmin <= FLT_EPSILON)
split_val = pmin + split_delta;
if (pmax - split_val <= FLT_EPSILON)
split_val = pmax - split_delta;
split_val = pmax - split_delta;
for (int si = 0; si < n; si++)
{
@@ -1209,7 +1209,7 @@ CvDTreeSplit* CvForestERTree::find_split_ord_reg( CvDTreeNode* node, int vi, flo
else
{
rsum += r;
R++;
R++;
}
}
best_val = (lsum*lsum*R + rsum*rsum*L)/((double)L*R);
@@ -1306,7 +1306,7 @@ CvDTreeSplit* CvForestERTree::find_split_cat_reg( CvDTreeNode* node, int vi, flo
if (var_class_mask->data.ptr[mask_class_idx])
{
lsum += r;
L++;
L++;
split->subset[var_class_idx >> 5] |= 1 << (var_class_idx & 31);
}
else
@@ -1320,8 +1320,8 @@ CvDTreeSplit* CvForestERTree::find_split_cat_reg( CvDTreeNode* node, int vi, flo
split->quality = (float)best_val;
cvReleaseMat(&var_class_mask);
}
}
}
}
return split;
}
@@ -1358,7 +1358,7 @@ void CvForestERTree::split_node_data( CvDTreeNode* node )
{
int ci = data->get_var_type(vi);
if (ci >= 0) continue;
int n1 = node->get_num_valid(vi), nr1 = 0;
float* values_buf = (float*)(uchar*)inn_buf;
int* missing_buf = (int*)(values_buf + n);
@@ -1369,7 +1369,7 @@ void CvForestERTree::split_node_data( CvDTreeNode* node )
for( i = 0; i < n; i++ )
nr1 += ((!missing[i]) & dir[i]);
left->set_num_valid(vi, n1 - nr1);
right->set_num_valid(vi, nr1);
right->set_num_valid(vi, nr1);
}
// split categorical vars, responses and cv_labels using new_idx relocation table
for( vi = 0; vi < data->get_work_var_count() + data->ord_var_count; vi++ )
@@ -1385,11 +1385,11 @@ void CvForestERTree::split_node_data( CvDTreeNode* node )
if (data->is_buf_16u)
{
unsigned short *ldst = (unsigned short *)(buf->data.s + left->buf_idx*buf->cols +
unsigned short *ldst = (unsigned short *)(buf->data.s + left->buf_idx*buf->cols +
ci*scount + left->offset);
unsigned short *rdst = (unsigned short *)(buf->data.s + right->buf_idx*buf->cols +
unsigned short *rdst = (unsigned short *)(buf->data.s + right->buf_idx*buf->cols +
ci*scount + right->offset);
for( i = 0; i < n; i++ )
{
int d = dir[i];
@@ -1415,11 +1415,11 @@ void CvForestERTree::split_node_data( CvDTreeNode* node )
}
else
{
int *ldst = buf->data.i + left->buf_idx*buf->cols +
int *ldst = buf->data.i + left->buf_idx*buf->cols +
ci*scount + left->offset;
int *rdst = buf->data.i + right->buf_idx*buf->cols +
int *rdst = buf->data.i + right->buf_idx*buf->cols +
ci*scount + right->offset;
for( i = 0; i < n; i++ )
{
int d = dir[i];
@@ -1435,7 +1435,7 @@ void CvForestERTree::split_node_data( CvDTreeNode* node )
*ldst = idx;
ldst++;
}
}
if( vi < data->var_count )
@@ -1443,7 +1443,7 @@ void CvForestERTree::split_node_data( CvDTreeNode* node )
left->set_num_valid(vi, n1 - nr1);
right->set_num_valid(vi, nr1);
}
}
}
}
// split sample indices
@@ -1457,14 +1457,14 @@ void CvForestERTree::split_node_data( CvDTreeNode* node )
temp_buf[i] = sample_idx_src[i];
int pos = data->get_work_var_count();
if (data->is_buf_16u)
{
unsigned short* ldst = (unsigned short*)(buf->data.s + left->buf_idx*buf->cols +
unsigned short* ldst = (unsigned short*)(buf->data.s + left->buf_idx*buf->cols +
pos*scount + left->offset);
unsigned short* rdst = (unsigned short*)(buf->data.s + right->buf_idx*buf->cols +
unsigned short* rdst = (unsigned short*)(buf->data.s + right->buf_idx*buf->cols +
pos*scount + right->offset);
for (i = 0; i < n; i++)
{
int d = dir[i];
@@ -1483,9 +1483,9 @@ void CvForestERTree::split_node_data( CvDTreeNode* node )
}
else
{
int* ldst = buf->data.i + left->buf_idx*buf->cols +
int* ldst = buf->data.i + left->buf_idx*buf->cols +
pos*scount + left->offset;
int* rdst = buf->data.i + right->buf_idx*buf->cols +
int* rdst = buf->data.i + right->buf_idx*buf->cols +
pos*scount + right->offset;
for (i = 0; i < n; i++)
{
@@ -1504,9 +1504,9 @@ void CvForestERTree::split_node_data( CvDTreeNode* node )
}
}
}
// deallocate the parent node data that is not needed anymore
data->free_node_data(node);
data->free_node_data(node);
}
CvERTrees::CvERTrees()
@@ -1576,10 +1576,10 @@ bool CvERTrees::train( const CvMat* _train_data, int _tflag,
__END__
return result;
}
bool CvERTrees::train( CvMLData* data, CvRTParams params)
bool CvERTrees::train( CvMLData* _data, CvRTParams params)
{
bool result = false;
@@ -1587,7 +1587,7 @@ bool CvERTrees::train( CvMLData* data, CvRTParams params)
__BEGIN__;
CV_CALL( result = CvRTrees::train( data, params) );
CV_CALL( result = CvRTrees::train( _data, params) );
__END__;
@@ -1609,7 +1609,7 @@ bool CvERTrees::grow_forest( const CvTermCriteria term_crit )
const int dims = data->var_count;
float maximal_response = 0;
CvMat* oob_sample_votes = 0;
CvMat* oob_sample_votes = 0;
CvMat* oob_responses = 0;
float* oob_samples_perm_ptr= 0;
@@ -1625,7 +1625,7 @@ bool CvERTrees::grow_forest( const CvTermCriteria term_crit )
// initialize these variable to avoid warning C4701
CvMat oob_predictions_sum = cvMat( 1, 1, CV_32FC1 );
CvMat oob_num_of_predictions = cvMat( 1, 1, CV_32FC1 );
nsamples = data->sample_count;
nclasses = data->get_num_classes();
@@ -1647,11 +1647,11 @@ bool CvERTrees::grow_forest( const CvTermCriteria term_crit )
cvGetRow( oob_responses, &oob_predictions_sum, 0 );
cvGetRow( oob_responses, &oob_num_of_predictions, 1 );
}
CV_CALL(oob_samples_perm_ptr = (float*)cvAlloc( sizeof(float)*nsamples*dims ));
CV_CALL(samples_ptr = (float*)cvAlloc( sizeof(float)*nsamples*dims ));
CV_CALL(missing_ptr = (uchar*)cvAlloc( sizeof(uchar)*nsamples*dims ));
CV_CALL(true_resp_ptr = (float*)cvAlloc( sizeof(float)*nsamples ));
CV_CALL(true_resp_ptr = (float*)cvAlloc( sizeof(float)*nsamples ));
CV_CALL(data->get_vectors( 0, samples_ptr, missing_ptr, true_resp_ptr ));
{
@@ -1661,7 +1661,7 @@ bool CvERTrees::grow_forest( const CvTermCriteria term_crit )
maximal_response = (float)MAX( MAX( fabs(minval), fabs(maxval) ), 0 );
}
}
trees = (CvForestTree**)cvAlloc( sizeof(trees[0])*max_ntrees );
memset( trees, 0, sizeof(trees[0])*max_ntrees );
@@ -1692,7 +1692,7 @@ bool CvERTrees::grow_forest( const CvTermCriteria term_crit )
sample.data.fl += dims, missing.data.ptr += dims )
{
CvDTreeNode* predicted_node = 0;
// predict oob samples
if( !predicted_node )
CV_CALL(predicted_node = tree->predict(&sample, &missing, true));
@@ -1796,12 +1796,12 @@ bool CvERTrees::grow_forest( const CvTermCriteria term_crit )
}
result = true;
cvFree( &oob_samples_perm_ptr );
cvFree( &samples_ptr );
cvFree( &missing_ptr );
cvFree( &true_resp_ptr );
cvReleaseMat( &sample_idx_for_tree );
cvReleaseMat( &oob_sample_votes );

View File

@@ -166,13 +166,13 @@ bool CvGBTrees::problem_type() const
//===========================================================================
bool
CvGBTrees::train( CvMLData* data, CvGBTreesParams params, bool update )
CvGBTrees::train( CvMLData* _data, CvGBTreesParams _params, bool update )
{
bool result;
result = train ( data->get_values(), CV_ROW_SAMPLE,
data->get_responses(), data->get_var_idx(),
data->get_train_sample_idx(), data->get_var_types(),
data->get_missing(), params, update);
result = train ( _data->get_values(), CV_ROW_SAMPLE,
_data->get_responses(), _data->get_var_idx(),
_data->get_train_sample_idx(), _data->get_var_types(),
_data->get_missing(), _params, update);
//update is not supported
return result;
}
@@ -1294,12 +1294,12 @@ CvGBTrees::calc_error( CvMLData* _data, int type, std::vector<float> *resp )
{
float err = 0.0f;
const CvMat* sample_idx = (type == CV_TRAIN_ERROR) ?
const CvMat* _sample_idx = (type == CV_TRAIN_ERROR) ?
_data->get_train_sample_idx() :
_data->get_test_sample_idx();
const CvMat* response = _data->get_responses();
int n = sample_idx ? get_len(sample_idx) : 0;
int n = _sample_idx ? get_len(_sample_idx) : 0;
n = (type == CV_TRAIN_ERROR && n == 0) ? _data->get_values()->rows : n;
if (!n)
@@ -1315,7 +1315,7 @@ CvGBTrees::calc_error( CvMLData* _data, int type, std::vector<float> *resp )
pred_resp = new float[n];
Sample_predictor predictor = Sample_predictor(this, pred_resp, _data->get_values(),
_data->get_missing(), sample_idx);
_data->get_missing(), _sample_idx);
//#ifdef HAVE_TBB
// tbb::parallel_for(cv::BlockedRange(0,n), predictor, tbb::auto_partitioner());
@@ -1323,7 +1323,7 @@ CvGBTrees::calc_error( CvMLData* _data, int type, std::vector<float> *resp )
cv::parallel_for(cv::BlockedRange(0,n), predictor);
//#endif
int* sidx = sample_idx ? sample_idx->data.i : 0;
int* sidx = _sample_idx ? _sample_idx->data.i : 0;
int r_step = CV_IS_MAT_CONT(response->type) ?
1 : response->step / CV_ELEM_SIZE(response->type);
@@ -1357,7 +1357,7 @@ CvGBTrees::CvGBTrees( const cv::Mat& trainData, int tflag,
const cv::Mat& responses, const cv::Mat& varIdx,
const cv::Mat& sampleIdx, const cv::Mat& varType,
const cv::Mat& missingDataMask,
CvGBTreesParams params )
CvGBTreesParams _params )
{
data = 0;
weak = 0;
@@ -1371,14 +1371,14 @@ CvGBTrees::CvGBTrees( const cv::Mat& trainData, int tflag,
clear();
train(trainData, tflag, responses, varIdx, sampleIdx, varType, missingDataMask, params, false);
train(trainData, tflag, responses, varIdx, sampleIdx, varType, missingDataMask, _params, false);
}
bool CvGBTrees::train( const cv::Mat& trainData, int tflag,
const cv::Mat& responses, const cv::Mat& varIdx,
const cv::Mat& sampleIdx, const cv::Mat& varType,
const cv::Mat& missingDataMask,
CvGBTreesParams params,
CvGBTreesParams _params,
bool update )
{
CvMat _trainData = trainData, _responses = responses;
@@ -1387,13 +1387,13 @@ bool CvGBTrees::train( const cv::Mat& trainData, int tflag,
return train( &_trainData, tflag, &_responses, varIdx.empty() ? 0 : &_varIdx,
sampleIdx.empty() ? 0 : &_sampleIdx, varType.empty() ? 0 : &_varType,
missingDataMask.empty() ? 0 : &_missingDataMask, params, update);
missingDataMask.empty() ? 0 : &_missingDataMask, _params, update);
}
float CvGBTrees::predict( const cv::Mat& sample, const cv::Mat& missing,
float CvGBTrees::predict( const cv::Mat& sample, const cv::Mat& _missing,
const cv::Range& slice, int k ) const
{
CvMat _sample = sample, _missing = missing;
return predict(&_sample, missing.empty() ? 0 : &_missing, 0,
CvMat _sample = sample, miss = _missing;
return predict(&_sample, _missing.empty() ? 0 : &miss, 0,
slice==cv::Range::all() ? CV_WHOLE_SEQ : cvSlice(slice.start, slice.end), k);
}

View File

@@ -141,7 +141,7 @@ bool CvKNearest::train( const CvMat* _train_data, const CvMat* _responses,
ok = true;
__END__;
if( responses && responses->data.ptr != _responses->data.ptr )
cvReleaseMat(&responses);
@@ -318,7 +318,7 @@ struct P1 {
result = _result;
buf_sz = _buf_sz;
}
const CvKNearest* pointer;
int k;
const CvMat* _samples;
@@ -329,7 +329,7 @@ struct P1 {
CvMat* _dist;
float* result;
int buf_sz;
void operator()( const cv::BlockedRange& range ) const
{
cv::AutoBuffer<float> buf(buf_sz);
@@ -429,7 +429,7 @@ bool CvKNearest::train( const Mat& _train_data, const Mat& _responses,
int _max_k, bool _update_base )
{
CvMat tdata = _train_data, responses = _responses, sidx = _sample_idx;
return train(&tdata, &responses, sidx.data.ptr ? &sidx : 0, _is_regression, _max_k, _update_base );
}
@@ -439,7 +439,7 @@ float CvKNearest::find_nearest( const Mat& _samples, int k, Mat* _results,
Mat* _dist ) const
{
CvMat s = _samples, results, *presults = 0, nresponses, *pnresponses = 0, dist, *pdist = 0;
if( _results )
{
if(!(_results->data && (_results->type() == CV_32F ||
@@ -449,7 +449,7 @@ float CvKNearest::find_nearest( const Mat& _samples, int k, Mat* _results,
_results->create(_samples.rows, 1, CV_32F);
presults = &(results = *_results);
}
if( _neighbor_responses )
{
if(!(_neighbor_responses->data && _neighbor_responses->type() == CV_32F &&
@@ -457,7 +457,7 @@ float CvKNearest::find_nearest( const Mat& _samples, int k, Mat* _results,
_neighbor_responses->create(_samples.rows, k, CV_32F);
pnresponses = &(nresponses = *_neighbor_responses);
}
if( _dist )
{
if(!(_dist->data && _dist->type() == CV_32F &&
@@ -465,15 +465,15 @@ float CvKNearest::find_nearest( const Mat& _samples, int k, Mat* _results,
_dist->create(_samples.rows, k, CV_32F);
pdist = &(dist = *_dist);
}
return find_nearest(&s, k, presults, _neighbors, pnresponses, pdist );
}
float CvKNearest::find_nearest( const cv::Mat& samples, int k, CV_OUT cv::Mat& results,
float CvKNearest::find_nearest( const cv::Mat& _samples, int k, CV_OUT cv::Mat& results,
CV_OUT cv::Mat& neighborResponses, CV_OUT cv::Mat& dists) const
{
return find_nearest(samples, k, &results, 0, &neighborResponses, &dists);
return find_nearest(_samples, k, &results, 0, &neighborResponses, &dists);
}
/* End of file */

View File

@@ -241,13 +241,13 @@ bool CvNormalBayesClassifier::train( const CvMat* _train_data, const CvMat* _res
double* cov_data = cov->data.db + i*_var_count;
double s1val = sum1[i];
double avg1 = avg_data[i];
int count = count_data[i];
int _count = count_data[i];
for( j = 0; j <= i; j++ )
{
double avg2 = avg2_data[j];
double cov_val = prod_data[j] - avg1 * sum2[j] - avg2 * s1val + avg1 * avg2 * count;
cov_val = (count > 1) ? cov_val / (count - 1) : cov_val;
double cov_val = prod_data[j] - avg1 * sum2[j] - avg2 * s1val + avg1 * avg2 * _count;
cov_val = (_count > 1) ? cov_val / (_count - 1) : cov_val;
cov_data[j] = cov_val;
}
}
@@ -294,7 +294,7 @@ struct predict_body {
value = _value;
var_count1 = _var_count1;
}
CvMat* c;
CvMat** cov_rotate_mats;
CvMat** inv_eigen_values;
@@ -306,15 +306,15 @@ struct predict_body {
CvMat* results;
float* value;
int var_count1;
void operator()( const cv::BlockedRange& range ) const
{
int cls = -1;
int rtype = 0, rstep = 0;
int rtype = 0, rstep = 0;
int nclasses = cls_labels->cols;
int _var_count = avg[0]->cols;
if (results)
{
rtype = CV_MAT_TYPE(results->type);
@@ -323,7 +323,7 @@ struct predict_body {
// allocate memory and initializing headers for calculating
cv::AutoBuffer<double> buffer(nclasses + var_count1);
CvMat diff = cvMat( 1, var_count1, CV_64FC1, &buffer[0] );
for(int k = range.begin(); k < range.end(); k += 1 )
{
int ival;
@@ -592,7 +592,7 @@ CvNormalBayesClassifier::CvNormalBayesClassifier( const Mat& _train_data, const
cov_rotate_mats = 0;
c = 0;
default_model_name = "my_nb";
CvMat tdata = _train_data, responses = _responses, vidx = _var_idx, sidx = _sample_idx;
train(&tdata, &responses, vidx.data.ptr ? &vidx : 0,
sidx.data.ptr ? &sidx : 0);
@@ -609,7 +609,7 @@ bool CvNormalBayesClassifier::train( const Mat& _train_data, const Mat& _respons
float CvNormalBayesClassifier::predict( const Mat& _samples, Mat* _results ) const
{
CvMat samples = _samples, results, *presults = 0;
if( _results )
{
if( !(_results->data && _results->type() == CV_32F &&
@@ -618,7 +618,7 @@ float CvNormalBayesClassifier::predict( const Mat& _samples, Mat* _results ) con
_results->create(_samples.rows, 1, CV_32F);
presults = &(results = *_results);
}
return predict(&samples, presults);
}

View File

@@ -307,14 +307,14 @@ bool CvRTrees::train( const CvMat* _train_data, int _tflag,
return grow_forest( params.term_crit );
}
bool CvRTrees::train( CvMLData* data, CvRTParams params )
bool CvRTrees::train( CvMLData* _data, CvRTParams params )
{
const CvMat* values = data->get_values();
const CvMat* response = data->get_responses();
const CvMat* missing = data->get_missing();
const CvMat* var_types = data->get_var_types();
const CvMat* train_sidx = data->get_train_sample_idx();
const CvMat* var_idx = data->get_var_idx();
const CvMat* values = _data->get_values();
const CvMat* response = _data->get_responses();
const CvMat* missing = _data->get_missing();
const CvMat* var_types = _data->get_var_types();
const CvMat* train_sidx = _data->get_train_sample_idx();
const CvMat* var_idx = _data->get_var_idx();
return train( values, CV_ROW_SAMPLE, response, var_idx,
train_sidx, var_types, missing, params );
@@ -331,7 +331,7 @@ bool CvRTrees::grow_forest( const CvTermCriteria term_crit )
const int dims = data->var_count;
float maximal_response = 0;
CvMat* oob_sample_votes = 0;
CvMat* oob_sample_votes = 0;
CvMat* oob_responses = 0;
float* oob_samples_perm_ptr= 0;
@@ -347,7 +347,7 @@ bool CvRTrees::grow_forest( const CvTermCriteria term_crit )
// initialize these variable to avoid warning C4701
CvMat oob_predictions_sum = cvMat( 1, 1, CV_32FC1 );
CvMat oob_num_of_predictions = cvMat( 1, 1, CV_32FC1 );
nsamples = data->sample_count;
nclasses = data->get_num_classes();
@@ -369,14 +369,14 @@ bool CvRTrees::grow_forest( const CvTermCriteria term_crit )
cvGetRow( oob_responses, &oob_predictions_sum, 0 );
cvGetRow( oob_responses, &oob_num_of_predictions, 1 );
}
oob_samples_perm_ptr = (float*)cvAlloc( sizeof(float)*nsamples*dims );
samples_ptr = (float*)cvAlloc( sizeof(float)*nsamples*dims );
missing_ptr = (uchar*)cvAlloc( sizeof(uchar)*nsamples*dims );
true_resp_ptr = (float*)cvAlloc( sizeof(float)*nsamples );
true_resp_ptr = (float*)cvAlloc( sizeof(float)*nsamples );
data->get_vectors( 0, samples_ptr, missing_ptr, true_resp_ptr );
double minval, maxval;
CvMat responses = cvMat(1, nsamples, CV_32FC1, true_resp_ptr);
cvMinMaxLoc( &responses, &minval, &maxval );
@@ -536,7 +536,7 @@ bool CvRTrees::grow_forest( const CvTermCriteria term_crit )
cvFree( &samples_ptr );
cvFree( &missing_ptr );
cvFree( &true_resp_ptr );
cvReleaseMat( &sample_idx_mask_for_tree );
cvReleaseMat( &sample_idx_for_tree );
@@ -592,9 +592,9 @@ float CvRTrees::calc_error( CvMLData* _data, int type , std::vector<float> *resp
{
CvMat sample, miss;
int si = sidx ? sidx[i] : i;
cvGetRow( values, &sample, si );
if( missing )
cvGetRow( missing, &miss, si );
cvGetRow( values, &sample, si );
if( missing )
cvGetRow( missing, &miss, si );
float r = (float)predict( &sample, missing ? &miss : 0 );
if( pred_resp )
pred_resp[i] = r;
@@ -610,15 +610,15 @@ float CvRTrees::calc_error( CvMLData* _data, int type , std::vector<float> *resp
CvMat sample, miss;
int si = sidx ? sidx[i] : i;
cvGetRow( values, &sample, si );
if( missing )
cvGetRow( missing, &miss, si );
if( missing )
cvGetRow( missing, &miss, si );
float r = (float)predict( &sample, missing ? &miss : 0 );
if( pred_resp )
pred_resp[i] = r;
float d = r - response->data.fl[si*r_step];
err += d*d;
}
err = sample_count ? err / (float)sample_count : -FLT_MAX;
err = sample_count ? err / (float)sample_count : -FLT_MAX;
}
return err;
}
@@ -635,12 +635,12 @@ float CvRTrees::get_train_error()
float *responses_ptr = (float*)cvAlloc( sizeof(float)*sample_count );
data->get_vectors( 0, values_ptr, missing_ptr, responses_ptr);
if (data->is_classifier)
{
int err_count = 0;
float *vp = values_ptr;
uchar *mp = missing_ptr;
uchar *mp = missing_ptr;
for (int si = 0; si < sample_count; si++, vp += var_count, mp += var_count)
{
CvMat sample = cvMat( 1, var_count, CV_32FC1, vp );
@@ -653,10 +653,10 @@ float CvRTrees::get_train_error()
}
else
CV_Error( CV_StsBadArg, "This method is not supported for regression problems" );
cvFree( &values_ptr );
cvFree( &missing_ptr );
cvFree( &responses_ptr );
cvFree( &responses_ptr );
return err;
}
@@ -701,7 +701,7 @@ float CvRTrees::predict( const CvMat* sample, const CvMat* missing ) const
float CvRTrees::predict_prob( const CvMat* sample, const CvMat* missing) const
{
if( nclasses == 2 ) //classification
if( nclasses == 2 ) //classification
{
cv::AutoBuffer<int> _votes(nclasses);
int* votes = _votes;
@@ -711,15 +711,15 @@ float CvRTrees::predict_prob( const CvMat* sample, const CvMat* missing) const
CvDTreeNode* predicted_node = trees[k]->predict( sample, missing );
int class_idx = predicted_node->class_idx;
CV_Assert( 0 <= class_idx && class_idx < nclasses );
++votes[class_idx];
}
return float(votes[1])/ntrees;
return float(votes[1])/ntrees;
}
else // regression
CV_Error(CV_StsBadArg, "This function works for binary classification problems only...");
CV_Error(CV_StsBadArg, "This function works for binary classification problems only...");
return -1;
}
@@ -809,15 +809,15 @@ void CvRTrees::read( CvFileStorage* fs, CvFileNode* fnode )
{
// initialize active variables mask
CvMat submask1;
cvGetCols( active_var_mask, &submask1, 0, nactive_vars );
cvGetCols( active_var_mask, &submask1, 0, nactive_vars );
cvSet( &submask1, cvScalar(1) );
if( nactive_vars < var_count )
{
CvMat submask2;
cvGetCols( active_var_mask, &submask2, nactive_vars, var_count );
cvZero( &submask2 );
}
if( nactive_vars < var_count )
{
CvMat submask2;
cvGetCols( active_var_mask, &submask2, nactive_vars, var_count );
cvZero( &submask2 );
}
}
}

View File

@@ -1065,10 +1065,10 @@ bool CvSVMSolver::solve_eps_svr( int _sample_count, int _var_count, const float*
CvSVMKernel* _kernel, double* _alpha, CvSVMSolutionInfo& _si )
{
int i;
double p = _kernel->params->p, C = _kernel->params->C;
double p = _kernel->params->p, _C = _kernel->params->C;
if( !create( _sample_count, _var_count, _samples, 0,
_sample_count*2, 0, C, C, _storage, _kernel, &CvSVMSolver::get_row_svr,
_sample_count*2, 0, _C, _C, _storage, _kernel, &CvSVMSolver::get_row_svr,
&CvSVMSolver::select_working_set, &CvSVMSolver::calc_rho ))
return false;
@@ -1101,7 +1101,7 @@ bool CvSVMSolver::solve_nu_svr( int _sample_count, int _var_count, const float**
CvSVMKernel* _kernel, double* _alpha, CvSVMSolutionInfo& _si )
{
int i;
double C = _kernel->params->C, sum;
double _C = _kernel->params->C, sum;
if( !create( _sample_count, _var_count, _samples, 0,
_sample_count*2, 0, 1., 1., _storage, _kernel, &CvSVMSolver::get_row_svr,
@@ -1110,11 +1110,11 @@ bool CvSVMSolver::solve_nu_svr( int _sample_count, int _var_count, const float**
y = (schar*)cvMemStorageAlloc( storage, sample_count*2*sizeof(y[0]) );
alpha = (double*)cvMemStorageAlloc( storage, alpha_count*sizeof(alpha[0]) );
sum = C * _kernel->params->nu * sample_count * 0.5;
sum = _C * _kernel->params->nu * sample_count * 0.5;
for( i = 0; i < sample_count; i++ )
{
alpha[i] = alpha[i + sample_count] = MIN(sum, C);
alpha[i] = alpha[i + sample_count] = MIN(sum, _C);
sum -= alpha[i];
b[i] = -_y[i];
@@ -1628,12 +1628,11 @@ bool CvSVM::train_auto( const CvMat* _train_data, const CvMat* _responses,
int svm_type, sample_count, var_count, sample_size;
int block_size = 1 << 16;
double* alpha;
int i, k;
RNG* rng = &theRNG();
// all steps are logarithmic and must be > 1
double degree_step = 10, g_step = 10, coef_step = 10, C_step = 10, nu_step = 10, p_step = 10;
double gamma = 0, C = 0, degree = 0, coef = 0, p = 0, nu = 0;
double gamma = 0, _C = 0, degree = 0, coef = 0, p = 0, nu = 0;
double best_degree = 0, best_gamma = 0, best_coef = 0, best_C = 0, best_nu = 0, best_p = 0;
float min_error = FLT_MAX, error;
@@ -1760,7 +1759,7 @@ bool CvSVM::train_auto( const CvMat* _train_data, const CvMat* _responses,
cvZero( responses_local );
// randomly permute samples and responses
for( i = 0; i < sample_count; i++ )
for(int i = 0; i < sample_count; i++ )
{
int i1 = (*rng)(sample_count);
int i2 = (*rng)(sample_count);
@@ -1779,7 +1778,7 @@ bool CvSVM::train_auto( const CvMat* _train_data, const CvMat* _responses,
{
// count class samples
int num_0=0,num_1=0;
for (i=0; i<sample_count; ++i)
for (int i=0; i<sample_count; ++i)
{
if (responses->data.i[i]==class_labels->data.i[0])
++num_0;
@@ -1875,10 +1874,10 @@ bool CvSVM::train_auto( const CvMat* _train_data, const CvMat* _responses,
}
int* cls_lbls = class_labels ? class_labels->data.i : 0;
C = C_grid.min_val;
_C = C_grid.min_val;
do
{
params.C = C;
params.C = _C;
gamma = gamma_grid.min_val;
do
{
@@ -1906,7 +1905,7 @@ bool CvSVM::train_auto( const CvMat* _train_data, const CvMat* _responses,
int train_size = trainset_size;
error = 0;
for( k = 0; k < k_fold; k++ )
for(int k = 0; k < k_fold; k++ )
{
memcpy( samples_local, samples, sizeof(samples[0])*test_size*k );
memcpy( samples_local + test_size*k, test_samples_ptr + test_size,
@@ -1930,7 +1929,7 @@ bool CvSVM::train_auto( const CvMat* _train_data, const CvMat* _responses,
EXIT;
// Compute test set error on <test_size> samples
for( i = 0; i < test_size; i++, true_resp += resp_elem_size, test_samples_ptr++ )
for(int i = 0; i < test_size; i++, true_resp += resp_elem_size, test_samples_ptr++ )
{
float resp = predict( *test_samples_ptr, var_count );
error += is_regression ? powf( resp - *(float*)true_resp, 2 )
@@ -1943,7 +1942,7 @@ bool CvSVM::train_auto( const CvMat* _train_data, const CvMat* _responses,
best_degree = degree;
best_gamma = gamma;
best_coef = coef;
best_C = C;
best_C = _C;
best_nu = nu;
best_p = p;
}
@@ -1962,9 +1961,9 @@ bool CvSVM::train_auto( const CvMat* _train_data, const CvMat* _responses,
gamma *= gamma_grid.step;
}
while( gamma < gamma_grid.max_val );
C *= C_grid.step;
_C *= C_grid.step;
}
while( C < C_grid.max_val );
while( _C < C_grid.max_val );
}
min_error /= (float) sample_count;

View File

@@ -156,7 +156,7 @@ void CvDTreeTrainData::set_data( const CvMat* _train_data, int _tflag,
int vi, i, size;
char err[100];
const int *sidx = 0, *vidx = 0;
if( _update_data && data_root )
{
data = new CvDTreeTrainData( _train_data, _tflag, _responses, _var_idx,
@@ -224,7 +224,7 @@ void CvDTreeTrainData::set_data( const CvMat* _train_data, int _tflag,
sample_count = sample_all;
var_count = var_all;
if( _sample_idx )
{
CV_CALL( sample_indices = cvPreprocessIndexArray( _sample_idx, sample_all ));
@@ -239,10 +239,10 @@ void CvDTreeTrainData::set_data( const CvMat* _train_data, int _tflag,
var_count = var_idx->rows + var_idx->cols - 1;
}
is_buf_16u = false;
if ( sample_count < 65536 )
is_buf_16u = true;
is_buf_16u = false;
if ( sample_count < 65536 )
is_buf_16u = true;
if( !CV_IS_MAT(_responses) ||
(CV_MAT_TYPE(_responses->type) != CV_32SC1 &&
CV_MAT_TYPE(_responses->type) != CV_32FC1) ||
@@ -251,13 +251,13 @@ void CvDTreeTrainData::set_data( const CvMat* _train_data, int _tflag,
CV_ERROR( CV_StsBadArg, "The array of _responses must be an integer or "
"floating-point vector containing as many elements as "
"the total number of samples in the training data matrix" );
r_type = CV_VAR_CATEGORICAL;
if( _var_type )
CV_CALL( var_type0 = cvPreprocessVarType( _var_type, var_idx, var_count, &r_type ));
CV_CALL( var_type = cvCreateMat( 1, var_count+2, CV_32SC1 ));
cat_var_count = 0;
ord_var_count = -1;
@@ -284,11 +284,11 @@ void CvDTreeTrainData::set_data( const CvMat* _train_data, int _tflag,
work_var_count = var_count + (is_classifier ? 1 : 0) // for responses class_labels
+ (have_labels ? 1 : 0); // for cv_labels
buf_size = (work_var_count + 1 /*for sample_indices*/) * sample_count;
shared = _shared;
buf_count = shared ? 2 : 1;
if ( is_buf_16u )
{
CV_CALL( buf = cvCreateMat( buf_count, buf_size, CV_16UC1 ));
@@ -298,13 +298,13 @@ void CvDTreeTrainData::set_data( const CvMat* _train_data, int _tflag,
{
CV_CALL( buf = cvCreateMat( buf_count, buf_size, CV_32SC1 ));
CV_CALL( int_ptr = (int**)cvAlloc( sample_count*sizeof(int_ptr[0]) ));
}
}
size = is_classifier ? (cat_var_count+1) : cat_var_count;
size = !size ? 1 : size;
CV_CALL( cat_count = cvCreateMat( 1, size, CV_32SC1 ));
CV_CALL( cat_ofs = cvCreateMat( 1, size, CV_32SC1 ));
size = is_classifier ? (cat_var_count + 1)*params.max_categories : cat_var_count*params.max_categories;
size = !size ? 1 : size;
CV_CALL( cat_map = cvCreateMat( 1, size, CV_32SC1 ));
@@ -389,12 +389,12 @@ void CvDTreeTrainData::set_data( const CvMat* _train_data, int _tflag,
{
int c_count, prev_label;
int* c_map;
if (is_buf_16u)
udst = (unsigned short*)(buf->data.s + vi*sample_count);
else
idst = buf->data.i + vi*sample_count;
// copy data
for( i = 0; i < sample_count; i++ )
{
@@ -428,7 +428,7 @@ void CvDTreeTrainData::set_data( const CvMat* _train_data, int _tflag,
_idst[i] = val;
pair16u32s_ptr[i].u = udst + i;
pair16u32s_ptr[i].i = _idst + i;
}
}
else
{
idst[i] = val;
@@ -502,7 +502,7 @@ void CvDTreeTrainData::set_data( const CvMat* _train_data, int _tflag,
// replace labels for missing values with -1
for( ; i < sample_count; i++ )
*int_ptr[i] = -1;
}
}
}
else if( ci < 0 ) // process ordered variable
{
@@ -536,14 +536,14 @@ void CvDTreeTrainData::set_data( const CvMat* _train_data, int _tflag,
else
idst[i] = i;
_fdst[i] = val;
}
if (is_buf_16u)
icvSortUShAux( udst, sample_count, _fdst);
else
icvSortIntAux( idst, sample_count, _fdst );
}
if( vi < var_count )
data_root->set_num_valid(vi, num_valid);
}
@@ -564,15 +564,15 @@ void CvDTreeTrainData::set_data( const CvMat* _train_data, int _tflag,
if( cv_n )
{
unsigned short* udst = 0;
int* idst = 0;
unsigned short* usdst = 0;
int* idst2 = 0;
if (is_buf_16u)
{
udst = (unsigned short*)(buf->data.s + (get_work_var_count()-1)*sample_count);
usdst = (unsigned short*)(buf->data.s + (get_work_var_count()-1)*sample_count);
for( i = vi = 0; i < sample_count; i++ )
{
udst[i] = (unsigned short)vi++;
usdst[i] = (unsigned short)vi++;
vi &= vi < cv_n ? -1 : 0;
}
@@ -581,15 +581,15 @@ void CvDTreeTrainData::set_data( const CvMat* _train_data, int _tflag,
int a = (*rng)(sample_count);
int b = (*rng)(sample_count);
unsigned short unsh = (unsigned short)vi;
CV_SWAP( udst[a], udst[b], unsh );
CV_SWAP( usdst[a], usdst[b], unsh );
}
}
else
{
idst = buf->data.i + (get_work_var_count()-1)*sample_count;
idst2 = buf->data.i + (get_work_var_count()-1)*sample_count;
for( i = vi = 0; i < sample_count; i++ )
{
idst[i] = vi++;
idst2[i] = vi++;
vi &= vi < cv_n ? -1 : 0;
}
@@ -597,12 +597,12 @@ void CvDTreeTrainData::set_data( const CvMat* _train_data, int _tflag,
{
int a = (*rng)(sample_count);
int b = (*rng)(sample_count);
CV_SWAP( idst[a], idst[b], vi );
CV_SWAP( idst2[a], idst2[b], vi );
}
}
}
if ( cat_map )
if ( cat_map )
cat_map->cols = MAX( total_c_count, 1 );
max_split_size = cvAlign(sizeof(CvDTreeSplit) +
@@ -751,7 +751,7 @@ CvDTreeNode* CvDTreeTrainData::subsample_data( const CvMat* _subsample_idx )
if (is_buf_16u)
{
unsigned short* udst = (unsigned short*)(buf->data.s + root->buf_idx*buf->cols +
unsigned short* udst = (unsigned short*)(buf->data.s + root->buf_idx*buf->cols +
vi*sample_count + root->offset);
for( i = 0; i < count; i++ )
{
@@ -762,7 +762,7 @@ CvDTreeNode* CvDTreeTrainData::subsample_data( const CvMat* _subsample_idx )
}
else
{
int* idst = buf->data.i + root->buf_idx*buf->cols +
int* idst = buf->data.i + root->buf_idx*buf->cols +
vi*sample_count + root->offset;
for( i = 0; i < count; i++ )
{
@@ -788,7 +788,7 @@ CvDTreeNode* CvDTreeTrainData::subsample_data( const CvMat* _subsample_idx )
if (is_buf_16u)
{
unsigned short* udst_idx = (unsigned short*)(buf->data.s + root->buf_idx*buf->cols +
unsigned short* udst_idx = (unsigned short*)(buf->data.s + root->buf_idx*buf->cols +
vi*sample_count + data_root->offset);
for( i = 0; i < num_valid; i++ )
{
@@ -812,7 +812,7 @@ CvDTreeNode* CvDTreeTrainData::subsample_data( const CvMat* _subsample_idx )
}
else
{
int* idst_idx = buf->data.i + root->buf_idx*buf->cols +
int* idst_idx = buf->data.i + root->buf_idx*buf->cols +
vi*sample_count + root->offset;
for( i = 0; i < num_valid; i++ )
{
@@ -840,14 +840,14 @@ CvDTreeNode* CvDTreeTrainData::subsample_data( const CvMat* _subsample_idx )
const int* sample_idx_src = get_sample_indices(data_root, (int*)(uchar*)inn_buf);
if (is_buf_16u)
{
unsigned short* sample_idx_dst = (unsigned short*)(buf->data.s + root->buf_idx*buf->cols +
unsigned short* sample_idx_dst = (unsigned short*)(buf->data.s + root->buf_idx*buf->cols +
workVarCount*sample_count + root->offset);
for (i = 0; i < count; i++)
sample_idx_dst[i] = (unsigned short)sample_idx_src[sidx[i]];
}
else
{
int* sample_idx_dst = buf->data.i + root->buf_idx*buf->cols +
int* sample_idx_dst = buf->data.i + root->buf_idx*buf->cols +
workVarCount*sample_count + root->offset;
for (i = 0; i < count; i++)
sample_idx_dst[i] = sample_idx_src[sidx[i]];
@@ -865,7 +865,7 @@ CvDTreeNode* CvDTreeTrainData::subsample_data( const CvMat* _subsample_idx )
void CvDTreeTrainData::get_vectors( const CvMat* _subsample_idx,
float* values, uchar* missing,
float* responses, bool get_class_idx )
float* _responses, bool get_class_idx )
{
CvMat* subsample_idx = 0;
CvMat* subsample_co = 0;
@@ -962,7 +962,7 @@ void CvDTreeTrainData::get_vectors( const CvMat* _subsample_idx,
}
// copy responses
if( responses )
if( _responses )
{
if( is_classifier )
{
@@ -972,7 +972,7 @@ void CvDTreeTrainData::get_vectors( const CvMat* _subsample_idx,
int idx = sidx ? sidx[i] : i;
int val = get_class_idx ? src[idx] :
cat_map->data.i[cat_ofs->data.i[cat_var_count]+src[idx]];
responses[i] = (float)val;
_responses[i] = (float)val;
}
}
else
@@ -983,7 +983,7 @@ void CvDTreeTrainData::get_vectors( const CvMat* _subsample_idx,
for( i = 0; i < count; i++ )
{
int idx = sidx ? sidx[i] : i;
responses[i] = _values[idx];
_responses[i] = _values[idx];
}
}
}
@@ -1122,7 +1122,7 @@ void CvDTreeTrainData::clear()
cvReleaseMat( &cat_map );
cvReleaseMat( &priors );
cvReleaseMat( &priors_mult );
node_heap = split_heap = 0;
sample_count = var_all = var_count = max_c_count = ord_var_count = cat_var_count = 0;
@@ -1130,7 +1130,7 @@ void CvDTreeTrainData::clear()
buf_count = buf_size = 0;
shared = false;
data_root = 0;
rng = &cv::theRNG();
@@ -1152,7 +1152,7 @@ void CvDTreeTrainData::get_ord_var_data( CvDTreeNode* n, int vi, float* ord_valu
const float** ord_values, const int** sorted_indices, int* sample_indices_buf )
{
int vidx = var_idx ? var_idx->data.i[vi] : vi;
int node_sample_count = n->sample_count;
int node_sample_count = n->sample_count;
int td_step = train_data->step/CV_ELEM_SIZE(train_data->type);
const int* sample_indices = get_sample_indices(n, sample_indices_buf);
@@ -1161,16 +1161,16 @@ void CvDTreeTrainData::get_ord_var_data( CvDTreeNode* n, int vi, float* ord_valu
*sorted_indices = buf->data.i + n->buf_idx*buf->cols +
vi*sample_count + n->offset;
else {
const unsigned short* short_indices = (const unsigned short*)(buf->data.s + n->buf_idx*buf->cols +
const unsigned short* short_indices = (const unsigned short*)(buf->data.s + n->buf_idx*buf->cols +
vi*sample_count + n->offset );
for( int i = 0; i < node_sample_count; i++ )
sorted_indices_buf[i] = short_indices[i];
*sorted_indices = sorted_indices_buf;
}
if( tflag == CV_ROW_SAMPLE )
{
for( int i = 0; i < node_sample_count &&
for( int i = 0; i < node_sample_count &&
((((*sorted_indices)[i] >= 0) && !is_buf_16u) || (((*sorted_indices)[i] != 65535) && is_buf_16u)); i++ )
{
int idx = (*sorted_indices)[i];
@@ -1179,14 +1179,14 @@ void CvDTreeTrainData::get_ord_var_data( CvDTreeNode* n, int vi, float* ord_valu
}
}
else
for( int i = 0; i < node_sample_count &&
for( int i = 0; i < node_sample_count &&
((((*sorted_indices)[i] >= 0) && !is_buf_16u) || (((*sorted_indices)[i] != 65535) && is_buf_16u)); i++ )
{
int idx = (*sorted_indices)[i];
idx = sample_indices[idx];
ord_values_buf[i] = *(train_data->data.fl + vidx* td_step + idx);
}
*ord_values = ord_values_buf;
}
@@ -1205,17 +1205,17 @@ const int* CvDTreeTrainData::get_sample_indices( CvDTreeNode* n, int* indices_bu
const float* CvDTreeTrainData::get_ord_responses( CvDTreeNode* n, float* values_buf, int*sample_indices_buf )
{
int sample_count = n->sample_count;
int _sample_count = n->sample_count;
int r_step = CV_IS_MAT_CONT(responses->type) ? 1 : responses->step/CV_ELEM_SIZE(responses->type);
const int* indices = get_sample_indices(n, sample_indices_buf);
for( int i = 0; i < sample_count &&
for( int i = 0; i < _sample_count &&
(((indices[i] >= 0) && !is_buf_16u) || ((indices[i] != 65535) && is_buf_16u)); i++ )
{
int idx = indices[i];
values_buf[i] = *(responses->data.fl + idx * r_step);
}
return values_buf;
}
@@ -1235,7 +1235,7 @@ const int* CvDTreeTrainData::get_cat_var_data( CvDTreeNode* n, int vi, int* cat_
cat_values = buf->data.i + n->buf_idx*buf->cols +
vi*sample_count + n->offset;
else {
const unsigned short* short_values = (const unsigned short*)(buf->data.s + n->buf_idx*buf->cols +
const unsigned short* short_values = (const unsigned short*)(buf->data.s + n->buf_idx*buf->cols +
vi*sample_count + n->offset);
for( int i = 0; i < n->sample_count; i++ )
cat_values_buf[i] = short_values[i];
@@ -1562,7 +1562,7 @@ bool CvDTree::train( const Mat& _train_data, int _tflag,
const Mat& _missing_mask, CvDTreeParams _params )
{
CvMat tdata = _train_data, responses = _responses, vidx=_var_idx,
sidx=_sample_idx, vtype=_var_type, mmask=_missing_mask;
sidx=_sample_idx, vtype=_var_type, mmask=_missing_mask;
return train(&tdata, _tflag, &responses, vidx.data.ptr ? &vidx : 0, sidx.data.ptr ? &sidx : 0,
vtype.data.ptr ? &vtype : 0, mmask.data.ptr ? &mmask : 0, _params);
}
@@ -1794,7 +1794,7 @@ double CvDTree::calc_node_dir( CvDTreeNode* node )
const float* val = 0;
const int* sorted = 0;
data->get_ord_var_data( node, vi, val_buf, sorted_buf, &val, &sorted, sample_idx_buf);
assert( 0 <= split_point && split_point < n1-1 );
if( !data->have_priors )
@@ -1848,7 +1848,7 @@ template<> CV_EXPORTS void Ptr<CvDTreeSplit>::delete_obj()
{
fastFree(obj);
}
DTreeBestSplitFinder::DTreeBestSplitFinder( CvDTree* _tree, CvDTreeNode* _node)
{
tree = _tree;
@@ -2310,7 +2310,7 @@ CvDTreeSplit* CvDTree::find_split_cat_class( CvDTreeNode* node, int vi, float in
}
CvDTreeSplit* split = 0;
if( best_subset >= 0 )
if( best_subset >= 0 )
{
split = _split ? _split : data->new_split_cat( 0, -1.0f );
split->var_idx = vi;
@@ -2933,7 +2933,7 @@ void CvDTree::complete_node_dir( CvDTreeNode* node )
{
int idx = labels[i];
if( !dir[i] && ( ((idx >= 0)&&(!data->is_buf_16u)) || ((idx != 65535)&&(data->is_buf_16u)) ))
{
int d = CV_DTREE_CAT_DIR(idx,subset);
dir[i] = (char)((d ^ inversed_mask) - inversed_mask);
@@ -3049,7 +3049,7 @@ void CvDTree::split_node_data( CvDTreeNode* node )
{
unsigned short *ldst, *rdst, *ldst0, *rdst0;
//unsigned short tl, tr;
ldst0 = ldst = (unsigned short*)(buf->data.s + left->buf_idx*buf->cols +
ldst0 = ldst = (unsigned short*)(buf->data.s + left->buf_idx*buf->cols +
vi*scount + left->offset);
rdst0 = rdst = (unsigned short*)(ldst + nl);
@@ -3095,9 +3095,9 @@ void CvDTree::split_node_data( CvDTreeNode* node )
else
{
int *ldst0, *ldst, *rdst0, *rdst;
ldst0 = ldst = buf->data.i + left->buf_idx*buf->cols +
ldst0 = ldst = buf->data.i + left->buf_idx*buf->cols +
vi*scount + left->offset;
rdst0 = rdst = buf->data.i + right->buf_idx*buf->cols +
rdst0 = rdst = buf->data.i + right->buf_idx*buf->cols +
vi*scount + right->offset;
// split sorted
@@ -3146,7 +3146,7 @@ void CvDTree::split_node_data( CvDTreeNode* node )
{
int ci = data->get_var_type(vi);
int n1 = node->get_num_valid(vi), nr1 = 0;
if( ci < 0 || (vi < data->var_count && !split_input_data) )
continue;
@@ -3158,11 +3158,11 @@ void CvDTree::split_node_data( CvDTreeNode* node )
if (data->is_buf_16u)
{
unsigned short *ldst = (unsigned short *)(buf->data.s + left->buf_idx*buf->cols +
unsigned short *ldst = (unsigned short *)(buf->data.s + left->buf_idx*buf->cols +
vi*scount + left->offset);
unsigned short *rdst = (unsigned short *)(buf->data.s + right->buf_idx*buf->cols +
unsigned short *rdst = (unsigned short *)(buf->data.s + right->buf_idx*buf->cols +
vi*scount + right->offset);
for( i = 0; i < n; i++ )
{
int d = dir[i];
@@ -3188,11 +3188,11 @@ void CvDTree::split_node_data( CvDTreeNode* node )
}
else
{
int *ldst = buf->data.i + left->buf_idx*buf->cols +
int *ldst = buf->data.i + left->buf_idx*buf->cols +
vi*scount + left->offset;
int *rdst = buf->data.i + right->buf_idx*buf->cols +
int *rdst = buf->data.i + right->buf_idx*buf->cols +
vi*scount + right->offset;
for( i = 0; i < n; i++ )
{
int d = dir[i];
@@ -3208,7 +3208,7 @@ void CvDTree::split_node_data( CvDTreeNode* node )
*ldst = idx;
ldst++;
}
}
if( vi < data->var_count )
@@ -3216,7 +3216,7 @@ void CvDTree::split_node_data( CvDTreeNode* node )
left->set_num_valid(vi, n1 - nr1);
right->set_num_valid(vi, nr1);
}
}
}
}
@@ -3230,9 +3230,9 @@ void CvDTree::split_node_data( CvDTreeNode* node )
int pos = data->get_work_var_count();
if (data->is_buf_16u)
{
unsigned short* ldst = (unsigned short*)(buf->data.s + left->buf_idx*buf->cols +
unsigned short* ldst = (unsigned short*)(buf->data.s + left->buf_idx*buf->cols +
pos*scount + left->offset);
unsigned short* rdst = (unsigned short*)(buf->data.s + right->buf_idx*buf->cols +
unsigned short* rdst = (unsigned short*)(buf->data.s + right->buf_idx*buf->cols +
pos*scount + right->offset);
for (i = 0; i < n; i++)
{
@@ -3252,9 +3252,9 @@ void CvDTree::split_node_data( CvDTreeNode* node )
}
else
{
int* ldst = buf->data.i + left->buf_idx*buf->cols +
int* ldst = buf->data.i + left->buf_idx*buf->cols +
pos*scount + left->offset;
int* rdst = buf->data.i + right->buf_idx*buf->cols +
int* rdst = buf->data.i + right->buf_idx*buf->cols +
pos*scount + right->offset;
for (i = 0; i < n; i++)
{
@@ -3272,9 +3272,9 @@ void CvDTree::split_node_data( CvDTreeNode* node )
}
}
}
// deallocate the parent node data that is not needed anymore
data->free_node_data(node);
data->free_node_data(node);
}
float CvDTree::calc_error( CvMLData* _data, int type, vector<float> *resp )
@@ -3304,9 +3304,9 @@ float CvDTree::calc_error( CvMLData* _data, int type, vector<float> *resp )
{
CvMat sample, miss;
int si = sidx ? sidx[i] : i;
cvGetRow( values, &sample, si );
if( missing )
cvGetRow( missing, &miss, si );
cvGetRow( values, &sample, si );
if( missing )
cvGetRow( missing, &miss, si );
float r = (float)predict( &sample, missing ? &miss : 0 )->value;
if( pred_resp )
pred_resp[i] = r;
@@ -3321,16 +3321,16 @@ float CvDTree::calc_error( CvMLData* _data, int type, vector<float> *resp )
{
CvMat sample, miss;
int si = sidx ? sidx[i] : i;
cvGetRow( values, &sample, si );
if( missing )
cvGetRow( missing, &miss, si );
cvGetRow( values, &sample, si );
if( missing )
cvGetRow( missing, &miss, si );
float r = (float)predict( &sample, missing ? &miss : 0 )->value;
if( pred_resp )
pred_resp[i] = r;
float d = r - response->data.fl[si*r_step];
err += d*d;
}
err = sample_count ? err / (float)sample_count : -FLT_MAX;
err = sample_count ? err / (float)sample_count : -FLT_MAX;
}
return err;
}
@@ -3527,7 +3527,7 @@ int CvDTree::cut_tree( int T, int fold, double min_alpha )
}
void CvDTree::free_prune_data(bool cut_tree)
void CvDTree::free_prune_data(bool _cut_tree)
{
CvDTreeNode* node = root;
@@ -3548,7 +3548,7 @@ void CvDTree::free_prune_data(bool cut_tree)
for( parent = node->parent; parent && parent->right == node;
node = parent, parent = parent->parent )
{
if( cut_tree && parent->Tn <= pruned_tree_idx )
if( _cut_tree && parent->Tn <= pruned_tree_idx )
{
data->free_node( parent->left );
data->free_node( parent->right );
@@ -3650,12 +3650,12 @@ CvDTreeNode* CvDTree::predict( const CvMat* _sample,
{
int a = c = cofs[ci];
int b = (ci+1 >= data->cat_ofs->cols) ? data->cat_map->cols : cofs[ci+1];
int ival = cvRound(val);
if( ival != val )
CV_Error( CV_StsBadArg,
"one of input categorical variable is not an integer" );
int sh = 0;
while( a < b )
{