📄 adaboost_train_main.cpp
字号:
{
sprintf(temstr,"step numbers: %.d\n",step);
printm(temstr);
}
// take only part of matrix train(1:m,:), train_label(1:m)
Matrix *tmp = new Matrix(one,one);
Matrix *train = new Matrix(step,c_train);
Matrix *test = new Matrix(step,c_test);
Matrix *train_first = new Matrix(cycles,c_train);
Matrix *train_next = new Matrix(cycles,c_train);
Matrix *train_label = new Matrix(step,value_one+1);
Matrix *test_label = new Matrix(step,value_one+1);
Matrix *train_hypothesis = new Matrix(step,cycles+1);
Matrix *test_hypothesis = new Matrix(step,cycles+1);
Matrix *Ava_data_matrix_first = new Matrix(cycles,c_train);
Matrix *Ava_data_matrix_next= new Matrix(cycles,c_train);
train->partOfMatrix(step,c_train-1,*train_matrix);
train_label->partOfMatrix(step,zero,*train_label_matrix);
test->partOfMatrix(step,c_test-1,*test_matrix);
test_label->partOfMatrix(step,zero,*test_label_matrix);
double ave_delta = 0;
train_first->partOfMatrix(cycles,c_train-1,*train_matrix);
train_next->partOfMatrixNext(cycles,c_train-1,step,*train_matrix);
// Comapre between the average of first martix (1..100) and the next matrix (400..500)
double Sum_ava_data_first=0;
double Sum_ava_data_val_first=0;
Ava_data_matrix_first->matrixSumCol(&Sum_ava_data_first, *train_first);
Sum_ava_data_val_first = Sum_ava_data_first / (cycles * (c_train-1));
double Sum_ava_data_next=0;
double Sum_ava_data_val_next=0;
Ava_data_matrix_next->matrixSumCol(&Sum_ava_data_next, *train_next);
Sum_ava_data_val_next = Sum_ava_data_next / (cycles * (c_train-1));
ave_delta=Sum_ava_data_val_next - Sum_ava_data_val_first;
ave_delta=fabs(ave_delta);
ave_delta = 3 * ceil(ave_delta);
int sign=1;
/********************************************************/
/* boost=adaBoost(train(1:m,:),train_label(1:m),cycles);*/
/********************************************************
adaBoost(train,train_matrix,train_label,train_label_matrix,train_hypothesis,test,
test_matrix,test_label,test_label_matrix,test_hypothesis,train_max_words_doc,
train_max_docs,test_max_words_doc,test_max_docs,step,cycles,boost,train_array,
label_train_array,test_array,label_test_array,ave_delta,sign,missingValueTrain,
missingDataProcedure);
*/
/*********************************************************************************************************/
/* [errorTrain(m/step),errorTest(m/step)]=getError(boost,train(1:m,:),train_label(1:m),test,test_label); */
/*********************************************************************************************************/
Matrix* errorTrain = new Matrix(one,step/10);
Matrix* errorTest = new Matrix(one,step/10);/*
getError(boost,train_hypothesis,train_matrix,train_label_matrix,test_hypothesis,
test_matrix,test_label_matrix,errorTrain,errorTest,train_max_words_doc,
train_max_docs,step,cycles,sign);
*/
double errorTrain_value=0;
double errorTest_value=0;
tmp->getValueSpecific(0,0,&errorTrain_value,*errorTrain);
tmp->getValueSpecific(0,0,&errorTest_value,*errorTest);
if (com_pro.show_compute_1)
{
sprintf(temstr,"Train error cycle result: %f\n",errorTrain_value);
printm(temstr);
sprintf(temstr,"Test error cycle result: %f\n",errorTest_value);
printm(temstr);
}
errorTrain_acc->copy(tt,*errorTrain);
errorTest_acc->copy(tt,*errorTest);
tt=tt+1;
step = step + 100;
//delete Matrix
delete tmp;
delete train;
delete train_label;
delete test;
delete test_label;
delete errorTrain;
delete errorTest;
delete train_first;
delete train_next;
delete train_hypothesis;
delete test_hypothesis;
delete Ava_data_matrix_first;
delete Ava_data_matrix_next;
}
delete boost;
delete iii;
delete ttt;
/********************************************************************************************************/
/* step=20; */
/* maxCycles=100; */
/* for cycles=step:step:maxCycles */
/* disp(cycles); */
/* boost=adaBoost(train,train_label,cycles); */
/* [errorTrain(cycles/step),errorTest(cycles/step)]=getError(boost,train,train_label,test,test_label); */
/* clear boost; */
/* end */
/********************************************************************************************************/
if (com_pro.show_action)
printm("run adaboost algorothm with different boosting");
int ttm=0;
int step_1 = 20;
cycles=20;
int maxCycles=1001;
Matrix* errorTrain_acc_1 = new Matrix(one,50);
Matrix* errorTest_acc_1 = new Matrix(one,50);
while (step_1 < maxCycles)
{
Matrix* boost = new Matrix(step_1,one);
Matrix* boost_test = new Matrix(step_1,one);
if (com_pro.show_compute_1)
{
sprintf(temstr,"step numbers: %.d\n",step_1);
printm(temstr);
}
Matrix *tmp = new Matrix(one,one);
Matrix *train_hypothesis = new Matrix(r_train-1,cycles+1);
//Matrix *train_hypothesis = new Matrix(r_train,cycles+1);
Matrix *test_hypothesis = new Matrix(r_test,cycles+1);
Matrix *tmp_test_hypothesis = new Matrix(cycles,1);
Matrix *train = new Matrix(r_train,c_train);
Matrix *test = new Matrix(r_test,c_test);
Matrix *train_label = new Matrix(r_train-1,one);
Matrix *test_label = new Matrix(r_test-1,one);
Matrix* errorTrain_1 = new Matrix(one,maxCycles/step_1);
Matrix* errorTest_1 = new Matrix(one,maxCycles/step_1);
train->partOfMatrix(r_train,c_train-1,*train_matrix);
train_label->partOfMatrix(r_train,zero,*train_label_matrix);
double ave_delta = 0;
int sign=2;
/*********************************************/
/* boost=adaBoost(train,train_label,cycles); */
/*********************************************/
adaBoost(train,train_matrix,train_label,train_label_matrix,train_hypothesis,test,
test_matrix,test_label,test_label_matrix,test_hypothesis,train_max_words_doc,
train_max_docs,test_max_words_doc,test_max_docs,step_1,cycles,boost,train_array,
label_train_array,test_array,label_test_array,ave_delta,sign,missingValueTrain,
missingValueTest,TrainMissingDataProcedure,TestMissingDataProcedure);
/*********************************************************************************************************/
/* [errorTrain(m/step),errorTest(m/step)]=getError(boost,train(1:m,:),train_label(1:m),test,test_label); */
/*********************************************************************************************************/
getError(boost,train_hypothesis,train_matrix,train_label_matrix,test_hypothesis,
test_matrix,test_label_matrix,errorTrain_1,errorTest_1,tmp_test_hypothesis,train_max_words_doc,
train_max_docs,step_1,cycles,sign);
double errorTrain_value_1=0;
double errorTest_value_1=0;
tmp->getValueSpecific(0,0,&errorTrain_value_1,*errorTrain_1);
tmp->getValueSpecific(0,0,&errorTest_value_1,*errorTest_1);
if (com_pro.show_compute_1)
{
sprintf(temstr,"Train error cycle result: %f\n",errorTrain_value_1);
printm(temstr);
sprintf(temstr,"Test error cycle result: %f\n",errorTest_value_1);
printm(temstr);
}
errorTrain_acc_1->copy(ttm,*errorTrain_1);
errorTest_acc_1->copy(ttm,*errorTest_1);
step_1 = step_1 + 20;
cycles= cycles + 20;
ttm=ttm+1;
if (step_1 == (maxCycles + 20 - 1)){
test_matrix_day->specificPartOfMatrix(*test_matrix,step_1,0);
final_test_hypothesis->copyMatrixToMatrix(*tmp_test_hypothesis);
test_matrix_intersection->specificPartOfMatrix(*test_matrix,step_1,2);
test_matrix_link->specificPartOfMatrix(*test_matrix,step_1,3);
}
//delete Matrix
delete train;
delete train_label;
delete test;
delete test_label;
delete errorTrain_1;
delete errorTest_1;
delete boost;
delete train_hypothesis;
delete test_hypothesis;
}
/***************************************************************/
/* Get the results of Test & Train error into the results file */
/***************************************************************/
if (com_param.blAadaboostresults)
write_result(resultfile,&result, errorTrain_acc, errorTest_acc, errorTrain_acc_1,
errorTest_acc_1, test_matrix_day, test_matrix_intersection, test_matrix_link,
final_test_hypothesis,cycles);
// delete THE MATRIX
delete train_matrix;
delete train_label_matrix;
delete test_matrix;
delete test_label_matrix;
delete errorTrain_acc;
delete errorTest_acc;
delete errorTrain_acc_1;
delete errorTest_acc_1;
delete final_test_hypothesis;
delete test_matrix_intersection;
delete test_matrix_link;
delete test_matrix_day;
if (com_pro.show_action)
printm("Cease to compute adaboost algorithm");
return(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -