打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
计算后验概率SVM中的A和B
function [A,B]=platt(out,target,prior0,prior1)% find the coefficients A and B such that the posterior probability% of P(y=1|x) = 1/(1+exp(A*f(x)+B)), where f(x) is the output% of the SVM%% out: vector of outputs of the SVM on a validation set% target: validation labels% prior0: number of negative points% prior1: number of positive points%% If no validation set is available, one might use the training% set to do a leave-one-out procedure. Using the span, this means% replacing out by something like out-target.*alpha.*span%Parameter settingmaxiter=100;     %Maximum number of iterationsminstep=1e-10;   %Minimum step taken in line searchsigma=1e-12;      %Set to any value sufficient to make H' = H + sigma I always PD%Construct initial values: target support in array t, initial function value in fvalhiTarget=(prior1+1.0)/(prior1+2.0);loTarget=1/(prior0+2.0);t = (target>=0)*hiTarget + (target<0)*loTarget;A=0.0;B=log((prior0+1.0)/(prior1+1.0));%% A vector version that caculates%% fval = sum m_i%%   m_i = t_i fApB_i + log(1.0 + exp(-fApB_i)) for fApB_i >= 0%%   m_i = (t_i - 1) fApB_i + log(1.0 + exp(fApB_i)) for fApB_i < 0fApB=out*A+B;logF=log(1.0+exp(-abs(fApB)));fval = sum((t - (fApB < 0)) .* fApB + logF);% Save repeated caculation in the main loopout2=out.*out;for it = 1:maxiter%Update Gradient and Hessian (use H' = H + sigma I)%% A vector version that calculates%% d1_i = t_i - p_i%% d2_i = p_i q_i%%   p_i = exp(-fApB) / (1.0 + exp(-fApB)), q_i = 1.0 / (1.0 + exp(-fApB)) for fApB_i >= 0%%   p_i = 1.0 / (1.0 + exp(fApB)), q_i = exp(fApB) / (1.0 + exp(fApB)) for fApB_i < 0expF = exp(-abs(fApB));oneexpFinv = (1.0+expF).^(-1);d2 = expF.*oneexpFinv.*oneexpFinv;d1 = t - max(expF, (fApB<0)).*oneexpFinv;h11 = sigma + sum(out2.*d2);h22 = sigma + sum(d2);h21 = sum(out.*d2);g1 = sum(out.*d1);g2 = sum(d1);if (abs(g1)<1e-5 & abs(g2)<1e-5) %Stopping criteriabreak;end;detinv=(h11*h22-h21*h21).^(-1);dA=-(h22*g1-h21*g2) .* detinv;dB=-(-h21*g1+h11*g2) .* detinv; %Modified Newton directiongd=g1*dA+g2*dB;stepsize=1;while (stepsize >= minstep) %Line searchnewA=A+stepsize*dA;newB=B+stepsize*dB;%% A vector version that caculates%% newf = sum m_i%%   m_i = t_i fApB_i + log(1.0 + exp(-fApB_i)) for fApB_i >= 0%%   m_i = (t_i - 1) fApB_i + log(1.0 + exp(fApB_i)) for fApB_i < 0fApB=out*newA+newB;logF=log(1+exp(-abs(fApB)));newf = sum((t - (fApB < 0)) .* fApB + logF);if (newf<fval+0.0001*stepsize*gd) %Check sufficient decreaseA=newA; B=newB; fval=newf;breakelsestepsize=stepsize*0.5;end;if (stepsize < minstep) %Line search failsbreakend;end;end;
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
HMM matlab代码实现+分析
MATLAB-fminsearch函数的使用
中子关联
梯度下降 计算实例
求选股公式 EXPMA 白线金叉黄线 MACD黄线DEA上穿0轴
通达信几个麟龙代替指标
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服