This repository has been archived by the owner on Jan 12, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
20170224 Add Multi-Objective Global Optimization (MOGO) as new class
- Loading branch information
Lazloo
committed
Feb 24, 2017
1 parent
1c3fa6b
commit 84cb779
Showing
15 changed files
with
289 additions
and
28 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
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
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,115 @@ | ||
classdef MOGO<handle | ||
|
||
%% Public Members | ||
properties(GetAccess='public',SetAccess='public') | ||
KrigingAnalyzeObj = []; | ||
CovModelChoice = 6; | ||
SaveInputDataOverIterations = cell(0); | ||
SaveOutputDataOverIterations = cell(0); | ||
SaveCovarParametersOverIterations = cell(0); | ||
InputDataRange = []; | ||
nInputVar = 0; | ||
% Number of realizations drawn during conditional simulation | ||
nRealizations = 5e2; | ||
|
||
InputData = []; | ||
OutputData = []; | ||
end | ||
properties(GetAccess='public',SetAccess='protected') | ||
|
||
% Saving optimization results in each iteration | ||
GlobalUncertainity = []; | ||
GlobalUncertainityNorm = []; | ||
HVVec = []; | ||
end | ||
%% Private Members | ||
properties(GetAccess='private',SetAccess='private') | ||
|
||
end | ||
|
||
%% Protected Members | ||
properties(GetAccess='protected',SetAccess='protected') | ||
|
||
end | ||
|
||
methods(Abstract) | ||
% These function have to be user defined in each inherinted class | ||
|
||
% ---------------------------------------------------------------- | ||
% Used in "generateData" | ||
[output] = objFct(obj,varargin) | ||
end | ||
|
||
methods | ||
%% Constructor | ||
function obj = MOGO() | ||
obj.KrigingAnalyzeObj = BayesianOptimizationClass(); | ||
obj.KrigingAnalyzeObj.addKrigingObject(1,'Test Name') | ||
obj.KrigingAnalyzeObj.KrigingObjects{1}.setNormInput(true) | ||
obj.KrigingAnalyzeObj.KrigingObjects{1}.setNormOutput(true) | ||
obj.KrigingAnalyzeObj.KrigingObjects{1}.setShowDetails(true) | ||
end | ||
%% Copy Operator for a shallow copy | ||
% ---------------------------------------------------------------- | ||
function copy = copyObj(obj) | ||
% Create a shallow copy of the calling object. | ||
copy = eval(class(obj)); | ||
meta = eval(['?',class(obj)]); | ||
for p = 1: size(meta.Properties,1) | ||
pname = meta.Properties{p}.Name; | ||
try | ||
eval(['copy.',pname,' = obj.',pname,';']); | ||
catch | ||
error(['\nCould not copy ',pname,'.\n']); | ||
% fprintf(['\nCould not copy ',pname,'.\n']); | ||
end | ||
end | ||
end | ||
%% General Methods | ||
[] = calcKriging(obj,varargin) | ||
% ---------------------------------------------------------------- | ||
function []=saveObject(obj,varargin) | ||
index = varargin{1}; | ||
save(strcat('tmpSave_',num2str(index)),'obj') | ||
end | ||
% ---------------------------------------------------------------- | ||
[] = saveTmpResults(obj,iIter) | ||
% ---------------------------------------------------------------- | ||
[] = estimateParetoCurve(obj,iKrigingEstimation) | ||
% ---------------------------------------------------------------- | ||
[] = setVariableNames(obj,inputNames,OutputNames) | ||
% ---------------------------------------------------------------- | ||
[] = calcAndSaveNewSamples(obj,iterationNumber) | ||
% ---------------------------------------------------------------- | ||
[inputData,outputData]=collectAllDataUntilGivenIteration(obj,finalIteration) | ||
% ---------------------------------------------------------------- | ||
function []=SaveCurrentCovarParameter(obj,iterationNumber) | ||
obj.SaveCovarParametersOverIterations{iterationNumber} = obj.KrigingAnalyzeObj.KrigingObjects{1}.getCovariogramModelParameters; | ||
end | ||
% ---------------------------------------------------------------- | ||
[]=generateNewData(obj,varargin); | ||
%% Set function | ||
function []=setInputDataRange(obj,InputDataRange) | ||
% Check | ||
if size(InputDataRange,1)== 2 && size(InputDataRange,2)== obj.nInputVar && obj.nInputVar~=2 | ||
InputDataRange = InputDataRange'; | ||
end | ||
obj.InputDataRange = InputDataRange; | ||
end | ||
|
||
function []=setInputData(obj,InputData) | ||
obj.resetData | ||
obj.InputData = InputData; | ||
obj.KrigingAnalyzeObj.KrigingObjects{1}.setInputData(obj.InputData) | ||
obj.SaveInputDataOverIterations{1} = obj.InputData; | ||
obj.nInputVar = size(InputData,2); | ||
end | ||
% ---------------------------------------------------------------- | ||
function []=setOutputData(obj,OutputData) | ||
obj.OutputData = OutputData; | ||
obj.KrigingAnalyzeObj.KrigingObjects{1}.setOutputData(obj.OutputData) | ||
obj.SaveOutputDataOverIterations{1} = obj.OutputData; | ||
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,23 @@ | ||
function [newSamplePoint] = calcAndSaveNewSamples(obj,varargin) | ||
% [] = calcAndSaveNewSamplesMultiObj(obj,iterationNumber,OptimizationAlgorithm,UseOnlyMaximumValue) | ||
iterationNumber = varargin{1}; | ||
|
||
if obj.KrigingAnalyzeObj.getnKrigingObjects>1 | ||
obj.KrigingAnalyzeObj.determineParetoSet(1:obj.KrigingAnalyzeObj.getnKrigingObjects) | ||
end | ||
% obj.nParetoSamples = obj.KrigingAnalyzeObj.getnParetoSetExperiments; | ||
|
||
% Save the covariogram parameters | ||
obj.SaveCovarParametersOverIterations{iterationNumber-1} = obj.KrigingAnalyzeObj.KrigingObjects{1}.getCovariogramModelParameters; | ||
newSamplePoint = obj.KrigingAnalyzeObj.calcNewSamplesViaMCMC(1:obj.KrigingAnalyzeObj.getnKrigingObjects,'DRAM'); | ||
|
||
|
||
% Generate New data points (For ome cases input variables are aslo part of the ouput of the obj function) | ||
obj.SaveInputDataOverIterations{iterationNumber} = newSamplePoint; | ||
obj.generateNewData(iterationNumber); | ||
|
||
% Save data points | ||
obj.InputData = [obj.InputData;obj.SaveInputDataOverIterations{iterationNumber}]; | ||
obj.OutputData = [obj.OutputData;obj.SaveOutputDataOverIterations{iterationNumber}]; | ||
% obj.KrigingAnalyzeObj.getNewSamples | ||
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,28 @@ | ||
function [] = calcKriging(obj,varargin) | ||
|
||
% Create kriging model for each object | ||
for iKrigingObject = 1:obj.KrigingAnalyzeObj.getnKrigingObjects | ||
obj.KrigingAnalyzeObj.KrigingObjects{iKrigingObject}.setUseMatlabRegressionGP(false); | ||
|
||
obj.KrigingAnalyzeObj.KrigingObjects{iKrigingObject}.setInputData(obj.InputData); | ||
obj.KrigingAnalyzeObj.KrigingObjects{iKrigingObject}.setOutputData(obj.OutputData(:,iKrigingObject)); | ||
|
||
obj.KrigingAnalyzeObj.KrigingObjects{iKrigingObject}.setCovariogramModelChoice(obj.CovModelChoice) | ||
maxValue = 1e2; | ||
|
||
if obj.KrigingAnalyzeObj.KrigingObjects{iKrigingObject}.getCovariogramModelChoice==3 | ||
obj.KrigingAnalyzeObj.KrigingObjects{iKrigingObject}.setLBCovariogramModelParameters([ones(1,obj.KrigingAnalyzeObj.KrigingObjects{1}.getnCovariogramParameters)]*1e-10) | ||
obj.KrigingAnalyzeObj.KrigingObjects{iKrigingObject}.setUBCovariogramModelParameters([maxValue,maxValue,2,2,maxValue,maxValue]) | ||
else | ||
obj.KrigingAnalyzeObj.KrigingObjects{iKrigingObject}.setLBCovariogramModelParameters([ones(1,obj.KrigingAnalyzeObj.KrigingObjects{1}.getnCovariogramParameters)]*1e-10) | ||
obj.KrigingAnalyzeObj.KrigingObjects{iKrigingObject}.setUBCovariogramModelParameters([ones(1,obj.KrigingAnalyzeObj.KrigingObjects{1}.getnCovariogramParameters)]*maxValue) | ||
end | ||
|
||
|
||
obj.KrigingAnalyzeObj.KrigingObjects{iKrigingObject}.generateRegressionGPModel() | ||
% obj.KrigingAnalyzeObj.KrigingObjects{iKrigingObject}.calcCovariogramMatrix | ||
|
||
end | ||
|
||
obj.setInputDataRange(obj.InputDataRange(1:obj.nInputVar,:)); | ||
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,18 @@ | ||
function [inputData,outputData]=collectAllDataUntilGivenIteration(obj,finalIteration) | ||
% First allocation | ||
nData=0; | ||
for iIter=1:finalIteration | ||
nData = nData + size(obj.SaveInputDataOverIterations{iIter},1); | ||
end | ||
|
||
% Now collecting | ||
inputData = zeros(nData,obj.nInputVar); | ||
outputData = zeros(nData,1); | ||
iRow = 0; | ||
for iIter=1:finalIteration | ||
nDataIter = size(obj.SaveInputDataOverIterations{iIter},1); | ||
inputData(iRow+1:iRow+nDataIter,:) = obj.SaveInputDataOverIterations{iIter}; | ||
outputData(iRow+1:iRow+nDataIter,1) = obj.SaveOutputDataOverIterations{iIter}; | ||
iRow = iRow + nDataIter; | ||
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,18 @@ | ||
function [] = estimateParetoCurve(obj,iKrigingEstimation) | ||
nObj = obj.KrigingAnalyzeObj.getnKrigingObjects; | ||
|
||
obj.KrigingAnalyzeObj.predictParetoCurve(1:nObj,obj.nRealizations,(10^3),30); | ||
globalUncertainity=obj.KrigingAnalyzeObj.getGlobalParetoUncertainity; | ||
globalUncertainityNorm=obj.KrigingAnalyzeObj.getGlobalParetoUncertainityNorm; | ||
|
||
refPoint = (1-obj.KrigingAnalyzeObj.getMinMax(1:nObj))/2; | ||
transformedOutput = -bsxfun(@times,obj.KrigingAnalyzeObj.getMinMax(1:nObj),obj.OutputData); | ||
HV=Hypervolume_MEX(transformedOutput,refPoint); | ||
|
||
obj.GlobalUncertainity(iKrigingEstimation) = globalUncertainity; | ||
obj.GlobalUncertainityNorm(iKrigingEstimation) = globalUncertainityNorm; | ||
obj.HVVec(iKrigingEstimation) = HV; | ||
|
||
|
||
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,4 @@ | ||
function [obj2] = externalFunction(obj,varargin) | ||
obj2 = obj; | ||
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,11 @@ | ||
function [] = generateNewData(obj,varargin) | ||
iterationNumber = varargin{1}; | ||
|
||
outputProto = obj.objFct(obj.SaveInputDataOverIterations{iterationNumber}); | ||
obj.SaveOutputDataOverIterations{iterationNumber} = outputProto(:,1:end-obj.nInputVar); | ||
|
||
% Save Input Data | ||
obj.SaveInputDataOverIterations{iterationNumber} = outputProto(:,end-obj.nInputVar+1: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,14 @@ | ||
function [varargout] = sampleFromDistribution(obj,varargin) | ||
muVec = varargin{1}; | ||
stdVec = varargin{2}; | ||
|
||
distA = randn(1e5,1); | ||
distB = randn(1e5,1); | ||
|
||
distA = distA*stdVec(1) + muVec(1); | ||
distB = distB*stdVec(2) + muVec(2); | ||
|
||
varargout{1} = distA; | ||
varargout{2} = distB; | ||
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,22 @@ | ||
function [] = saveTmpResults(obj,iIter) | ||
%% Backup | ||
fileNameUnc = strcat('globalUncertainityVec_iIter',num2str(iIter)); | ||
fileNameIn = strcat('input_iIter',num2str(iIter)); | ||
fileNameOut = strcat('output_iIter',num2str(iIter)); | ||
fileNameNormUnc = strcat('globalUncertainityNormVec_iIter',num2str(iIter)); | ||
fileNameHV = strcat('HVMatrixVec_iIter',num2str(iIter)); | ||
|
||
% Save | ||
input = obj.InputData; | ||
output = obj.OutputData; | ||
GU = obj.GlobalUncertainity; | ||
GUN = obj.GlobalUncertainityNorm; | ||
HVVec = obj.HVVec; | ||
save(fileNameIn,'input') | ||
save(fileNameOut,'output') | ||
save(fileNameUnc,'GU') | ||
save(fileNameNormUnc,'GUN') | ||
save(fileNameHV,'HVVec') | ||
|
||
end | ||
|
Oops, something went wrong.