• 大小: 833KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-10
  • 语言: Matlab
  • 标签: matlab  

资源简介

高斯过程回归及分类的代码,内容全,有实例,注释清晰。包括分类系列和预测回归系列,值得感兴趣的同学学习借鉴。里面有对应的数据和demo程序,程序可运行,MATLAB2014a下测试通过,其他版本没有测试。(网页版的0

资源截图

代码片段和文件信息

% Calculates for xstar x-coordinates the bestEstimate and the 95%
% confidence interval (bounds) for a Gaussian process regression.
% Mark Ebden July 2008
%
% Inputs:
%  k - a handle to the covariance function
%  Xy - the training data x- and y-coordinates
%  theta - the GP parameters to be passed to the covariance function
%          (e.g. length scale periodicity etc.
%  sigma_n - the noise (optional -- default 0)
%    NOTE: sigma_n should be left as zero if k *already* includes the noise term as I usually do.
%  xstar - specify the x-coordinates to solve for (optional -- default is
%          to let the algorithm choose them)
%  graphing - produce a plot of results (optional)
%             Default is to plot the results unless the function outputs were asked for
%
% Outputs:
%  xstar - x-coordinates (default 100 are chosen)
%  K - covariance matrix among training data
%  V - variance at each xstar

function [xstar bestEstimate bounds K V] = calcGP (k X y theta sigma_n xstar graphing)

if nargin < 7
    if nargout == 0
        graphing = 1; 
    else
        graphing = 0;
    end
end
if nargin < 6 || ~any(xstar)
    r2 =(max(X)-min(X));
    N = 1e3; % How many points to use
    z = .5; % How much to extend the time series on either side (e.g. .5 is 50% extension on left and on right)
    xstar = (0:N)/N * (z*2+1)*r2 + min(X)-r2*z;
end
if nargin < 5
    sigma_n = 0;
end
if nargin < 4
    theta = [1 0 1 0];
end

% a) Initializations
meany = mean(y); y = y - meany;
n = size(X1); lx = length(xstar);
K = zeros(n); kstar = zeros(n1);
for i = 1:n
    for j = 1:n
        K(ij) = k (X(i)X(j)theta);
    end
end
fstarbar = zeros(lx1); V = zeros(lx1);

% b) One-off calculations
diags = max(1e3*eps sigma_n^2); % beef up the diagonal if sigma_n = 0
L = chol (K + diags*eye(n)‘lower‘); 
alpha = L‘\(L\y);
logpyX = -y‘*alpha/2 - sum(log(diag(L))) - n*log(2*pi)/2; % Log marginal likelihood

% c) xstar loop
for q = 1:lx
    for i = 1:n
        kstar(i) = k (X(i)xstar(q)theta);
    end
    kstar
    % Mean of prediction
    fstarbar(q) = kstar‘ * alpha;
    % Variance of prediction
    v = L\kstar;
    ystar_noise = sigma_n^2; % recall f* has no noise itself (Algorithm 2.1 on p 19 of H152)
    V(q) = k (xstar(q)xstar(q)theta) - v‘*v + ystar_noise;
end
bounds = [fstarbar+1.96*sqrt(V) fstarbar-1.96*sqrt(V)]+meany;
bestEstimate = fstarbar+meany;

% d) Output
if graphing == 1
    figure hold on
    stdRegion (xstarbounds)
    plot (xstarbestEstimate‘k‘)
    plot (Xy+meany‘b+‘)
end

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      31996  2006-03-07 20:29  gpml\doc\alg21.gif

     文件      43172  2006-03-07 20:08  gpml\doc\alg31.gif

     文件      34064  2006-03-07 20:08  gpml\doc\alg32.gif

     文件      66673  2006-03-07 20:08  gpml\doc\alg35.gif

     文件      32226  2006-03-07 20:08  gpml\doc\alg36.gif

     文件      60084  2006-03-07 20:08  gpml\doc\alg51.gif

     文件      41085  2006-03-07 20:08  gpml\doc\alg52.gif

     文件      34439  2006-03-26 03:00  gpml\doc\classification.html

     文件      36772  2006-03-15 00:12  gpml\doc\fig2d.gif

     文件      35364  2006-03-15 00:12  gpml\doc\fig2de1.gif

     文件      42683  2006-03-15 00:12  gpml\doc\fig2de2.gif

     文件      38483  2006-03-15 00:12  gpml\doc\fig2de3.gif

     文件      34059  2006-03-15 00:12  gpml\doc\fig2dl1.gif

     文件      40431  2006-03-15 00:12  gpml\doc\fig2dl2.gif

     文件      38375  2006-03-15 00:12  gpml\doc\fig2dl3.gif

     文件      17875  2006-03-10 22:56  gpml\doc\figepp.gif

     文件      23299  2006-03-10 22:56  gpml\doc\figepp2.gif

     文件       6109  2006-03-27 15:58  gpml\doc\figl.gif

     文件      21386  2006-03-07 20:29  gpml\doc\figl1.gif

     文件      17854  2006-03-09 23:57  gpml\doc\figlapp.gif

     文件      25557  2006-03-09 23:57  gpml\doc\figlapp2.gif

     文件      16078  2006-03-27 16:35  gpml\doc\figlf.gif

     文件      16712  2006-03-27 22:10  gpml\doc\figlm.gif

     文件       3461  2007-06-26 18:30  gpml\doc\index.html

     文件      16598  2006-03-29 01:45  gpml\doc\regression.html

     文件       7738  2006-03-29 18:39  gpml\doc\sparse-approx.html

     文件         77  2006-03-07 20:08  gpml\doc\style.css

     文件       5097  2007-07-24 23:34  gpml\gpml\approxEP.m

     文件       1936  2007-06-27 19:45  gpml\gpml\approximations.m

     文件       3094  2007-06-26 18:12  gpml\gpml\approxLA.m

............此处省略60个文件信息

评论

共有 条评论