



下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
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;這里需要另外分別撰寫兩個函數(shù),其中一個為生成 adaboost 模型的訓(xùn)練函數(shù),另外為測試測試樣本的測試函數(shù)。代碼如下:functionadaboost_model=adaboost_tr(tr_func_handle,te_func_handle,train_set,lab
6、els,no_of_hypothesis)%訓(xùn)練函數(shù)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)%高函數(shù)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);其中上面函數(shù)由于體積太大, 另外還需要分別撰寫兩個閾值函數(shù)和一個隸屬分配函數(shù)。functionmodel=threshold_tr(train_set,sample_weig
11、hts,labels)%訓(xùn)練閾值函數(shù)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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 商丘學(xué)院《建筑信息建模(BM)》2023-2024學(xué)年第二學(xué)期期末試卷
- 九江理工職業(yè)學(xué)院《動物病毒與人類健康》2023-2024學(xué)年第二學(xué)期期末試卷
- 湖南工程學(xué)院《數(shù)據(jù)結(jié)構(gòu)與算法分析課程設(shè)計》2023-2024學(xué)年第二學(xué)期期末試卷
- 《活動二 安全網(wǎng)上行》(教學(xué)設(shè)計)-2023-2024學(xué)年六年級上冊綜合實踐活動蒙滬版
- 遼寧現(xiàn)代服務(wù)職業(yè)技術(shù)學(xué)院《美術(shù)表現(xiàn)一中國畫》2023-2024學(xué)年第二學(xué)期期末試卷
- 海南外國語職業(yè)學(xué)院《自然地理基礎(chǔ)》2023-2024學(xué)年第二學(xué)期期末試卷
- 地震數(shù)據(jù)采集系統(tǒng)項目效益評估報告
- 山東商務(wù)職業(yè)學(xué)院《工程技術(shù)基礎(chǔ)》2023-2024學(xué)年第二學(xué)期期末試卷
- 鄭州商貿(mào)旅游職業(yè)學(xué)院《跨境電商平臺操作》2023-2024學(xué)年第二學(xué)期期末試卷
- 武漢商學(xué)院《文獻檢索與學(xué)術(shù)訓(xùn)練》2023-2024學(xué)年第二學(xué)期期末試卷
- 2024年廣告部業(yè)務(wù)年度工作計劃樣本(3篇)
- 《大學(xué)生創(chuàng)新創(chuàng)業(yè)實務(wù)》課件-2.1創(chuàng)新思維訓(xùn)練 訓(xùn)練創(chuàng)新思維
- 能源管理軟件招標模板高效節(jié)能
- 城鄉(xiāng)環(huán)衛(wèi)保潔投標方案
- 有效喝酒免責協(xié)議書(2篇)
- 《高血脂相關(guān)知識》課件
- 統(tǒng)編版語文六年級下冊3《古詩三首》課件
- 雅禮中學(xué)2024-2025學(xué)年初三創(chuàng)新人才選拔數(shù)學(xué)試題及答案
- 廣東清遠人文介紹
- 豐田的全面質(zhì)量管理
- 《黃金基礎(chǔ)知識培訓(xùn)》課件
評論
0/150
提交評論