computeMatrixError

PURPOSE ^

compute error vector from matrices

SYNOPSIS ^

function errorVector = computeMatrixError(matrixOne, matrixTwo,errorType, groupVector)

DESCRIPTION ^

 compute error vector from matrices

 Syntax: errorVector = computeMatrixError(referenceMatrix, ...
                         sampleMatrix, errorType)

 The following error types are supported, while a detailed definition can
   be obtained <a href="matlab: help computeMatrixError>helpErrorDefinition">here</a>: relativeSquared, absoluteSquared, relativeMean, 
   absoluteMean, relativeTotal, absoluteTotal.

 With errorType='all', all error vectors are returned in a structure with
   fields according to the error types given above.

 See also: approximateDec

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function errorVector = computeMatrixError(matrixOne, matrixTwo, ...
0002     errorType, groupVector)
0003 % compute error vector from matrices
0004 %
0005 % Syntax: errorVector = computeMatrixError(referenceMatrix, ...
0006 %                         sampleMatrix, errorType)
0007 %
0008 % The following error types are supported, while a detailed definition can
0009 %   be obtained <a href="matlab: help computeMatrixError>helpErrorDefinition">here</a>: relativeSquared, absoluteSquared, relativeMean,
0010 %   absoluteMean, relativeTotal, absoluteTotal.
0011 %
0012 % With errorType='all', all error vectors are returned in a structure with
0013 %   fields according to the error types given above.
0014 %
0015 % See also: approximateDec
0016 
0017 % The elk-library: convex geometry applied to crystallization modeling.
0018 %   Copyright (C) 2013 Alexander Reinhold
0019 %
0020 % This program is free software: you can redistribute it and/or modify it
0021 %   under the terms of the GNU General Public License as published by the
0022 %   Free Software Foundation, either version 3 of the License, or (at your
0023 %   option) any later version.
0024 %
0025 % This program is distributed in the hope that it will be useful, but
0026 %   WITHOUT ANY WARRANTY; without even the implied warranty of
0027 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0028 %   General Public License for more details.
0029 %
0030 % You should have received a copy of the GNU General Public License along
0031 %   with this program.  If not, see <http://www.gnu.org/licenses/>.
0032 
0033 %% Info
0034 % Note that weights for the elements might be applied before calling this
0035 %   function. A weighted aggregation of all error components can be
0036 %   obtained by a subsequent scalar product between errorVectors and a
0037 %   weight vector.
0038 %/
0039 
0040 if ~exist('ratio', 'var') || isempty(ratio)
0041     ratio = 1;
0042 end
0043 
0044 n = size(matrixOne, 2);
0045 nReal = n*ratio;
0046 errorMatrix = matrixOne - matrixTwo;
0047 switch lower(errorType)
0048     case 'relativesquared'
0049     errorVector = 1/nReal * sqrt(...
0050         sum((errorMatrix ./ matrixOne).^2, 2) );
0051     
0052     case 'relativemean'
0053     errorVector = 1/nReal * sum(abs(errorMatrix ./ matrixOne), 2);
0054     
0055     case 'relativemax'
0056     errorVector = max(abs(errorMatrix ./ matrixOne), [], 2);
0057     
0058     case 'absolutesquared'
0059     errorVector = (1/ratio) * sum(errorMatrix.^2, 2);
0060 
0061     case 'absolute'
0062     errorVector = (1/ratio) * sum(abs(errorMatrix), 2);
0063     
0064     case 'absolutemax'
0065     errorVector = max(abs(errorMatrix), [], 2);
0066     
0067     case 'relativetotal'
0068     errorVector = (1/ratio) * (sum(matrixOne, 2) - sum(matrixTwo, 2)) ./ ...
0069         sum(matrixOne, 2);
0070     
0071     case 'absolutetotal'
0072     errorVector = (1/ratio) * (sum(matrixOne, 2) - sum(matrixTwo, 2));
0073     
0074     case 'relativemaxgroupedmean'
0075     errorVector = 0*errorMatrix(:,1);
0076     for iGroup = 1:max(groupVector)
0077         errorVector = max(errorVector, abs((...
0078             sum(matrixOne(:, groupVector==iGroup), 2) - ...
0079             sum(matrixTwo(:, groupVector==iGroup), 2)) ./ ...
0080             sum(matrixOne(:, groupVector==iGroup), 2)));
0081     end
0082     
0083     case 'all'
0084     errorVector.relativeSquared = ...
0085         computeMatrixError(matrixOne, matrixTwo, 'relativeSquared');
0086     
0087     errorVector.relativeMean = ...
0088         computeMatrixError(matrixOne, matrixTwo, 'relativeMean');
0089     
0090     errorVector.absoluteSquared = ...
0091         computeMatrixError(matrixOne, matrixTwo, 'absoluteSquared');
0092     
0093     errorVector.absoluteMean = ...
0094         computeMatrixError(matrixOne, matrixTwo, 'absolute');
0095     
0096     errorVector.relativeTotal = ...
0097         computeMatrixError(matrixOne, matrixTwo, 'relativeTotal');
0098     
0099     errorVector.absoluteTotal = ...
0100         computeMatrixError(matrixOne, matrixTwo, 'absoluteTotal');
0101     
0102     otherwise
0103     error('elk:approximation:wrongInput', ...
0104         ['Given error type ''' errorType '''is not supported']);
0105     
0106 end
0107 
0108 end
0109 
0110 function helpErrorDefinition()
0111 % %%% Detailed Error definitions for <a href="matlab: help computeMatrixError">computeMatrixError</a>
0112 % n  - total number of columns in matrixOne and matrixTwo
0113 % xi - reference value (column of matrixOne)
0114 % yi - sample value (column of matrixTwo)
0115 % e  - aggregated error vector
0116 %
0117 % %% absoluteSquared
0118 % e = sum( (xi - yi).^2 )
0119 %
0120 % %% relativeSquared
0121 % e = 1/n * sqrt(sum( ((xi - yi) ./ xi )^2 ))
0122 %
0123 % %% absolute
0124 % e = sum( abs(xi - yi) )
0125 %
0126 % %% relativeMean
0127 % e = 1/n * sum( abs(xi - yi) )
0128 %
0129 % %% absoluteTotal
0130 % e = ( sum( xi ) - sum( yi ) )
0131 %
0132 % %% relativeTotal
0133 % e = ( sum( xi ) - sum( yi ) ) / sum( xi )
0134 %
0135 % %%
0136 end

Generated on Sat 18-Jul-2015 16:45:31 by m2html © 2005