java版 高斯过程,高斯过程回归

我正在编写高斯过程回归算法 . 这是代码:

% Data generating function

fh = @(x)(2*cos(2*pi*x/10).*x);

% range

x = -5:0.01:5;

N = length(x);

% Sampled data points from the generating function

M = 50;

selection = boolean(zeros(N,1));

j = randsample(N, M);

% mark them

selection(j) = 1;

Xa = x(j);

% compute the function and extract mean

f = fh(Xa) - mean(fh(Xa));

sigma2 = 1;

% computing the interpolation using all x's

% It is expected that for points used to build the GP cov. matrix, the

% uncertainty is reduced...

K = squareform(pdist(x'));

K = exp(-(0.5*K.^2)/sigma2);

% upper left corner of K

Kaa = K(selection,selection);

% lower right corner of K

Kbb = K(~selection,~selection);

% upper right corner of K

Kab = K(selection,~selection);

% mean of posterior

m = Kab'*inv(Kaa+0.001*eye(M))*f';

% cov. matrix of posterior

D = Kbb - Kab'*inv(Kaa + 0.001*eye(M))*Kab;

% sampling M functions from from GP

[A,B,C] = svd(Kaa);

F0 = A*sqrt(B)*randn(M,M);

% mean from GP using sampled points

F0m = mean(F0,2);

F0d = std(F0,0,2);

%%

% put together data and estimation

F = zeros(N,1);

S = zeros(N,1);

F(selection) = f' + F0m;

S(selection) = F0d;

% sampling M function from posterior

[A,B,C] = svd(D);

a = A*sqrt(B)*randn(N-M,M);

% mean from posterior GPs

Fm = m + mean(a,2);

Fmd = std(a,0,2);

F(~selection) = Fm;

S(~selection) = Fmd;

%%

figure;

% show what we got...

plot(x, F, ':r', x, F-2*S, ':b', x, F+2*S, ':b'), grid on;

hold on;

% show points we got

plot(Xa, f, 'Ok');

% show the whole curve

plot(x, fh(x)-mean(fh(x)), 'k');

grid on;

我希望得到一些不错的数据,其中未知数据点的不确定性会很大,并且采样数据点周围很小 . 我得到了一个奇怪的数字甚至更奇怪的是,采样数据点周围的不确定性大于其余数据点 . 有人可以向我解释我做错了什么吗?谢谢!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值