% 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 下载量 57 浏览量
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+
- 资源: 6476
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 企业文化的三层结构.docx
- 企业文化概念的探讨.docx
- 企业文化就是一言一行.docx
- 企业文化与东西方文化传统.docx
- 基于java的网上教学辅助系统的设计与实现论文.doc
- Be Like a Goldfish, Don't Memorize! Mitigating Memorization in Generative LLMs
- 从《士兵突击》学管理之企业文化.doc
- 论企业文化和企业制度.doc
- 浅论人力资源管理与企业文化的关系.doc
- 王伟论企业文化.doc
- 传统文化与企业家精神.docx
- 陈亮:企业文化建设的核心是认同.docx
- 传承与发展——企业家与企业文化之辩证关系.docx
- 董明珠:用企业文化留住人.docx
- 李东生首谈企业文化 TCL管理方式正在变革.docx
- 蒋锡培:社会公益需要构建慈善的企业文化.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功