-
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.
- Loading branch information
Showing
7 changed files
with
292 additions
and
4 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
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,27 @@ | ||
classdef Matern12<kernels.Kernel | ||
|
||
properties | ||
theta | ||
end | ||
|
||
methods | ||
|
||
function obj = Matern12(scale,theta) | ||
obj.scale = scale; | ||
obj.scales{1} = scale; | ||
obj.theta = theta; | ||
obj.thetas{1} = theta; | ||
obj.kernels{1} = obj; | ||
obj.w.map = 'none'; | ||
obj.warping{1} = obj.w; | ||
end | ||
|
||
function [K] = forward_(obj,x1,x2,theta) | ||
|
||
d = obj.dist(x1./theta,x2./theta); | ||
|
||
K = exp(-d); | ||
end | ||
|
||
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,29 @@ | ||
classdef Matern32<kernels.Kernel | ||
|
||
properties | ||
theta | ||
end | ||
|
||
methods | ||
|
||
function obj = Matern32(scale,theta) | ||
obj.scale = scale; | ||
obj.scales{1} = scale; | ||
obj.theta = theta; | ||
obj.thetas{1} = theta; | ||
obj.kernels{1} = obj; | ||
obj.w.map = 'none'; | ||
obj.warping{1} = obj.w; | ||
end | ||
|
||
function [K] = forward_(obj,x1,x2,theta) | ||
|
||
d = obj.dist(x1./theta,x2./theta); | ||
|
||
K = (1 + sqrt(3)*d); | ||
|
||
K = K.*exp(-sqrt(3)*d); | ||
end | ||
|
||
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
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,16 @@ | ||
function [y] = StressedPlate(x,i) | ||
|
||
T = 25000; | ||
E = 210*10^9; | ||
nu = 0.3; | ||
rho = 7800; | ||
|
||
switch i | ||
case 1 | ||
y = sqrt(1./(rho*x(:,3))).*sqrt(((E*x(:,3).^3)./(12*(1-nu))).*((pi^2)./x(:,1).^2 + (pi^2)./x(:,2).^2).^2 + T*((pi^2)./x(:,1).^2 + (pi^2)./x(:,2).^2)) - 120; | ||
case 2 | ||
y = sqrt(1./(rho*x(:,3))).*sqrt(((E*x(:,3).^3)./(12*(1-nu))).*((pi^2)./x(:,1).^2 + (pi^2)./x(:,2).^2).^2) - 120; | ||
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,110 @@ | ||
|
||
clear all | ||
clc | ||
|
||
lb = [0.5 0.5 2.5*10^(-3)]; | ||
ub = [1.5 1.5 7.5*10^(-3)]; | ||
|
||
xx = lb + (ub - lb).*lhsdesign(50000,3); | ||
yy = StressedPlate(xx,1); | ||
|
||
x1 = lb + (ub - lb).*lhsdesign(5,3); | ||
y1 = StressedPlate(x1,1); | ||
|
||
x2 = [lb + (ub - lb).*lhsdesign(100,3)]; | ||
y2 = StressedPlate(x2,2); | ||
|
||
x{1} = x1; | ||
x{2} = x2; | ||
|
||
y{1} = y1; | ||
y{2} = y2; | ||
|
||
%% | ||
ma = means.linear([1 1 1 1]); | ||
mb = means.linear([1 1 1]); | ||
|
||
a = kernels.Matern52(1,[0.1 0.2 0.1 0.3]);%.periodic(1,10); | ||
b = kernels.EQ(1,[0.2 0.2 0.2]); | ||
a.signn = 0; | ||
b.signn = 0; | ||
|
||
%% | ||
tic | ||
for i = 1:2 | ||
Z{i} = GP(mb,b); | ||
Z{i} = Z{i}.condition(x{i},y{i},lb,ub); | ||
Z{i} = Z{i}.train(); | ||
end | ||
toc | ||
|
||
%% | ||
tic | ||
MF = NLMFGP(Z,ma,a); | ||
MF = MF.condition(); | ||
MF = MF.train(); | ||
toc | ||
|
||
|
||
%% | ||
figure | ||
hold on | ||
utils.plotLineOut(Z{1},(lb+ub)/2,1,'color','r') | ||
utils.plotLineOut(Z{2},(lb+ub)/2,1,'color','b') | ||
|
||
%% | ||
|
||
figure | ||
hold on | ||
utils.plotLineOut(MF,(lb+ub)/2,1) | ||
|
||
%% | ||
|
||
1 - mean((yy - Z{1}.eval_mu(xx)).^2)./var(yy) | ||
max(abs(yy - Z{1}.eval_mu(xx)))./std(yy) | ||
|
||
1 - mean((yy - MF.eval_mu(xx)).^2)./var(yy) | ||
max(abs(yy - MF.eval_mu(xx)))./std(yy) | ||
|
||
%% | ||
for jj = 1:40 | ||
|
||
[xn,Rn] = BO.argmax(@BO.maxVAR,MF); | ||
|
||
x{1} = [x{1}; xn]; | ||
x{2} = [x{2}; xn]; | ||
|
||
y{1} = [y{1}; StressedPlate(xn,1)]; | ||
y{2} = [y{2}; StressedPlate(xn,2)]; | ||
|
||
for ii = 1:2 | ||
%Z{ii} = GP(mb,b); | ||
Z{i} = Z{i}.condition(x{i},y{i},lb,ub); | ||
%Z{ii} = Z{ii}.train(); | ||
end | ||
|
||
MF.GPs = Z; | ||
MF = MF.condition(); | ||
MF = MF.train(); | ||
|
||
R2z(jj) = 1 - mean((yy - Z{1}.eval_mu(xx)).^2)./var(yy); | ||
RMAEz(jj) = max(abs(yy - Z{1}.eval_mu(xx)))./std(yy); | ||
|
||
R2MF(jj) = 1 - mean((yy - MF.eval_mu(xx)).^2)./var(yy); | ||
RMAEMF(jj) = max(abs(yy - MF.eval_mu(xx)))./std(yy); | ||
|
||
figure(1) | ||
clf(1) | ||
hold on | ||
plot(1:jj,R2z) | ||
plot(1:jj,R2MF) | ||
|
||
figure(2) | ||
clf(2) | ||
hold on | ||
plot(1:jj,RMAEz) | ||
plot(1:jj,RMAEMF) | ||
|
||
drawnow | ||
|
||
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,107 @@ | ||
|
||
clear all | ||
clc | ||
|
||
lb = [0.5 0.5 2.5*10^(-3)]; | ||
ub = [1.5 1.5 7.5*10^(-3)]; | ||
|
||
xx = lb + (ub - lb).*lhsdesign(50000,3); | ||
yy = StressedPlate(xx,1); | ||
|
||
x1 = lb + (ub - lb).*lhsdesign(5,3); | ||
y1 = StressedPlate(x1,1); | ||
|
||
x2 = [lb + (ub - lb).*lhsdesign(20,3)]; | ||
y2 = StressedPlate(x2,2); | ||
|
||
x{1} = x1; | ||
x{2} = x2; | ||
|
||
y{1} = y1; | ||
y{2} = y2; | ||
|
||
%% | ||
ma = means.linear([1 1 1 1]); | ||
mb = means.linear([1 1 1]); | ||
|
||
a = kernels.EQ(1,[0.1 0.2 0.1 0.3]);%.periodic(1,10); | ||
b = kernels.EQ(1,[0.2 0.2 0.2]); | ||
a.signn = 0; | ||
b.signn = 0; | ||
|
||
%% | ||
tic | ||
for i = 1:2 | ||
Z{i} = GP(mb,b); | ||
Z{i} = Z{i}.condition(x{i},y{i},lb,ub); | ||
Z{i} = Z{i}.train(); | ||
end | ||
toc | ||
|
||
%% | ||
tic | ||
MF = NLMFGP(Z,ma,a); | ||
MF = MF.condition(); | ||
MF = MF.train(); | ||
toc | ||
|
||
|
||
%% | ||
figure | ||
hold on | ||
utils.plotLineOut(Z{1},(lb+ub)/2,1,'color','r') | ||
utils.plotLineOut(Z{2},(lb+ub)/2,1,'color','b') | ||
|
||
%% | ||
|
||
figure | ||
hold on | ||
utils.plotLineOut(MF,(lb+ub)/2,1) | ||
|
||
%% | ||
|
||
1 - mean((yy - Z{1}.eval_mu(xx)).^2)./var(yy) | ||
max(abs(yy - Z{1}.eval_mu(xx)))./std(yy) | ||
|
||
1 - mean((yy - MF.eval_mu(xx)).^2)./var(yy) | ||
max(abs(yy - MF.eval_mu(xx)))./std(yy) | ||
|
||
%% | ||
for jj = 1:50 | ||
|
||
[xn,Rn] = BO.argmax(@BO.maxVAR,MF); | ||
|
||
x{1} = [x{1}; xn]; | ||
x{2} = [x{2}; xn]; | ||
|
||
y{1} = [y{1}; StressedPlate(xn,1)]; | ||
y{2} = [y{2}; StressedPlate(xn,2)]; | ||
|
||
for ii = 1:2 | ||
Z{ii} = Z{ii}.condition(x{ii},y{ii},lb,ub); | ||
end | ||
|
||
MF.GPs = Z; | ||
MF = MF.condition(); | ||
|
||
R2z(jj) = 1 - mean((yy - Z{1}.eval_mu(xx)).^2)./var(yy); | ||
RMAEz(jj) = max(abs(yy - Z{1}.eval_mu(xx)))./std(yy); | ||
|
||
R2MF(jj) = 1 - mean((yy - MF.eval_mu(xx)).^2)./var(yy); | ||
RMAEMF(jj) = max(abs(yy - MF.eval_mu(xx)))./std(yy); | ||
|
||
figure(1) | ||
clf(1) | ||
hold on | ||
plot(1:jj,R2z) | ||
plot(1:jj,R2MF) | ||
|
||
figure(2) | ||
clf(2) | ||
hold on | ||
plot(1:jj,RMAEz) | ||
plot(1:jj,RMAEMF) | ||
|
||
drawnow | ||
|
||
end |