



下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、clearallclctr_n=200;%thepopulationofthetrainsette_n=200;%thepopulationofthetestsetweak_learner_n=20;%thepopulationoftheweak_learnertr_set=1,5;2,3;3,2;4,6;4,7;5,9;6,5;6,7;8,5;8,8;te_se=1,5;2,3;3,2;4,6;4,7;5,9;6,5;6,7;8,5;8,8;tr_labels=2,2,1,1,2,2,1,2,1,1;te_labels=2,2,1,1,2,2,1,2,1,1;figure;subplot(2
2、,2,1);holdon;axissquare;indices=tr_labels=1;plot(tr_set(indices,1),tr_set(indices,2),b*);indices=indices;plot(tr_set(indices,1),tr_set(indices,2),r*);title(Trainingset);subplot(2,2,2);holdon;axissquare;indices=te_labels=1;plot(te_set(indices,1),te_set(indices,2),b*)3;indices=indices;plot(te_set(indi
3、ces,1),te_set(indices,2),r*);title(Trainingset);%Trainingandtestingerrorratestr_error=zeros(1,weak_learner_n);te_error=zeros(1,weak_learner_n);fori=1:weak_learner_nadaboost_model=adaboost_tr(threshold_tr,threshold_te,tr_set,tr_labels,i);第 1 页无标题L_tr,hits_tr=adaboost_te(adaboost_model,threshold_te,te
4、_set,te_labels);tr_error(i)=(tr_n-hits_tr)/tr_n;L_te,hits_te=adaboost_te(adaboost_model,threshold_te,te_set,te_labels);te_error(i)=(te_n-hits_te)/te_n;endsubplot(2,2,3);plot(1:weak_learner_n,tr_error);axis(1,weak_learner_n,0,1);title(TrainingError);xlabel(weakclassifiernumber);ylabel(errorrate);grid
5、on;subplot(2,2,4);axissquare;plot(1:weak_learner_n,te_error);axis(1,weak_learner_n,0,1);title(TestingError);xlabel(weakclassifiernumber);ylabel(errorrate);gridon;这里需要另外分别撰写两个函数,其中一个为生成 adaboost 模型的训练函数,另外为测试测试样本的测试函数。代码如下:functionadaboost_model=adaboost_tr(tr_func_handle,te_func_handle,train_set,lab
6、els,no_of_hypothesis)%训练函数adaboost_model=struct(weights,zeros(1,no_of_hypothesis),parameters/);%cell(1,no_of_hypothesis);sample_n=size(train_set,1);samples_weight=ones(sample_n,1)/sample_n;forturn=1:no_of_hypothesisadaboost_model.parametersturn=tr_func_handle(train_set,samples_weight,labels);L,hits,
7、error_rate=te_func_handle(adaboost_model.parametersturn,train_set,samples_weight,labels);if(error_rate=1)error_rate=1-eps;elseif(error_rate=0)error_rate=eps;end%Theweightoftheturn-thweakclassifieradaboost_model.weights(turn)=10g10(1-error_rate)/error_rate);C=likelihood2class(L);t_labeled=(C=labels);
8、%truelabeledsamples%Importanceofthetrueclassifiedsamplesisdecreasedforthenextweakclassifiersamples_weight(t_labeled)=samples_weight(t_labeled)*.(error_rate)/(1-error_rate);%Normalization第 2 页无标题samples_weight=samples_weight/sum(samples_weight);end%Normalizationadaboost_model.weights=adaboost_model.w
9、eights/sum(adaboost_model.weights);functionL,hits=adaboost_te(adaboost_model,te_func_handle,test_set,.true_labels)%高函数hypothesis_n=length(adaboost_model.weights);sample_n=size(test_set,1);class_n=length(unique(true_labels);temp_L=zeros(sample_n,class_n,hypothesis_n);fori=1:hypothesis_ntemp_L(:,:,i),
10、hits,error_rate=te_func_handle(adaboost_model.parametersi,.test_set,ones(sample_n,1),true_labels);temp_L(:,:,i)=temp_L(:,:,i)*adaboost_model.weights(i);endL=sum(temp_L,3);hits=sum(likelihood2class(L)=true_labels);其中上面函数由于体积太大, 另外还需要分别撰写两个阈值函数和一个隶属分配函数。functionmodel=threshold_tr(train_set,sample_weig
11、hts,labels)%训练阈值函数model=struct(min_error,min_error_thr,pos_neg,dim,);sample_n=size(train_set,1);min_error=sum(sample_weights);min_error_thr=0;pos_neg=pos;%foreachdimensionfordim=1:size(train_set,2)sorted=sort(train_set(:,dim),1,ascend);%foreachintervalinthespecifieddimensionfori=1:(sample_n+1)if(i=1
12、)thr=sorted(1)-0.5;elseif(i=sample_n+1)thr=sorted(sample_n)+0.5;elsethr=(sorted(i-1)+sorted(i)/2;endind1=train_set(:,dim)thr;ind2=ind1;tmp_err=sum(sample_weights(labels.*ind1)=2)+sum(sample_weights(labels.*ind2)=1);if(tmp_errmin_error)第 3M无标题min_error=tmp_err;min_error_thr=thr;pos_neg=pos;model.dim=
13、dim;endind1=train_set(:,dim)thr;ind2=ind1;tmp_err=sum(sample_weights(labels.*ind1)=1)+sum(sample_weights(labels.*ind2)=2);if(tmp_errmodel.min_error_thr)+1;elseind=(featmodel.min_error_thr)+1;endhits=sum(ind=true_labels);error_rate=sum(sample_weights(ind=true_labels);L=zeros(length(feat),2);L(ind=1,1)=1;L(ind=2,2)=1;functionclas
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 智慧小镇申论题目及答案
- 六年级数学教研组工作计划(5篇)
- 食品饮料餐饮销售市场推广拓展计划
- 农业生产技术规范及标准
- 中级爆破工程考试试题及答案
- 2025年山东省烟台市事业单位工勤技能考试题库(含答案)
- CN120269262A 一种装修用支架焊接的辅助工装 (苏州卿露扬精密机械科技有限公司)
- CN120111157B 基于fpga的高清图像旋转系统及方法 (成都维德青云电子有限公司)
- UPS电池安装安全培训课件
- CN120107836A 一种体育跑道路面损伤识别方法 (泉州信息工程学院)
- 2025年在线少儿英语培训行业当前发展趋势与投资机遇洞察报告
- 石油管道保护施工方案
- 2025秋开学典礼 校长引用电影《长安的荔枝》讲话:荔枝尚早,路正长远-在时光中奔跑,用行动送达自己的“长安”
- 中级经济师模拟试题及答案
- 家庭食品卫生知识培训课件
- 无人机应用技术培训教材
- 地铁安保培训课件
- 华中数控车床课件
- 2025年食品安全监督员专业技能考核试题及答案解析
- 七年级初一新生家长会上校长走心讲话:陪孩子一起长大是一场不能重来的旅程
- 企业微信办公使用教程
评论
0/150
提交评论