Skip to content

Commit

Permalink
Change iter data
Browse files Browse the repository at this point in the history
  • Loading branch information
jhadida committed Mar 28, 2017
1 parent 611dcea commit d2f64a8
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 90 deletions.
18 changes: 11 additions & 7 deletions GPSO.m
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,12 @@
[i_max,k_max] = self.step_select(objfun);
upn = self.step_update(upc,upn);

Nselect = nnz(i_max);
if Nselect == 0
if nnz(i_max) == 0
warning( 'No leaf selected for iteration, aborting.' );
break;
end

self.progress(tstart,Nselect);
self.progress(tstart,i_max);
self.notify( 'PostIteration' );

end
Expand Down Expand Up @@ -375,14 +374,19 @@ function info(self,fmt,varargin)
end

% print progress
function data = progress(self,tstart,Nselect)
function data = progress(self,tstart,i_max)

data = [toc(tstart), self.tree.depth, Nselect, self.srgt.Ne, self.srgt.best_score];
%data = [toc(tstart), self.tree.depth, Nselect, self.srgt.Ne, self.srgt.best_score];

Ne = self.srgt.Ne;
time = toc(tstart);
best = self.srgt.best_score;
data = struct( 'runtime', time, 'split', i_max, 'neval', Ne, 'score', best );

self.iter{end+1} = data;
self.info('\tEnd of iteration #%d (depth: %d, nselect: %d, neval: %d, score: %g)', ...
self.Niter, data(2), data(3), data(4), data(5) );
self.info('\t------------------------------ Elapsed time: %s\n', dk.time.sec2str(data(1)) );
self.Niter, numel(i_max), nnz(i_max), Ne, best );
self.info('\t------------------------------ Elapsed time: %s\n', dk.time.sec2str(time) );

end

Expand Down
44 changes: 22 additions & 22 deletions GPSO_Tree.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,28 @@
self.Ns = 0;
end

% serialise data to be saved
function D = serialise(self)
F = {'level','Nl','Ns'};
n = numel(F);
D = struct();

for i = 1:n
f = F{i};
D.(f) = self.(f);
end
D.version = '0.1';
end
function self=unserialise(self,D)
F = {'level','Nl','Ns'};
n = numel(F);

for i = 1:n
f = F{i};
self.(f) = D.(f);
end
end

function self=init(self,ndim,rid)
%
% ndim: dimensionality of search space
Expand Down Expand Up @@ -109,28 +131,6 @@

end

% serialise data to be saved
function D = serialise(self)
F = {'level','Nl','Ns'};
n = numel(F);
D = struct();

for i = 1:n
f = F{i};
D.(f) = self.(f);
end
D.version = '0.1';
end
function self=unserialise(self,D)
F = {'level','Nl','Ns'};
n = numel(F);

for i = 1:n
f = F{i};
self.(f) = D.(f);
end
end

end

end
121 changes: 60 additions & 61 deletions GP_Surrogate.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
properties (SetAccess = private)
x; % sample coordinates
y; % data array with columns [mu,sigma,ucb]
GP; % GP parameters

lower;
upper;

varsigma; % controls optimism in the face of uncertainty (not saved)
GP; % GP parameters
varsigma; % controls optimism in the face of uncertainty (NOT SAVED)
Ne, Ng; % number of evaluated/GP-based samples
end

Expand All @@ -18,7 +18,7 @@
delta; % dimensions of the box
end

properties
properties (Transient)
LIK_BND = [-9 -1]; % scale of value uncertainty
COV_BND = [-4 -1]; % scale of spatial variation
end
Expand All @@ -40,27 +40,26 @@
self.Ng = 0;
end

% setters
function self=set_gp(self, hyp, meanfunc, covfunc)

gp.hyp = hyp;
gp.likfunc = @likGauss; % Gaussian likelihood is assumed for analytics
gp.meanfunc = meanfunc;
gp.covfunc = covfunc;

self.GP = gp;
% serialise data to be saved
function D = serialise(self)
F = {'lower','upper','x','y','Ne','Ng','GP'};
n = numel(F);
D = struct();

for i = 1:n
f = F{i};
D.(f) = self.(f);
end
D.version = '0.1';
end

function v=get_varsigma(self)
v = self.varsigma(self.Ng);
end
function self=set_varsigma_paper(self,eta)
% JH: original varsigma can be complex for M=1 and eta=1
self.varsigma = @(M) sqrt(max( 0, 4*log(pi*M) - 2*log(12*eta) )); % cf Lemma 1
end
function self=set_varsigma_const(self,val)
self.varsigma = @(M) val;
function self=unserialise(self,D)
F = {'lower','upper','x','y','Ne','Ng','GP'};
n = numel(F);

for i = 1:n
f = F{i};
self.(f) = D.(f);
end
end

% dependent properties
Expand All @@ -84,7 +83,33 @@
self.Ng = 0;

end


% mutators/accessors
function self=set_gp(self, hyp, meanfunc, covfunc)

gp.hyp = hyp;
gp.likfunc = @likGauss; % Gaussian likelihood is assumed for analytics
gp.meanfunc = meanfunc;
gp.covfunc = covfunc;

self.GP = gp;

end

function v=get_varsigma(self)
v = self.varsigma(self.Ng);
end
function self=set_varsigma_paper(self,eta)
% JH: original varsigma can be complex for M=1 and eta=1
self.varsigma = @(M) sqrt(max( 0, 4*log(pi*M) - 2*log(12*eta) )); % cf Lemma 1
end
function self=set_varsigma_const(self,val)
self.varsigma = @(M) val;
end
end

methods

% normalise/denormalise coordinates
function y = normalise(self,x)
y = bsxfun( @minus, x, self.lower );
Expand Down Expand Up @@ -126,9 +151,9 @@

if ~isempty(e)
dk.assert( isscalar(e), '[bug] Duplicate points found at indices: %s', sprintf('%d ',e) );
self.y(e,3) = y(i,3);
self.y(e,3) = y(i,3); % just update UCB of the existing point
else
c = c+1;
c = c+1; % count new points
e = ns + c; % new index
g = g + (y(i,2) > 0); % is the new point GP-based?

Expand Down Expand Up @@ -163,41 +188,6 @@
[m,s] = self.gp_call(self.normalise(xq));
end

% serialise data to be saved
function D = serialise(self)
F = {'lower','upper','x','y','Ne','Ng','GP'};
n = numel(F);
D = struct();

for i = 1:n
f = F{i};
D.(f) = self.(f);
end
D.version = '0.1';
end
function self=unserialise(self,D)
F = {'lower','upper','x','y','Ne','Ng','GP'};
n = numel(F);

for i = 1:n
f = F{i};
self.(f) = D.(f);
end
end

end

methods

% access y's columns
function y = ycol(self,c,k)
if nargin > 2
y = self.y(k,c);
else
y = self.y(:,c);
end
end

% aliases to y's columns
% if called without index, returns the whole column
function m = mu(self,varargin), m = self.ycol(1,varargin{:}); end
Expand Down Expand Up @@ -251,7 +241,16 @@

end

methods
methods (Hidden)

% access y's columns
function y = ycol(self,c,k)
if nargin > 2
y = self.y(k,c);
else
y = self.y(:,c);
end
end

% UCB update
function self=ucb_update(self)
Expand Down

0 comments on commit d2f64a8

Please sign in to comment.