


objective function for optimal approximation THIS IS NO USER FUNCTION


0001 function objectiveValue = genericObjectiveFunction(x, heMatrix, dec, ... 0002 par, grassStruct, sampleProjectionData) 0003 % objective function for optimal approximation 0004 % 0005 % THIS IS NO USER FUNCTION 0006 0007 % The elk-library: convex geometry applied to crystallization modeling. 0008 % Copyright (C) 2013 Alexander Reinhold 0009 % 0010 % This program is free software: you can redistribute it and/or modify it 0011 % under the terms of the GNU General Public License as published by the 0012 % Free Software Foundation, either version 3 of the License, or (at your 0013 % option) any later version. 0014 % 0015 % This program is distributed in the hope that it will be useful, but 0016 % WITHOUT ANY WARRANTY; without even the implied warranty of 0017 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0018 % General Public License for more details. 0019 % 0020 % You should have received a copy of the GNU General Public License along 0021 % with this program. If not, see <http://www.gnu.org/licenses/>. 0022 0023 % projection matrix 0024 projectionMatrix = computeProjectionFromGrass(x, grassStruct); 0025 % define penalty function 0026 % penaltyValue = @(validRatio)((validRatio < par.penaltyRatioLimit)*... 0027 % (par.penaltyRatioLimit - validRatio)*par.penaltySlope); 0028 0029 %% projection 0030 if strcmpi(par.projectionType, 'true') 0031 heMatrixProjected = projectionMatrix * heMatrix; 0032 else 0033 %! DEV: this is temporarily not supported: 0034 error('elk:approximation:internalError', 'DEV: not supported'); 0035 heMatrixProjected = estimateHeMatrix(heMatrix, projectionMatrix, ... 0036 sampleProjectionData); 0037 %/ 0038 end 0039 0040 %% evaluate error 0041 if strcmpi(par.errorType, 'PCA') 0042 % objective 0043 objectiveValue = sum((heMatrix(:) - heMatrixProjected(:)).^2); 0044 else 0045 % measure matrix (enforce validity) 0046 measureMatrix = computeMeasureDec(dec, 'hC', ... 0047 heMatrixProjected, par.measureList, [], [], 1); 0048 0049 % get ratio of columns that contribute to errors 0050 % ratio = sum(fadeOutScaling) / length(fadeOutScaling); 0051 0052 % error vector 0053 errorVector = computeMatrixError(par.measureValueMatrix, ... 0054 measureMatrix, par.errorType, par.errorGroupVector); 0055 0056 % apply weights and penalty 0057 % objectiveValue = par.measureWeightVector(:)'*errorVector + penaltyValue(ratio); 0058 objectiveValue = par.measureWeightVector(:)'*errorVector; 0059 0060 end