资源简介
Boosting算法的MATLAB代码实现
代码片段和文件信息
classdef Adaboost < handle
%Adaboost
properties
k_max;
k_next;
k_cur;
part_trains;
base_learner;
learners;
learner_weights;
early_terminate;
d_weights;
d_size;
end
methods
function a = Adaboost(k_max base_learner early_terminate)
%k-max: Size of the model integer >= 1
%base_learner: Model constructor function e.g. @()CART()
%The model must be an object with methods a.train(inputs outputs)
%and outputs = a.test(inputs).
%early_terminate: Optional detemines whether to terminate if base
%learner error is greater than 0.5 (default is to continue and the
%base learner receives a negative weight).
if (nargin < 3)
early_terminate = false;
end
a.k_max = k_max;
a.part_trains = a.k_max;
a.k_next = a.k_max;
a.learners = cell(a.k_max 1);
a.learner_weights = zeros(a.k_max 1);
a.base_learner = base_learner;
a.early_terminate = early_terminate;
a.k_cur = 0;
end
function part_train(a inputs outputs k_next)
a.k_next = k_next;
a.train(inputs outputs);
a.k_next = a.k_max;
end
function train(a inputs outputs)
if (a.k_cur == 0)
a.d_size = size(inputs 1);
a.d_weights = ones(a.d_size 1) ./ a.d_size;
end
while (a.k_cur < a.k_next)
a.k_cur = a.k_cur + 1;
%Create an NxN square of cumulatively summed weights (i.e. N
%rows containing the weight cumsum). Create an NxN square of random
%numbers (N columns containing the same N random numbers). Compare
%them and sum the rows. The number of weights that are less than
%each random number indicates the index sampled by that row.
indices = sum(repmat(cumsum(a.d_weights)‘ a.d_size 1) <= ...
repmat(rand(a.d_size 1) 1 a.d_size) 2) + 1;
a.learners{a.k_cur} = a.base_learner();
a.learners{a.k_cur}.train(inputs(indices :) outputs(indices));
predictions = a.learners{a.k_cur}.test(inputs) == outputs;
weighted_error = sum(~predictions .* a.d_weights);
if (a.early_terminate && weighted_error > 0.5)
a.k_max = a.k_cur - 1;
a.k_cur = a.k_cur - 1;
a.learner_weights = a.learner_weights(1:a.k_max);
break;
end
weighted_error = min(max(weighted_error 0.01) 0.99);
a.learner_weights(a.k_cur) = 0.5 * log((1 - weighted_error) / weighted_error);
a.d_weights = feval(@(x)x./sum(x) a.d_weights .* ...
exp(-a.learner_weights(a.k_cur) * ssign(predictions)));
end
end
function outputs = test(a inputs)
outputs = ssign(a.margins(inputs));
end
function margins = margins(a inputs)
margins = cell2mat(arrayfun(@(x)a.learners{x}.test(i
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3166 2014-01-15 22:55 boosting_demo\boosting_demo\Adaboost.m
文件 18577 2014-01-15 22:55 boosting_demo\boosting_demo\boosting_demo.m
文件 784 2014-01-15 22:55 boosting_demo\boosting_demo\CART.m
文件 3095 2014-01-15 22:55 boosting_demo\boosting_demo\DataGen.m
文件 5002 2014-01-15 22:55 boosting_demo\boosting_demo\LinearRegression.m
文件 1189 2014-01-15 22:55 boosting_demo\boosting_demo\NeuralNetwork.m
文件 2619 2014-01-15 22:55 boosting_demo\boosting_demo\OnlineNaiveBayes.m
文件 323 2014-01-15 22:55 boosting_demo\boosting_demo\ssign.m
文件 1395 2014-01-15 22:55 boosting_demo\boosting_demo\Stump.m
文件 692 2014-01-15 22:55 boosting_demo\boosting_demo\SVM.m
文件 1340 2014-01-15 22:55 boosting_demo\license.txt
目录 0 2014-01-15 22:55 boosting_demo\boosting_demo
目录 0 2014-01-15 22:55 boosting_demo
----------- --------- ---------- ----- ----
38182 13
- 上一篇:matlab dtmf
- 下一篇:函数绘图软件
相关资源
- matlab dtmf
- matlab孤立点提取函数
- MIMO信道容量仿真matlab代码
- 图像彩色增强matlab源码
- 轮廓波变换及其去噪的程序
- 平稳小波变换程序及其应用
- 电力负荷分配matlab程序part2
- 电力负荷分配matlab程序
- 基于MATLAB的二级斜齿轮减速器优化设
- matlab电磁波趋肤深度程序
- 基于MATLAB标定工具箱的鱼眼相机标定
- MATLAB控制系统仿真与详解附书光盘.
- 图像拉普拉斯金字塔融合算法源代码
- 锯齿波的傅里叶级数matlab实现
- 史密斯圆图动态展示
- 基于相关系数的影像匹配matlab
- 图像分割评价函数
- 2*1的Alamouti空时码BER性能曲线matlab源码
- MATLAB音乐合成
- 保持邻域嵌入算法也就是NPE算法的M
- 免疫算法和遗传算法解决物流选址问
- 微分方程求解原理 matlab 代码+斜率图
- QPSK信号+白噪声程序MATLAB
- 迈克尔逊干涉仪matlab仿真程序
- matlab图像双三次插值自写函数
- 算数编码、解码,Matlab程序
- matlab中.mat数据格式转换为txt格式
- Matlab波特图Bode绘制
- 格理论LLL算法源码
- Matlab / R ReferenceMatlab R 函数对照手册
评论
共有 条评论