From 68c4a2eeae4fe09d3f5e1d61628d6949834c7aac Mon Sep 17 00:00:00 2001 From: noblec04 Date: Wed, 1 Jan 2025 22:12:01 -0700 Subject: [PATCH] cleanup --- MatlabGP/+BO/HVUCB.asv | 27 ---- MatlabGP/MOGP.asv | 237 --------------------------------- MatlabGP/examples/testMOGP.asv | 48 ------- 3 files changed, 312 deletions(-) delete mode 100644 MatlabGP/+BO/HVUCB.asv delete mode 100644 MatlabGP/MOGP.asv delete mode 100644 MatlabGP/examples/testMOGP.asv diff --git a/MatlabGP/+BO/HVUCB.asv b/MatlabGP/+BO/HVUCB.asv deleted file mode 100644 index 6e987ab..0000000 --- a/MatlabGP/+BO/HVUCB.asv +++ /dev/null @@ -1,27 +0,0 @@ -function [alpha] = HVUCB(Z,x) - -lb_y = min(Z.Y); -ub_y = max(Z.Y); - -Y = (Z.Y - lb_y)./(ub_y - lb_y); - -A = utils.ParetoFront(Y); -%HV = utils.hypervolume(Y(A==1,:),max(Y)); - -%HV = sum(Y(A==1,:),'all'); - -yn = Z.UCB(x); - -Yn = [Z.Y;yn]; - -Yn = (Yn - lb_y)./(ub_y - lb_y); - -An = utils.ParetoFront(Yn); -%HVn = utils.hypervolume(Yn(An==1,:),max(Y)); -HVn = sum(Yn(An==1,:),'all'); - -alpha = HVn - HV; - -alpha = -1*alpha; - -end \ No newline at end of file diff --git a/MatlabGP/MOGP.asv b/MatlabGP/MOGP.asv deleted file mode 100644 index 3f7d630..0000000 --- a/MatlabGP/MOGP.asv +++ /dev/null @@ -1,237 +0,0 @@ -%{ - Multi-output Gaussian Process - - A set of single-task exact Gaussian Process with Gaussian Likelihood. - - A mean and kernel function can be created from which the GP can be - generated. - - The GP can then be conditioned on training data. - - The GP can then be trained to optimize the HPs of the mean and kernel - by finding the mean of the posterior distribution over parameters, or - by finding the MAP estimate if the number of HPs is large. - -%} - -classdef MOGP - - properties - GPs - - mean - kernel - - X - Y - - lb_x=0; - ub_x=1; - end - - methods - - function obj = MOGP(mean,kernel,N) - if isempty(mean) - mean = means.zero; - end - obj.mean = mean; - obj.kernel = kernel; - - for i = 1:N - obj.GPs{i} = GP(mean,kernel); - end - end - - function [y,sig] = eval(obj,x) - - nY = numel(obj.GPs); - for i = 1:nY - - if nargout==2 - [y(:,i),sig(:,i)] = obj.GPs{i}.eval(obj,x); - else - [y(:,i)] = obj.GPs{i}.eval(obj,x); - end - - end - end - - function [y] = eval_mu(obj,x) - - nY = numel(obj.GPs); - for i = 1:nY - - y(:,i) = obj.GPs{i}.eval_mu(obj,x); - - end - - end - - function [sig] = eval_var(obj,x) - - nY = numel(obj.GPs); - for i = 1:nY - - sig(:,i) = obj.GPs{i}.eval_var(obj,x); - - end - - end - - function y = sample(obj,x) - - nY = numel(obj.GPs); - for i = 1:nY - - y(:,i) = obj.GPs{i}.sample(obj,x); - - end - - end - - function [dy,dsig] = eval_grad(obj,x) - - nY = numel(obj.GPs); - for i = 1:nY - - [dy(:,i,:),dsig(:,i,:)] = obj.GPs{i}.eval_grad(obj,x); - - end - - - end - - function [obj] = condition(obj,X,Y,lb,ub) - - obj.X = X; - obj.Y = Y; - - if nargin<4 - obj.lb_x = min(X); - obj.ub_x = max(X); - else - obj.lb_x = lb; - obj.ub_x = ub; - end - - nY = numel(obj.GPs); - for i = 1:nY - - obj.GPs{i} = obj.GPs{i}.condition(obj,X,Y(:,i),obj.lb_x,obj.ub_x); - - end - - end - - function L = LOO(obj) - - if isempty(obj.Kinv) - obj.Kinv = obj.K\eye(size(obj.K,1)); - end - L = 0.5*(obj.alpha.^2)./diag(obj.Kinv);% - 0.5*log(diag(obj.Kinv)); - end - - function [thetas,ntm,ntk,tm0,tk0] = getHPs(obj) - - tm0 = obj.mean.getHPs(); - tk0 = obj.kernel.getHPs(); - - ntm = numel(tm0); - ntk = numel(tk0); - - thetas = [tm0 tk0]; - - end - - function obj = setHPs(obj,theta) - - [~,ntm,~] = obj.getHPs(); - - obj.mean = obj.mean.setHPs(theta(1:ntm)); - obj.kernel = obj.kernel.setHPs(theta(ntm+1:end)); - - end - - function [obj,LL] = train(obj,regress) - - if nargin<2 - regress=0; - end - - nY = numel(obj.GPs); - for i = 1:nY - - [obj.GPs{i},LL(i)] = obj.GPs{i}.train(regress); - - end - end - - function [obj, LL] = train2(obj) - - nY = numel(obj.GPs); - for i = 1:nY - - [obj.GPs{i},LL(i)] = obj.GPs{i}.train2(regress); - - end - - end - - function obj = resolve(obj,x,y) - - replicates = ismembertol(x,obj.X,1e-4,'ByRows',true); - - x(replicates,:) = []; - y(replicates,:) = []; - - if size(x,1)>0 - - obj.X = [obj.X; x]; - obj.Y = [obj.Y; y]; - - for i = 1:nY - - obj.GPs{i} = obj.GPs{i}.resolve(obj,regress); - - end - end - - end - - %Operator Overloading - - - function obj = or(obj,A) - x = A(:,1:end-1); - y = A(:,end); - - obj = obj.condition(x,y); - end - - function warpedobj = exp(obj) - - warpedobj = warpGP(obj,'exp'); - - end - - function warpedobj = cos(obj) - - warpedobj = warpGP(obj,'cos'); - - end - - function warpedobj = sin(obj) - - warpedobj = warpGP(obj,'sin'); - - end - - function warpedobj = mpower(obj,~) - - warpedobj = warpGP(obj,'square'); - - end - - end -end \ No newline at end of file diff --git a/MatlabGP/examples/testMOGP.asv b/MatlabGP/examples/testMOGP.asv deleted file mode 100644 index 8a91e52..0000000 --- a/MatlabGP/examples/testMOGP.asv +++ /dev/null @@ -1,48 +0,0 @@ - -clear -close all -clc - -xx = [lhsdesign(15,1)]; -yy = normrnd(forr(xx,0),0*forr(xx,0)+0); - -xmesh = linspace(0,1,100)'; -ymesh = forr(xmesh,0); - -ma = means.const(1); -ka = kernels.Matern52(1,1); - -Z = MOGP(ma,ka,3); -Z = Z.condition(xx,yy,0,1); -Z = Z.train(); - -utils.plotLineOut(Z,0,1) -hold on -plot(xx,yy,'x') -plot(xmesh,ymesh,'.') - -%% - -[xn,Rn] = BO.argmax(@BO.HVUCB,Z) - -%% - -function y = forr(x,dx) - -nx = length(x); - -A = 0.5; B = 10; C = -5; - -for i = 1:nx - if x(i)<0.45 - y(i,1) = (6*x(i)-2).^2.*sin(12*x(i)-4); - else - y(i,1) = (6*x(i)-2).^2.*sin(12*x(i)-4)+dx; - end - - y(i,2) = 0.4*(6*x(i)-2).^2.*sin(12*x(i)-4)-cos(x(i).^2-1; - y(i,3) = A*(6*x(i)-2).^2.*sin(12*x(i)-4)+B*(x(i)-0.5)-C; -end - -end -