% SB1_ESTIMATE Estimate parameters in a sparse Bayesian model
%
% [W,USED,ML,A,B,G] = SB1_ESTIMATE(PHI,T,A,B,MAXITS,MONITS)
%
% OUTPUT ARGUMENTS:
%
% W Estimated weights (subset of full model)
% USED Indices of relevant basis vectors
% ML Marginal likelihood of final model
% A Estimated 'alpha' values
% B Estimated 'beta' value for regression
% G Estimated 'gamma' (well-determinedness) parameters
%
% INPUT ARGUMENTS:
%
% PHI Basis function/design matrix
% T Target vector
% A Initial alpha value (scalar)
% B Initial beta value
% - set to zero for classification
% - set negative to fix in regression,
% MAXITS Maximum number of iterations to run for
% MONITS Monitor estimation progress every MONITS iterations
% [optional, defaults to zero]
%
%
% NOTES: Arguments should be self-explanatory, although in regression
% a negative value for BETA is used to indicate that it should
% remain fixed (to the positive value) during estimation.
%
% Copyright 2009 :: Michael E. Tipping
%
% This file is part of the SPARSEBAYES baseline implementation (V1.10)
%
% Contact the author: m a i l [at] m i k e t i p p i n g . c o m
%
function [weights, used, marginal, alpha, beta, gamma] = ...
SB1_Estimate(PHI,t,alpha,beta,maxIts,monIts)
% Terminate estimation when no log-alpha value changes by more than this
MIN_DELTA_LOGALPHA = 1e-3;
% Prune basis function when its alpha is greater than this
% - reduce this to be more agressive
%
ALPHA_MAX = 1e9;
% Default to no monitoring
if ~exist('monIts','var')
monIts = 0;
end
REGRESSION = (beta~=0);
if REGRESSION
% Regression settings
%
% - negative beta is used to indicate that the noise model
% is to remain fixed
%
FIXED_BETA = beta<0;
beta = abs(beta);
else
% Classification settings
%
maxIts_pm = 25; % Maximum iterations for posterior mode-finder
end
% Set up parameters and hyperparameters
[N,M] = size(PHI);
w = zeros(M,1);
alpha = alpha*ones(M,1);
gamma = ones(M,1);
% Useful shortcut
PHIt = PHI'*t;
%
LAST_IT = 0;
%
% The main loop
%
for i=1:maxIts
%
% Prune based on large values of alpha
%
useful = (alpha<ALPHA_MAX);
alpha_used = alpha(useful);
M = sum(useful);
%
% Prune weights and basis
%
w(~useful) = 0;
PHI_used = PHI(:,useful);
%
% Compute key stats:
%
% - most probable weights
% - inverse Cholesky factor
% - data error
%
if REGRESSION
%
% Calculation is analytic for Gaussian likelihood here
%
Hessian = (PHI_used'*PHI_used)*beta + diag(alpha_used);
try chol(Hessian);
Hessian = Hessian;
catch ME;
X = diag(rand(size(Hessian,1),1));
U = orth(rand(size(Hessian,1),size(Hessian,1)));
Hessian = U' * X * U;
end
U = chol(Hessian);
Ui = inv(U);
w(useful) = (Ui * (Ui' * PHIt(useful)))*beta;
%
ED = sum((t-PHI_used*w(useful)).^2); % Data error
dataLikely = (N*log(beta) - beta*ED)/2;
else
%
% Must call posterior mode finder for Bernoulli likelihood
%
[w(useful) Ui dataLikely] = ...
SB1_PosteriorMode(PHI_used,t,w(useful),alpha_used,maxIts_pm);
end
%
% Need determinant and diagonal values of
% posterior weight covariance matrix (SIGMA in paper)
%
logdetH = -2*sum(log(diag(Ui)));
diagSig = sum(Ui.^2,2);
%
% Well-determinedness parameters (gamma)
%
gamma = 1 - alpha_used.*diagSig;
%
% Compute marginal likelihood (approximation for classification case)
%
marginal = dataLikely - 0.5*(logdetH - sum(log(alpha_used)) + ...
(w(useful).^2)'*alpha_used);
%
% Output diagnostic info when requested and at end
%
if (LAST_IT || (monIts && ~rem(i,monIts)))
if REGRESSION
SB1_Diagnostic(1,'%5d> L = %.3f\t Gamma = %.2f (nz = %d)\t s=%.3f\n',...
i, marginal, sum(gamma), sum(useful), sqrt(1/beta));
else
SB1_Diagnostic(1,'%5d> L = %.3f\t Gamma = %.2f (nz = %d)\n',...
i, marginal, sum(gamma), sum(useful));
end
end
if ~LAST_IT
%
% alpha and beta re-estimation on all but last iteration
% (only update the posterior statistics the last time around)
%
logAlpha = log(alpha(useful));
%
% Alpha re-estimation
%
% This will be much improved in the subsequent SB2 library
%
% MacKay-style update for alpha given in original NIPS paper
%
alpha(useful) = gamma ./ w(useful).^2;
%
% Terminate if the largest alpha change is smaller than threshold
%
au = alpha(useful);
maxDAlpha = max(abs(logAlpha(au~=0)-log(au(au~=0))));
if maxDAlpha<MIN_DELTA_LOGALPHA
LAST_IT = 1;
SB1_Diagnostic(1,...
'Terminating: max log(alpha) change is %g (<%g).\n', ...
maxDAlpha, MIN_DELTA_LOGALPHA);
end
%
% Beta re-estimate in regression (unless fixed)
%
if REGRESSION && ~FIXED_BETA
beta = (N - sum(gamma))/ED;
end
else
% Its the last iteration due to termination, leave outer loop
break; % that's all folks!
end
end
%
% Tidy up return values
%
weights = w(useful);
used = find(useful);
%
if ~LAST_IT
SB1_Diagnostic(1,'Terminating due to max iterations (did not converge)\n');
end
SB1_Diagnostic(1,'Hyperparameter estimation complete\n');
SB1_Diagnostic(2,'non-zero parameters:\t%d\n', length(weights));
SB1_Diagnostic(2,'log10-alpha min/max:\t%.2f/%.2f\n', ...
log10([min(alpha_used) max(alpha_used)]));
没有合适的资源?快使用搜索试试~ 我知道了~
【RVM预测】基于matlab相关向量机RVM数据多输入单输出回归预测【含Matlab源码 期】.zip
共13个文件
m:8个
png:4个
mat:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 51 浏览量
2024-10-10
21:46:13
上传
评论
收藏 100KB ZIP 举报
温馨提示
CSDN海神之光上传的全部代码均可运行,亲测可用,直接替换数据即可,适合小白; 1、代码压缩包内容 主函数:Main .m; 调用函数:其他m文件;无需运行 运行结果效果图; 2、代码运行版本 Matlab 2019b;若运行有误,根据提示修改;若不会,可私信博主; 3、运行操作步骤 步骤一:将所有文件放到Matlab的当前文件夹中; 步骤二:双击打开除Main.m的其他m文件; 步骤三:点击运行,等程序运行完得到结果; 4、仿真咨询 如需其他服务,可私信博主或扫描博主博客文章底部QQ名片; 4.1 CSDN博客或资源的完整代码提供 4.2 期刊或参考文献复现 4.3 Matlab程序定制 4.4 科研合作
资源推荐
资源详情
资源评论
收起资源包目录
【RVM预测】基于matlab相关向量机RVM数据多输入单输出回归预测【含Matlab源码 期】.zip (13个子文件)
【RVM预测】基于matlab相关向量机RVM数据多输入单输出回归预测【含Matlab源码 期】
3.png 11KB
main.m 2KB
SB1_KernelFunction.m 3KB
SB1_Estimate.m 6KB
1.png 10KB
SB1_Diagnostic.m 535B
SB1_RVM.m 3KB
SB1_PosteriorMode.m 4KB
getEnvironment.m 390B
setEnvironment.m 895B
4.png 8KB
data.mat 45KB
2.png 13KB
共 13 条
- 1
资源评论
海神之光
- 粉丝: 5w+
- 资源: 6086
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- stable diffusion InstantID的antelopev2模型
- 四叶草全球服直装.apk
- java毕业设计-基于SSM的私人牙科诊所管理系统【代码+部署教程】
- 哈夫曼树,共20页,内容简洁有效,干货满满,一份材料搞定哈夫曼树
- 《TCPIP协议》PPT课件,共71页,内容丰富,适合自学或教学使用
- 基于Java语言的Spring4.x中文Spring框架设计源码参考文档
- C/C++编程技巧之前后置递增运算符解析与应用
- 计算机科学:C++中链表数据结构详解及其基本操作实现
- 基于PyTorch的Alpha Sigma围棋游戏模型:基于Alpha Zero算法的强化学习与蒙特卡洛树搜索设计源码
- IPv4子网划分详解与实践
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功