Skip to content

Commit

Permalink
update 3
Browse files Browse the repository at this point in the history
  • Loading branch information
noblec04 committed Jun 24, 2024
1 parent cdcc423 commit 2fb3a4d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 24 deletions.
2 changes: 1 addition & 1 deletion MatlabGP/+BO/opt.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

a = means.linear(ones(1,length(lb)))*means.linear(ones(1,length(lb))) + means.linear(ones(1,length(lb))) + means.const(1);

b = kernels.RQ(1,0.2*ones(1,length(lb)));
b = kernels.RQ(1,1,0.2*ones(1,length(lb)));
b.signn = 0.0001;

Z = GP(a,b);
Expand Down
2 changes: 1 addition & 1 deletion MatlabGP/+means/const.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

function [y,dy] = forward(~,x,theta)
y = theta + 0*x(:,1);
dy = 0*x;
dy = 0*x(:,1);
end

end
Expand Down
19 changes: 17 additions & 2 deletions MatlabGP/+means/means.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

end

function [y,dy] = eval(obj,x)
function [y,dY] = eval(obj,x)

nb = numel(obj.meanz);

Expand Down Expand Up @@ -65,7 +65,13 @@
if nargout>1
[y1,dy1] = obj.meanz{i}.forward(x,obj.coeffs{i});

dy = -1*y.*(dy1)./y1.^2;
dy{i} = -1*y.*(dy1)./y1.^2;

if i>1
for jj = 1:i-1
dy{jj} = y1.*dy{jj};
end
end

y = y./y1;
else
Expand All @@ -75,6 +81,15 @@
end
end

if nargout>1
jj = 1;
for i = 1:numel(dy)
nn = size(dy{i},2);
dY(:,jj:jj+nn-1) = cell2mat(dy(i));
jj=jj+nn;
end
end

end

function V = getHPs(obj)
Expand Down
40 changes: 20 additions & 20 deletions MatlabGP/GP.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
dksf = obj.kernel.grad(xs,xx);
dm = obj.mean.grad(xs);

dy = dm + (dksf*obj.alpha)';
dy = dm + (dksf'*obj.alpha)';
end

end
Expand All @@ -88,7 +88,7 @@

if nargout>1
dksf = obj.kernel.grad(xs,xx);
dsig = -1*(-2*(ksf*obj.Kinv*dksf'));
dsig = -1*(-2*(ksf*obj.Kinv*dksf));
end

end
Expand Down Expand Up @@ -195,7 +195,7 @@
dnLL = zeros(1,length(theta));

for i = 1:ntm
dnLL(i) = -2*obj.alpha'*dm{i};
dnLL(i) = -2*obj.alpha'*dm(:,i);
end
n=0;
for i = ntm+1:length(theta)
Expand Down Expand Up @@ -258,27 +258,27 @@

func = @(x) obj.LL(x,regress,ntm);

% xxt = tlb + (tub - tlb).*lhsdesign(500*length(tlb),length(tlb));
%
% for ii = 1:size(xxt,1)
% LL(ii) = -1*func(xxt(ii,:));
% end
%
% LL = exp(1 + LL - max(LL));
%
% theta = sum(xxt.*LL')/sum(LL);

for i = 1:5
tx0 = tlb + (tub - tlb).*rand(1,length(tlb));

%[theta{i},val(i)] = bads(func,tx0,tlb,tub);
[theta{i},val(i)] = VSGD(func,tx0,'lr',0.02,'lb',tlb,'ub',tub,'gamma',0.0001,'iters',400,'tol',1*10^(-4));
xxt = tlb + (tub - tlb).*lhsdesign(500*length(tlb),length(tlb));

for ii = 1:size(xxt,1)
LL(ii) = func(xxt(ii,:));
end

[mval,i] = min(val);
LL = exp(1 + LL - max(LL));

theta = theta{i};
theta = sum(xxt.*LL')/sum(LL);

% for i = 1:5
% tx0 = tlb + (tub - tlb).*rand(1,length(tlb));
%
% %[theta{i},val(i)] = bads(func,tx0,tlb,tub);
% [theta{i},val(i)] = VSGD(func,tx0,'lr',0.02,'lb',tlb,'ub',tub,'gamma',0.0001,'iters',400,'tol',1*10^(-4));
%
% end
%
% [mval,i] = min(val);
%
% theta = theta{i};

if regress
obj.kernel.signn = theta(end);
Expand Down

0 comments on commit 2fb3a4d

Please sign in to comment.