MCPcopy Create free account
hub / github.com/biometrics/openbr / update_weights

Method update_weights

openbr/core/boost.cpp:1120–1359  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1118}
1119
1120void CascadeBoost::update_weights(CvBoostTree* tree)
1121{
1122 int n = data->sample_count;
1123 double sumW = 0.;
1124 int step = 0;
1125 float* fdata = 0;
1126 int *sampleIdxBuf;
1127 const int* sampleIdx = 0;
1128 int inn_buf_size = ((params.boost_type == LOGIT) || (params.boost_type == GENTLE) ? n*sizeof(int) : 0) +
1129 ( !tree ? n*sizeof(int) : 0 );
1130 cv::AutoBuffer<uchar> inn_buf(inn_buf_size);
1131 uchar* cur_inn_buf_pos = (uchar*)inn_buf;
1132 if ( (params.boost_type == LOGIT) || (params.boost_type == GENTLE) )
1133 {
1134 step = CV_IS_MAT_CONT(data->responses_copy->type) ?
1135 1 : data->responses_copy->step / CV_ELEM_SIZE(data->responses_copy->type);
1136 fdata = data->responses_copy->data.fl;
1137 sampleIdxBuf = (int*)cur_inn_buf_pos; cur_inn_buf_pos = (uchar*)(sampleIdxBuf + n);
1138 sampleIdx = data->get_sample_indices( data->data_root, sampleIdxBuf );
1139 }
1140 CvMat* buf = data->buf;
1141 size_t length_buf_row = data->get_length_subbuf();
1142 if( !tree ) // before training the first tree, initialize weights and other parameters
1143 {
1144 int* classLabelsBuf = (int*)cur_inn_buf_pos; cur_inn_buf_pos = (uchar*)(classLabelsBuf + n);
1145 const int* classLabels = data->get_class_labels(data->data_root, classLabelsBuf);
1146 // in case of logitboost and gentle adaboost each weak tree is a regression tree,
1147 // so we need to convert class labels to floating-point values
1148 double w0 = 1./n;
1149 double p[2] = { 1, 1 };
1150
1151 cvReleaseMat( &orig_response );
1152 cvReleaseMat( &sum_response );
1153 cvReleaseMat( &weak_eval );
1154 cvReleaseMat( &subsample_mask );
1155 cvReleaseMat( &weights );
1156
1157 orig_response = cvCreateMat( 1, n, CV_32S );
1158 weak_eval = cvCreateMat( 1, n, CV_64F );
1159 subsample_mask = cvCreateMat( 1, n, CV_8U );
1160 weights = cvCreateMat( 1, n, CV_64F );
1161 subtree_weights = cvCreateMat( 1, n + 2, CV_64F );
1162
1163 if (data->is_buf_16u)
1164 {
1165 unsigned short* labels = (unsigned short*)(buf->data.s + data->data_root->buf_idx*length_buf_row +
1166 data->data_root->offset + (data->work_var_count-1)*data->sample_count);
1167 for( int i = 0; i < n; i++ )
1168 {
1169 // save original categorical responses {0,1}, convert them to {-1,1}
1170 orig_response->data.i[i] = classLabels[i]*2 - 1;
1171 // make all the samples active at start.
1172 // later, in trim_weights() deactivate/reactive again some, if need
1173 subsample_mask->data.ptr[i] = (uchar)1;
1174 // make all the initial weights the same.
1175 weights->data.db[i] = w0*p[classLabels[i]];
1176 // set the labels to find (from within weak tree learning proc)
1177 // the particular sample weight, and where to store the response.

Callers

nothing calls this directly

Calls 5

logRatioFunction · 0.85
get_sample_indicesMethod · 0.80
get_class_labelsMethod · 0.80
predictMethod · 0.80
expFunction · 0.50

Tested by

no test coverage detected