From ae5bda0459a87069aab6b8c45a6085a868392bb0 Mon Sep 17 00:00:00 2001 From: Lazloo Date: Tue, 20 Sep 2016 16:18:27 +0200 Subject: [PATCH] 20160920 - Improve in code documentation - small bug fixing - Enable optimality trsting for screening Signed-off-by: Lazloo --- dependencies/@AnalyzeKriging/AnalyzeKriging.m | 4 +- .../calcExpectedImprovementFromPredictions.m | 5 +- .../@AnalyzeKriging/calcInterpolation_2D.m | 2 +- .../@AnalyzeKriging/checkInputInterpolation.m | 13 ++- .../@AnalyzeKriging/doTestForOptimality.m | 5 + .../@AnalyzeKriging/plotInterpolation_nD.m | 102 +++++++++++++++--- dependencies/@AnalyzeKriging/plotOptimum23D.m | 8 +- .../@AnalyzeKriging/plotScreeningAnalysis.m | 11 +- .../@AnalyzeMixture/calcInterpolation.m | 2 +- .../MarginalLikelihoodCovarPara.m | 2 +- .../@KrigingSuperClass/calcCrossOverQuality.m | 3 + .../MatrixInversion/invupdatered.m | 2 +- 12 files changed, 128 insertions(+), 31 deletions(-) diff --git a/dependencies/@AnalyzeKriging/AnalyzeKriging.m b/dependencies/@AnalyzeKriging/AnalyzeKriging.m index 483b5ce..d234974 100644 --- a/dependencies/@AnalyzeKriging/AnalyzeKriging.m +++ b/dependencies/@AnalyzeKriging/AnalyzeKriging.m @@ -583,7 +583,7 @@ end % ---------------------------------------------------------------- function [nKrigingObjects]=getnKrigingObjects(obj) - nKrigingObjects = length(obj.getKrigingObjectNames); + nKrigingObjects = length(obj.KrigingObjects); end %------------------------------------------------------------------ function []=checknKrigingObjects(obj) @@ -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 diff --git a/dependencies/@AnalyzeKriging/calcExpectedImprovementFromPredictions.m b/dependencies/@AnalyzeKriging/calcExpectedImprovementFromPredictions.m index 5cc16f6..bd89bac 100644 --- a/dependencies/@AnalyzeKriging/calcExpectedImprovementFromPredictions.m +++ b/dependencies/@AnalyzeKriging/calcExpectedImprovementFromPredictions.m @@ -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 diff --git a/dependencies/@AnalyzeKriging/calcInterpolation_2D.m b/dependencies/@AnalyzeKriging/calcInterpolation_2D.m index 01da09f..6d4df38 100644 --- a/dependencies/@AnalyzeKriging/calcInterpolation_2D.m +++ b/dependencies/@AnalyzeKriging/calcInterpolation_2D.m @@ -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: - diff --git a/dependencies/@AnalyzeKriging/checkInputInterpolation.m b/dependencies/@AnalyzeKriging/checkInputInterpolation.m index d01d80b..3ce4ab1 100644 --- a/dependencies/@AnalyzeKriging/checkInputInterpolation.m +++ b/dependencies/@AnalyzeKriging/checkInputInterpolation.m @@ -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 @@ -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 diff --git a/dependencies/@AnalyzeKriging/doTestForOptimality.m b/dependencies/@AnalyzeKriging/doTestForOptimality.m index 40d0b73..a0e08cb 100644 --- a/dependencies/@AnalyzeKriging/doTestForOptimality.m +++ b/dependencies/@AnalyzeKriging/doTestForOptimality.m @@ -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 diff --git a/dependencies/@AnalyzeKriging/plotInterpolation_nD.m b/dependencies/@AnalyzeKriging/plotInterpolation_nD.m index b1ef6a9..45d9340 100644 --- a/dependencies/@AnalyzeKriging/plotInterpolation_nD.m +++ b/dependencies/@AnalyzeKriging/plotInterpolation_nD.m @@ -1,5 +1,5 @@ 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 @@ -7,6 +7,10 @@ % 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: - % @@ -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 @@ -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 @@ -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)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 @@ -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)); diff --git a/dependencies/@AnalyzeKriging/plotScreeningAnalysis.m b/dependencies/@AnalyzeKriging/plotScreeningAnalysis.m index bed8e9b..7745e6a 100644 --- a/dependencies/@AnalyzeKriging/plotScreeningAnalysis.m +++ b/dependencies/@AnalyzeKriging/plotScreeningAnalysis.m @@ -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 @@ -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() @@ -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; @@ -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' diff --git a/dependencies/@AnalyzeMixture/calcInterpolation.m b/dependencies/@AnalyzeMixture/calcInterpolation.m index f98b67b..54e3c13 100644 --- a/dependencies/@AnalyzeMixture/calcInterpolation.m +++ b/dependencies/@AnalyzeMixture/calcInterpolation.m @@ -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 diff --git a/dependencies/@KrigingSuperClass/MarginalLikelihoodCovarPara.m b/dependencies/@KrigingSuperClass/MarginalLikelihoodCovarPara.m index 9451bf3..f9938b3 100644 --- a/dependencies/@KrigingSuperClass/MarginalLikelihoodCovarPara.m +++ b/dependencies/@KrigingSuperClass/MarginalLikelihoodCovarPara.m @@ -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 diff --git a/dependencies/@KrigingSuperClass/calcCrossOverQuality.m b/dependencies/@KrigingSuperClass/calcCrossOverQuality.m index 159548f..2f0e2a9 100644 --- a/dependencies/@KrigingSuperClass/calcCrossOverQuality.m +++ b/dependencies/@KrigingSuperClass/calcCrossOverQuality.m @@ -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 @@ -170,6 +172,7 @@ obj.nExperiments = nExpBackup; obj.UseInverse = UseInverseBackUP; obj.setCovariogramModelParameters(covParaBackup); + obj.setUseMatlabRegressionGP(UseGPRMatlabBackup) %% Set Functions % --------------------------------------------------------------------- diff --git a/dependencies/auxiliaryFunctions/MatrixInversion/invupdatered.m b/dependencies/auxiliaryFunctions/MatrixInversion/invupdatered.m index d47dd85..726350a 100644 --- a/dependencies/auxiliaryFunctions/MatrixInversion/invupdatered.m +++ b/dependencies/auxiliaryFunctions/MatrixInversion/invupdatered.m @@ -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.');