void ColorWindow::create_objects() { int x = 10, init_x = 10, y = 10, init_y = 10; lock_window("ColorWindow::create_objects"); change_values(); //printf("ColorWindow::create_objects 1 %p\n", this); add_tool(wheel = new PaletteWheel(this, x, y)); //printf("ColorWindow::create_objects 1\n"); wheel->create_objects(); //printf("ColorWindow::create_objects 1\n"); x += 180; add_tool(wheel_value = new PaletteWheelValue(this, x, y)); //printf("ColorWindow::create_objects 1\n"); wheel_value->create_objects(); y += 180; x = init_x; //printf("ColorWindow::create_objects 1\n"); add_tool(output = new PaletteOutput(this, x, y)); //printf("ColorWindow::create_objects 1\n"); output->create_objects(); //printf("ColorWindow::create_objects 1\n"); x += 240; y = init_y; add_tool(new BC_Title(x, y, _("Hue"), SMALLFONT)); y += 15; //printf("ColorWindow::create_objects 1 %p\n", this); add_tool(hue = new PaletteHue(this, x, y)); y += 30; //printf("ColorWindow::create_objects 1\n"); add_tool(new BC_Title(x, y, _("Saturation"), SMALLFONT)); y += 15; //printf("ColorWindow::create_objects 1\n"); add_tool(saturation = new PaletteSaturation(this, x, y)); y += 30; //printf("ColorWindow::create_objects 1\n"); add_tool(new BC_Title(x, y, _("Value"), SMALLFONT)); y += 15; //printf("ColorWindow::create_objects 1\n"); add_tool(value = new PaletteValue(this, x, y)); y += 30; //printf("ColorWindow::create_objects 1\n"); add_tool(new BC_Title(x, y, _("Red"), SMALLFONT)); y += 15; //printf("ColorWindow::create_objects 1\n"); add_tool(red = new PaletteRed(this, x, y)); y += 30; //printf("ColorWindow::create_objects 1\n"); add_tool(new BC_Title(x, y, _("Green"), SMALLFONT)); y += 15; //printf("ColorWindow::create_objects 1\n"); add_tool(green = new PaletteGreen(this, x, y)); y += 30; //printf("ColorWindow::create_objects 1\n"); add_tool(new BC_Title(x, y, _("Blue"), SMALLFONT)); y += 15; //printf("ColorWindow::create_objects 1\n"); add_tool(blue = new PaletteBlue(this, x, y)); if(thread->do_alpha) { y += 30; add_tool(new BC_Title(x, y, _("Alpha"), SMALLFONT)); y += 15; add_tool(alpha = new PaletteAlpha(this, x, y)); } update_display(); show_window(); flush(); unlock_window(); return; }
bool CvGBTrees::train( const CvMat* _train_data, int _tflag, const CvMat* _responses, const CvMat* _var_idx, const CvMat* _sample_idx, const CvMat* _var_type, const CvMat* _missing_mask, CvGBTreesParams _params, bool /*_update*/ ) //update is not supported { CvMemStorage* storage = 0; params = _params; bool is_regression = problem_type(); clear(); /* n - count of samples m - count of variables */ int n = _train_data->rows; int m = _train_data->cols; if (_tflag != CV_ROW_SAMPLE) { int tmp; CV_SWAP(n,m,tmp); } CvMat* new_responses = cvCreateMat( n, 1, CV_32F); cvZero(new_responses); data = new CvDTreeTrainData( _train_data, _tflag, new_responses, _var_idx, _sample_idx, _var_type, _missing_mask, _params, true, true ); if (_missing_mask) { missing = cvCreateMat(_missing_mask->rows, _missing_mask->cols, _missing_mask->type); cvCopy( _missing_mask, missing); } orig_response = cvCreateMat( 1, n, CV_32F ); int step = (_responses->cols > _responses->rows) ? 1 : _responses->step / CV_ELEM_SIZE(_responses->type); switch (CV_MAT_TYPE(_responses->type)) { case CV_32FC1: { for (int i=0; i<n; ++i) orig_response->data.fl[i] = _responses->data.fl[i*step]; }; break; case CV_32SC1: { for (int i=0; i<n; ++i) orig_response->data.fl[i] = (float) _responses->data.i[i*step]; }; break; default: CV_Error(CV_StsUnmatchedFormats, "Response should be a 32fC1 or 32sC1 vector."); } if (!is_regression) { class_count = 0; unsigned char * mask = new unsigned char[n]; memset(mask, 0, n); // compute the count of different output classes for (int i=0; i<n; ++i) if (!mask[i]) { class_count++; for (int j=i; j<n; ++j) if (int(orig_response->data.fl[j]) == int(orig_response->data.fl[i])) mask[j] = 1; } delete[] mask; class_labels = cvCreateMat(1, class_count, CV_32S); class_labels->data.i[0] = int(orig_response->data.fl[0]); int j = 1; for (int i=1; i<n; ++i) { int k = 0; while ((int(orig_response->data.fl[i]) - class_labels->data.i[k]) && (k<j)) k++; if (k == j) { class_labels->data.i[k] = int(orig_response->data.fl[i]); j++; } } } // inside gbt learning proccess only regression decision trees are built data->is_classifier = false; // preproccessing sample indices if (_sample_idx) { int sample_idx_len = get_len(_sample_idx); switch (CV_MAT_TYPE(_sample_idx->type)) { case CV_32SC1: { sample_idx = cvCreateMat( 1, sample_idx_len, CV_32S ); for (int i=0; i<sample_idx_len; ++i) sample_idx->data.i[i] = _sample_idx->data.i[i]; } break; case CV_8S: case CV_8U: { int active_samples_count = 0; for (int i=0; i<sample_idx_len; ++i) active_samples_count += int( _sample_idx->data.ptr[i] ); sample_idx = cvCreateMat( 1, active_samples_count, CV_32S ); active_samples_count = 0; for (int i=0; i<sample_idx_len; ++i) if (int( _sample_idx->data.ptr[i] )) sample_idx->data.i[active_samples_count++] = i; } 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); } else { sample_idx = cvCreateMat( 1, n, CV_32S ); for (int i=0; i<n; ++i) sample_idx->data.i[i] = i; } sum_response = cvCreateMat(class_count, n, CV_32F); sum_response_tmp = cvCreateMat(class_count, n, CV_32F); cvZero(sum_response); delta = 0.0f; /* in the case of a regression problem the initial guess (the zero term in the sum) is set to the mean of all the training responses, that is the best constant model */ if (is_regression) base_value = find_optimal_value(sample_idx); /* in the case of a classification problem the initial guess (the zero term in the sum) is set to zero for all the trees sequences */ else base_value = 0.0f; /* current predicition on all training samples is set to be equal to the base_value */ cvSet( sum_response, cvScalar(base_value) ); weak = new pCvSeq[class_count]; for (int i=0; i<class_count; ++i) { storage = cvCreateMemStorage(); weak[i] = cvCreateSeq( 0, sizeof(CvSeq), sizeof(CvDTree*), storage ); storage = 0; } // subsample params and data rng = &cv::theRNG(); int samples_count = get_len(sample_idx); params.subsample_portion = params.subsample_portion <= FLT_EPSILON || 1 - params.subsample_portion <= FLT_EPSILON ? 1 : params.subsample_portion; int train_sample_count = cvFloor(params.subsample_portion * samples_count); if (train_sample_count == 0) train_sample_count = samples_count; int test_sample_count = samples_count - train_sample_count; int* idx_data = new int[samples_count]; subsample_train = cvCreateMatHeader( 1, train_sample_count, CV_32SC1 ); *subsample_train = cvMat( 1, train_sample_count, CV_32SC1, idx_data ); if (test_sample_count) { subsample_test = cvCreateMatHeader( 1, test_sample_count, CV_32SC1 ); *subsample_test = cvMat( 1, test_sample_count, CV_32SC1, idx_data + train_sample_count ); } // training procedure for ( int i=0; i < params.weak_count; ++i ) { do_subsample(); for ( int k=0; k < class_count; ++k ) { find_gradient(k); CvDTree* tree = new CvDTree; tree->train( data, subsample_train ); change_values(tree, k); if (subsample_test) { CvMat x; CvMat x_miss; int* sample_data = sample_idx->data.i; int* subsample_data = subsample_test->data.i; int s_step = (sample_idx->cols > sample_idx->rows) ? 1 : sample_idx->step/CV_ELEM_SIZE(sample_idx->type); for (int j=0; j<get_len(subsample_test); ++j) { int idx = *(sample_data + subsample_data[j]*s_step); float res = 0.0f; if (_tflag == CV_ROW_SAMPLE) cvGetRow( data->train_data, &x, idx); else cvGetCol( data->train_data, &x, idx); if (missing) { if (_tflag == CV_ROW_SAMPLE) cvGetRow( missing, &x_miss, idx); else cvGetCol( missing, &x_miss, idx); res = (float)tree->predict(&x, &x_miss)->value; } else { res = (float)tree->predict(&x)->value; } sum_response_tmp->data.fl[idx + k*n] = sum_response->data.fl[idx + k*n] + params.shrinkage * res; } } cvSeqPush( weak[k], &tree ); tree = 0; } // k=0..class_count CvMat* tmp; tmp = sum_response_tmp; sum_response_tmp = sum_response; sum_response = tmp; tmp = 0; } // i=0..params.weak_count delete[] idx_data; cvReleaseMat(&new_responses); data->free_train_data(); return true; } // CvGBTrees::train(...)