求Rankboost算法的Matlab版源代码,或者给我链接我去下也行 10
展开全部
function [ rbf ] = RankBoost( X,Y,D,T )
%RankBoost implemetation of RankBoost algoritm
% Input:
% X - train set.
% Y - train labels.
% D - distribution function over X times X, it the form of 2D matrix.
% T - number of iteration of the boosting.
% Output:
% rbf - Ranking Function.
rbf = RankBoostFunc(T);
% w - the current distribution in any iteration, initilize to D
w = D;
for t=1:T
tic;
fprintf('RankBoost: creating the function, iteration %d out of %d\n',t,T);
WL = getBestWeakLearner(X,Y,w);
rbf.addWeakLearner(WL,t);
rbf.addAlpha(WL.alpha,t);
alpha=WL.alpha;
%update the distribution
%eval the weak learnler on the set of X and Y
h=WL.eval(X);
[hlen, ~] = size(h);
% tmph = (repmat(h,1,hlen) - repmat(h',hlen,1));
% w=w.*exp(tmph.*alpha);
[rows, cols] = size(w);
sumw = 0;
for r=1:rows
for c=1:cols
w(r,c) = w(r,c)*exp((h(r)-h(c))*alpha);
sumw = sumw + w(r,c);
end
end
%normalize w
% w = w./sum(w(:));
w = w./sumw;
toc;
end
end
%RankBoost implemetation of RankBoost algoritm
% Input:
% X - train set.
% Y - train labels.
% D - distribution function over X times X, it the form of 2D matrix.
% T - number of iteration of the boosting.
% Output:
% rbf - Ranking Function.
rbf = RankBoostFunc(T);
% w - the current distribution in any iteration, initilize to D
w = D;
for t=1:T
tic;
fprintf('RankBoost: creating the function, iteration %d out of %d\n',t,T);
WL = getBestWeakLearner(X,Y,w);
rbf.addWeakLearner(WL,t);
rbf.addAlpha(WL.alpha,t);
alpha=WL.alpha;
%update the distribution
%eval the weak learnler on the set of X and Y
h=WL.eval(X);
[hlen, ~] = size(h);
% tmph = (repmat(h,1,hlen) - repmat(h',hlen,1));
% w=w.*exp(tmph.*alpha);
[rows, cols] = size(w);
sumw = 0;
for r=1:rows
for c=1:cols
w(r,c) = w(r,c)*exp((h(r)-h(c))*alpha);
sumw = sumw + w(r,c);
end
end
%normalize w
% w = w./sum(w(:));
w = w./sumw;
toc;
end
end
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询