-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extended Autodiff mldivide function to loop over gradient components to allow gradient propagation of batch likelihood objective function in VGP implementation.
- Loading branch information
Showing
12 changed files
with
200 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,37 @@ | ||
function [alpha, dalpha] = FUNBOmax(Z,x) | ||
|
||
if nargout>1 | ||
x=AutoDiff(x); | ||
end | ||
|
||
ys = max(Z.Y); | ||
|
||
gamma = 1; | ||
|
||
%Calculate std at x | ||
[varf,dvarf] = Z.eval_var(x); | ||
[muf] = Z.eval_mu(x); | ||
[varf] = Z.eval_var(x); | ||
|
||
if nargout>1 | ||
dmuf = getderivs(muf); | ||
muf = full(getvalue(muf)); | ||
|
||
[muf,dmuf] = Z.eval_mu(x); | ||
dvarf = getderivs(varf); | ||
varf = full(getvalue(varf)); | ||
end | ||
|
||
sigf = sqrt(abs(varf)); | ||
dsigf = dvarf./(2*sigf+eps); | ||
|
||
%Calculate beta value at x | ||
beta = (ys - muf + gamma*sigf)/sigf; | ||
dbeta = -dmuf./sigf + (gamma - beta)*dsigf/sigf; | ||
|
||
%Calculate expected improvement over current best measurement | ||
alpha = -sigf*(beta*normcdf(beta)+normpdf(beta)); | ||
dalpha = -dsigf*alpha/sigf - sigf*dbeta*normcdf(beta); | ||
|
||
if nargout>1 | ||
dbeta = (-dmuf./sigf + (gamma - beta)*dsigf/sigf); | ||
dalpha = -1*(-dsigf*alpha/sigf - sigf*dbeta*normcdf(beta)); | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
function contourf(kr,X0,dim1,dim2,varargin) | ||
|
||
% dim1 - Vary this dimension | ||
% dim2 - plot along this dimension | ||
% f - plot this fidelity | ||
|
||
input=inputParser; | ||
input.KeepUnmatched=true; | ||
input.addOptional('new_fig',false,@islogical); % Create a new figure | ||
input.addOptional('lb',kr.lb_x,@isnumeric); % Lower bound of plot | ||
input.addOptional('ub',kr.ub_x,@isnumeric); % Upper bound of plot | ||
input.addOptional('cmap','thermal'); | ||
input.addOptional('LS','-'); | ||
input.addOptional('nL',50); | ||
input.parse(varargin{:}) | ||
in=input.Results; | ||
|
||
if in.new_fig | ||
figure | ||
end | ||
|
||
a1=in.lb(dim1); | ||
b1=in.ub(dim1); | ||
|
||
|
||
a2=in.lb(dim2); | ||
b2=in.ub(dim2); | ||
|
||
n = in.nL; | ||
|
||
xx1 = linspace(a1,b1,n); | ||
xx2 = linspace(a2,b2,n); | ||
|
||
mb = X0; | ||
|
||
for i = 1:n | ||
for j = 1:n | ||
|
||
XX = mb; | ||
XX(dim1) = xx1(i); | ||
XX(dim2) = xx2(j); | ||
|
||
Yj = kr.eval(XX); | ||
YY(i,j) = Yj(1); | ||
|
||
end | ||
end | ||
|
||
contourf(xx2,xx1,YY); | ||
hold on | ||
shading interp | ||
utils.cmocean(in.cmap); | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
clear | ||
clc | ||
|
||
xmesh = lhsdesign(10,2); | ||
|
||
xs = lhsdesign(1000,2); | ||
|
||
b = kernels.EQ(1,[1 1]); | ||
|
||
tt = 0.001:0.01:2; | ||
|
||
for i = 1:200 | ||
|
||
theta = AutoDiff([tt(i) 1]); | ||
|
||
b = b.setHPs(theta); | ||
|
||
KXX = b.build(xmesh,xmesh); | ||
|
||
KXs = b.build(xmesh,xs); | ||
|
||
v = KXX\KXs; | ||
|
||
LL = sum(sum(v*v',1)); | ||
|
||
lv(i) = LL.values; | ||
ld(:,i) = LL.derivatives; | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.