Skip to content
This repository has been archived by the owner on Jan 12, 2025. It is now read-only.

Commit

Permalink
20160920
Browse files Browse the repository at this point in the history
- Improve in code documentation
- small bug fixing
- Enable optimality trsting for screening

Signed-off-by: Lazloo <freier@ibt-w2k.kfa-juelich.de>
  • Loading branch information
Lazloo committed Sep 20, 2016
1 parent c55044f commit ae5bda0
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 31 deletions.
4 changes: 2 additions & 2 deletions dependencies/@AnalyzeKriging/AnalyzeKriging.m
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@
end
% ----------------------------------------------------------------
function [nKrigingObjects]=getnKrigingObjects(obj)
nKrigingObjects = length(obj.getKrigingObjectNames);
nKrigingObjects = length(obj.KrigingObjects);
end
%------------------------------------------------------------------
function []=checknKrigingObjects(obj)
Expand Down Expand Up @@ -788,7 +788,7 @@

%------------------------------------------------------------------
function []=setMaxSizeOfPredictions(obj,MaxSizeOfPredictions)
obj.MaxSizeOfPredictions = MaxSizeOfPredictions;
% obj.MaxSizeOfPredictions = MaxSizeOfPredictions;
for iKrigingObject = 1 : length(obj.KrigingObjectTypes)
obj.KrigingObjects{iKrigingObject}.setMaxSizeOfPredictions(MaxSizeOfPredictions);
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
function [ExpectedImprovement]=calcExpectedImprovementFromPredictions(obj,varargin)
% Copyright 2014-2016: Lars Freier, Eric von Lieres
% See the license note at the end of the file.
% [ExpectedImprovement]=calcExpectedImprovement(obj,KrigingObjectIndex,predictions)
% KrigingObjectIndex ... indicates the which Kriging Objective
% is considered
% prediction ... nPoints X 1 matrix containing Kriging predictions
%
% Copyright 2014-2016: Lars Freier, Eric von Lieres
% See the license note at the end of the file.

KrigingObjectIndex = varargin{1};
if length(KrigingObjectIndex)~=1
Expand Down
2 changes: 1 addition & 1 deletion dependencies/@AnalyzeKriging/calcInterpolation_2D.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function []=calcInterpolation_2D(obj,varargin)
% [] = calcInterpolation_3D(KrigingObjectIndex,[InputVar1,InputVar2],RemainingIndices,RemainingValues)
% [] = calcInterpolation_2D(KrigingObjectIndex,[InputVar1,InputVar2],RemainingIndices,RemainingValues)
%
% For Further Detail see documentation of "calcMutualInterpolation_23D()"
% You can set: -
Expand Down
13 changes: 9 additions & 4 deletions dependencies/@AnalyzeKriging/checkInputInterpolation.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@
end
InputVar1 = 1;
case 2
InputVar1 = 1;
InputVar2 = 2;
if length(varargin)>2
InputVar1 = varargin{2}(1);
InputVar2 = setdiff(1:2,InputVar1);
else
InputVar1 = 1;
InputVar2 = 2;
end
otherwise
switch dimensionInterpolation
case 2
Expand Down Expand Up @@ -55,8 +60,8 @@
if length(unique([varargin{2},RemainingIndices]))~=obj.KrigingObjects{KrigingObjectIndex(1)}.getnInputVar
error('Entries in "[InputVar1,InputVar2]" and "RemainingIndices" must be unique')
end
if dimensionInterpolation>2&&(size(RemainingValues,1)*size(RemainingValues,2))~=obj.KrigingObjects{KrigingObjectIndex}.getnInputVar-2
error('RemainingValues must be a vector with length %i',obj.KrigingObjects{KrigingObjectIndex}.getnInputVar-2)
if dimensionInterpolation>2&&(size(RemainingValues,1)*size(RemainingValues,2))~=obj.KrigingObjects{KrigingObjectIndex(1)}.getnInputVar-2
error('RemainingValues must be a vector with length %i',obj.KrigingObjects{KrigingObjectIndex(1)}.getnInputVar-2)
end

% Transpose if neccesary
Expand Down
5 changes: 5 additions & 0 deletions dependencies/@AnalyzeKriging/doTestForOptimality.m
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
inputVar1=(obj.KrigingPrediction_Screening{KrigingObjectIndex,2}{iCombination}(:,inputVarIndices(1)));
inputVar2=(obj.KrigingPrediction_Screening{KrigingObjectIndex,2}{iCombination}(:,inputVarIndices(2)));
inputData = [inputVar1,inputVar2];
case 5
% Case Screening
prediction = obj.KrigingPrediction_InterpolationnD{KrigingObjectIndex,1}(:,1);
sd = obj.KrigingPrediction_InterpolationnD{KrigingObjectIndex,1}(:,2);
inputData = obj.KrigingPrediction_InterpolationnD{KrigingObjectIndex,4};
otherwise
error('Diminsion is unusual')
end
Expand Down
102 changes: 89 additions & 13 deletions dependencies/@AnalyzeKriging/plotInterpolation_nD.m
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
function [] = plotInterpolation_nD(obj,varargin)
% plotInterpolation_nD(KrigingObjectIndex)
% plotInterpolation_nD(KrigingObjectIndex,Objective,testValue)
%
% Uses the data which are calculated by calcInterpolation_nD and
% create a nD-Plot out of them
%
% Input: -
% - KrigingObjectIndex ... index of the kriging object which should
% be used in this function.
% - Objective ... decide if the Kriging estimation ('KrigingInterpolation'), the expected
% improvement ('ExpectedImprovement') or optimal regions
% ('Optimum') shall be plotted
% - testValue ... if Objective = 'Optimum', testValue can be used as
%
% Output: -
%
Expand All @@ -22,14 +26,26 @@

%% Initialization
KrigingObjectIndex = varargin{1};
if length(varargin)>1
Objective = varargin{2};
else
Objective = 'KrigingInterpolation';
end
if length(varargin)>2
testValue = varargin{3};
else
testValue = [];
end
[minEstimation,maxEstimation,Estimation] = doInitialization(KrigingObjectIndex,Objective);

KrigingObjectIndex = obj.checkKrigingIndizes(KrigingObjectIndex);
KrigingObjectIndexArray = KrigingObjectIndex;
KrigingObjectIndex = KrigingObjectIndexArray(1);

% Collecting Kriging predicion
Estimation = obj.KrigingPrediction_InterpolationnD{KrigingObjectIndex,1}(:,1);
minEstimation = min(Estimation);
maxEstimation = max(Estimation);
% Estimation = obj.KrigingPrediction_InterpolationnD{KrigingObjectIndex,1}(:,1);
% minEstimation = min(Estimation);
% maxEstimation = max(Estimation);

% Matrix containing all combination of input variables calues
% which were used for prediciton
Expand Down Expand Up @@ -74,23 +90,63 @@
if obj.getShowColorBar||obj.getnPlots>1
subplot(nRows,obj.getnPlots+offsetIndices,ceil(obj.getnPlots/2))
end
title(obj.getKrigingObjectNames{KrigingObjectIndex},'FontSize',20)
switch Objective
case 'KrigingInterpolation'
title(obj.getKrigingObjectNames{KrigingObjectIndex},'FontSize',20)
case 'ExpectedImprovement'
title(sprintf('Exp. Improvement: %s',obj.getKrigingObjectNames{KrigingObjectIndex}),'FontSize',20)
case 'Optimum'
title(sprintf('Plateau Plot: %s',obj.getKrigingObjectNames{KrigingObjectIndex}),'FontSize',20)
otherwise
error('Unknown plotting objective')
end

% Colorbar
if obj.getNormColors==1
caxis([minEstimation,maxEstimation])
end

if obj.getShowColorBar==1&&obj.getNormColors==1
subplot(obj.getnPlots,obj.getnPlots+offsetIndices,obj.getnPlots+offsetIndices:obj.getnPlots+offsetIndices:obj.getnPlots*(obj.getnPlots+offsetIndices))
colorbar
axis off
end
if obj.getNormColors==1
caxis([minEstimation,maxEstimation])
end

% Adjust Color map
colormap(gcf,obj.ColormapToolbox);

%% ----------------------Nested Function -----------------------
% labelPlotxAxis
function [minEstimation,maxEstimation,plottingObjective] = doInitialization(KrigingObjectIndex,Objective)
minEstimation = inf;
maxEstimation = -inf;

switch Objective
case 'KrigingInterpolation'
% In case of mutual kriging, the entries in
% KrigingPrediction_InterpolationnD for all kriging objects
% used are the same -> redunant information saving
plottingObjective = obj.KrigingPrediction_InterpolationnD{KrigingObjectIndex(1),1};
plottingObjective = plottingObjective(:,1);
minEstimation = min(minEstimation,min(plottingObjective));
maxEstimation = max(maxEstimation,max(plottingObjective));
case 'ExpectedImprovement'
% plottingObjective = obj.calcExpectedImprovementFromPredictions(KrigingObjectIndex,obj.KrigingPrediction_InterpolationnD{KrigingObjectIndex,1});
prediction = obj.KrigingPrediction_InterpolationnD{KrigingObjectIndex,1};
prediction(:,1) = -obj.MinMax(KrigingObjectIndex)*prediction(:,1);
plottingObjective = obj.calcExpectedImprovementMainPart(KrigingObjectIndex,prediction);
minEstimation = min(minEstimation,min(plottingObjective));
maxEstimation = max(maxEstimation,max(plottingObjective));
case 'Optimum'
minEstimation = 0;
maxEstimation = 1;
% plottingObjective = [];

[~,plottingObjective] = doTestForOptimality(obj,KrigingObjectIndex,5,testValue);
otherwise
error('Unknown plotting objective')
end
end
% -------------------------------------------------------------
function [] = createContourPlot(iRow,iPlots2)

% Indices where the input values equal to the expected ones
Expand All @@ -110,10 +166,30 @@
% Actual Plotting
OutputPart = Estimation(obj.Accuracy^2*obj.nPlots*(iRow-1)+1:obj.Accuracy^2*obj.nPlots*(iRow));
OutputPart = OutputPart(logical(indexEstimation));
if inputVarIndices(1)<inputVarIndices(2)
contourf(InputMatrixProto{inputVarIndices(iRow,1),iRow}',InputMatrixProto{inputVarIndices(iRow,2),iRow}',reshape(OutputPart,obj.Accuracy,obj.Accuracy)',obj.nContourLevels)
else
contourf(InputMatrixProto{inputVarIndices(iRow,1),iRow}',InputMatrixProto{inputVarIndices(iRow,2),iRow}',reshape(OutputPart,obj.Accuracy,obj.Accuracy)',obj.nContourLevels)

switch Objective
case {'KrigingInterpolation','ExpectedImprovement'}

contourf(InputMatrixProto{inputVarIndices(iRow,1),iRow}',...
InputMatrixProto{inputVarIndices(iRow,2),iRow}',...
reshape(OutputPart,obj.Accuracy,obj.Accuracy)',obj.nContourLevels)

% Set Colormap
colormap(gcf,obj.ColormapToolbox);
case 'Optimum'
indexValid = OutputPart;
inputMatrixFull = obj.KrigingPrediction_InterpolationnD{KrigingObjectIndex,2};
inputMatrixPart = inputMatrixFull(obj.Accuracy^2*obj.nPlots*(iRow-1)+1:obj.Accuracy^2*obj.nPlots*(iRow),:);
inputMatrixPart = inputMatrixPart(logical(indexEstimation),:);
inputDataOpt = [inputMatrixPart(:,inputVarIndices(iRow,1)),inputMatrixPart(:,inputVarIndices(iRow,2))];

% Fill in the t-test results
hold on
plot(inputDataOpt(indexValid,1),inputDataOpt(indexValid,2),'r*');
plot(inputDataOpt(~indexValid,1),inputDataOpt(~indexValid,2),'b*');
axis tight
otherwise
error('Unknown plotting objective')
end

% Adjusting color range
Expand Down
8 changes: 6 additions & 2 deletions dependencies/@AnalyzeKriging/plotOptimum23D.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@

KrigingObjectIndex = varargin{1};
dimensionInterpolation = varargin{2};
% testValue = varargin{3};
if length(varargin)>2
testValue = varargin{3};
else
testValue = [];
end

% In case of mutual Kriging interpolation, the prediction of all
% objects is saved redundant, such that only the first index should
Expand All @@ -53,7 +57,7 @@
KrigingObjectIndex = KrigingObjectIndexArray(1);


[inputData,indexValid]=doTestForOptimality(obj,varargin{:});
[inputData,indexValid]=doTestForOptimality(obj,varargin{:},testValue);
indexInvalid = ~indexValid;

names = obj.getInputVarNames(KrigingObjectIndex(1));
Expand Down
11 changes: 7 additions & 4 deletions dependencies/@AnalyzeKriging/plotScreeningAnalysis.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function [] = plotScreeningAnalysis(obj,varargin)
% [] = plotScreeningAnalysis(obj,KrigingObjectIndex,Objective)
% [] = plotScreeningAnalysis(KrigingObjectIndex,Objective,testValue)
% KrigingObjectIndex ... index of the Kriging object which should
% be used here
% This function uses the data generated using "calcScreeningAnalysis" and
Expand Down Expand Up @@ -45,7 +45,7 @@
error('KrigingObjectIndex must be a scalar')
end
Objective = varargin{2};
[nCombinations,nPossibleCombi,minEstimation,maxEstimation,plottingObjective] = doInitialiaztion(KrigingObjectIndex,Objective);
[nCombinations,nPossibleCombi,minEstimation,maxEstimation,plottingObjective] = doInitialization(KrigingObjectIndex,Objective);

%% Actual Plotting
figure()
Expand Down Expand Up @@ -82,7 +82,7 @@
colorbar('off')
end
%% Nested Functions
function [nCombinations,nPossibleCombi,minEstimation,maxEstimation,plottingObjective] = doInitialiaztion(KrigingObjectIndex,Objective)
function [nCombinations,nPossibleCombi,minEstimation,maxEstimation,plottingObjective] = doInitialization(KrigingObjectIndex,Objective)
nCombinations = length(obj.KrigingPrediction_Screening{KrigingObjectIndex,1});
nPossibleCombi = (obj.KrigingObjects{KrigingObjectIndex}.getnInputVar-1);
minEstimation = inf;
Expand All @@ -94,7 +94,10 @@
maxEstimation = max(maxEstimation,max(obj.KrigingPrediction_Screening{KrigingObjectIndex,1}{iCombinationNested}(:,1)));
plottingObjective = [];
case 'ExpectedImprovement'
plottingObjective = obj.calcExpectedImprovementFromPredictions(KrigingObjectIndex,obj.KrigingPrediction_Screening{KrigingObjectIndex,1}{iCombinationNested});
% plottingObjective = obj.calcExpectedImprovementFromPredictions(KrigingObjectIndex,obj.KrigingPrediction_Screening{KrigingObjectIndex,1}{iCombinationNested});
prediction = obj.KrigingPrediction_Screening{KrigingObjectIndex,1}{iCombinationNested};
prediction(:,1) = -obj.MinMax(KrigingObjectIndex)*prediction(:,1);
plottingObjective = obj.calcExpectedImprovementMainPart(KrigingObjectIndex,prediction);
minEstimation = min(minEstimation,min(plottingObjective));
maxEstimation = max(maxEstimation,max(plottingObjective));
case 'Optimum'
Expand Down
2 changes: 1 addition & 1 deletion dependencies/@AnalyzeMixture/calcInterpolation.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
% [BasisFct{1}(obj.KrigingObjects{KrigingObjectIndex}.getBasisFctParameters,Input),...
% zeros(size(Input,1),1)];

evaluateBasisFunction(obj,KrigingObjectIndex,Input);
evaluateBasisFunction(obj,KrigingObjectIndex,Input,size(Input,2));

else

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
estimateBasisFctCoefficients(obj)
C = obj.CovariogramMatrix(1:obj.nExperiments,1:obj.nExperiments);
detC = det(C);
numericalLimit = 1e-16;
numericalLimit = realmin;
if detC<=numericalLimit
detC = numericalLimit;
end
Expand Down
3 changes: 3 additions & 0 deletions dependencies/@KrigingSuperClass/calcCrossOverQuality.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
% Set the defined model parameters
obj.setCovariogramModelParameters(varargin{1});
covariogramBackupMatrix = obj.getCovariogramMatrix;
UseGPRMatlabBackup = obj.getUseMatlabRegressionGP;
obj.setUseMatlabRegressionGP(false)

% Calculated initial inverse of the covariogramgram matrix. Later this
% inverse is only updated
Expand Down Expand Up @@ -170,6 +172,7 @@
obj.nExperiments = nExpBackup;
obj.UseInverse = UseInverseBackUP;
obj.setCovariogramModelParameters(covParaBackup);
obj.setUseMatlabRegressionGP(UseGPRMatlabBackup)

%% Set Functions
% ---------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
%

% Input checks.
error(nargchk(1,3,nargin))
% error(nargchk(1,3,nargin))
[n,m] = size(A);
if n~=m
error('A should be square.');
Expand Down

0 comments on commit ae5bda0

Please sign in to comment.