资源简介
基于二叉分类决策树的AdaBoost算法实现,特征必须为2值的,标签可为多个

代码片段和文件信息
#include
#include
#include
#include
#include “Binary_Decision_Tree.cpp“
bool first=true;
using namespace std;
const int totalTrees=10;
double line(double error){
return 0.5-error;
}
void copyArray(int *sourceint *destint length){
for(int i=0;i dest[i]=source[i];
}
void normalize(double *arrayint length){
double sum=0;
for(int i=0;i sum+=array[i];
for(int i=0;i array[i]=array[i]/sum;
}
class AdaBoost{
public:
int rowscolsnumTrees;
int total;
DecisionTree **treeSet;
double *weightSamples;
double *weightTrees;
public:
int sign(double x);
AdaBoost(int rint cint numTrees);
void train(int **featureint *category);
int predict(int *sample);
void fillSamples(int **featureint *categoryint **samplesint *types);
};
int AdaBoost::sign(double x){
if(x>0)
return 1;
else if(x==0)
return 0;
else
return -1;
}
AdaBoost::AdaBoost(int rint cint num){
rows=r;
cols=c;
numTrees=num;
total=10*rows;
weightSamples=new double[rows];
setValue(weightSamples(double)1/rowsrows);
weightTrees=new double[numTrees];
setValue(weightTrees(double)1/numTreesnumTrees);
treeSet=new DecisionTree*[numTrees];
for(int i=0;i treeSet[i]=new DecisionTree(10*rowscols);
}
void AdaBoost::train(int **featureint *category){
int **samples=new int*[total];
for(int i=0;i samples[i]=new int[cols];
int *types=new int[total];
int judge[rows];
for(int i=0;i fillSamples(featurecategorysamplestypes);
treeSet[i]->train(samplestypes);
double error=0;
setValue(judge-1rows);//correct jugment
for(int j=0;j int cat=treeSet[i]->predict(feature[j]);
if(cat!=category[j]){
judge[j]=1;//wrong jugment
error+=weightSamples[j];
}
}
weightTrees[i]=line(error);
if(weightTrees[i]>5){
cout<<“weight:“< cout<<“error:“< }
if(i+1 for(int j=0;j double exponent=weightTrees[i]*judge[j];
weightSamples[j]=weightSamples[j]*exp(exponent);
}
normalize(weightSamplesrows);
}
}
normalize(weightTreesnumTrees);
}
void AdaBoost::fillSamples(int **featureint *categoryint **samplesint *types){
int tag=0pre=0;
for(int i=0;i tag+=weightSamples[i]*total;
for(int j=pre;j copyArray(feature[i]samples[j]cols);
types[j]=category[i];
}
pre=tag;
}
if(tag for(int j=tag;j int random=rand()%rows;
copyArray(feature[random]samples[j]cols);
types[j]=category[random];
}
}
int AdaBoost::predict(int *sample){
double sum=0;
for(int i=0;i sum+=weightTrees[i]*treeSet[i]->predict(sample);
return (int)(sum+0.5);
}
int main(){
srand((unsigned)time(NULL));
int rows=1000cols=8;
AdaBoost
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 4545 2015-09-24 22:05 AdaBoost_Demo.cpp
文件 7853 2015-09-24 17:38 Binary_Decision_Tree.cpp
相关资源
- 论文研究-基于肤色和AdaBoost算法的彩
- Paul Viola 的Adaboost级联检测器英文原文
- 论文研究 - 基于EMD和BP_AdaBoost神经网络
-
ob
jectMarker正样本采集 - mit Adaboost训练人脸库
- haar+Adaboost人脸检测viola-jones人脸检测
- Adaboost人头部检测 opencv vc
- 基于Adaboost算法的人脸识别 北京大学
- Boosting方法-从AdaBoost到LightGBM
- 基于Adaboost算法的人脸检测
- 基于Adaboost算法的人脸检测研究
- 基于AdaBoost的人脸检测改进算法
- 基于AdaBoost算法的人脸检测系统设计
- 结合Gabor特征与Adaboost的人脸表情识别
-
haartraining+ob
jectmarker,opencv,Adaboo - Haar+AdaBoost人脸检测适用于DSP板子(比
- 基于Adaboost算法的实时行人检测系统
- opencv车辆检测model
- 基于AdaBoost算法的人脸检测(北京大学
- AdaBoost人脸检测程序
- HOG+Adaboost级联分类器训练代码
- Haar+Adaboost级联的目标检测程序亲测可
- 利用haar+CART+adaboost训练自己的人脸检
- Haar+Adaboost人脸检测 C实现
- 基于BP_Adaboost的强分类器设计-公司财
- adaboost 人脸识别
- 基于NavieBayes的adaboost算法实现
- AdaBoost讲解
- AdaBoost人脸识别完整实现(含特征提取
- AdaBoost实战代码
评论
共有 条评论