Home > vbmeg > functions > common > utility > vb_err_array.m

vb_err_array

PURPOSE ^

calculate difference of two arrays

SYNOPSIS ^

function [err, Sx, Sy] = vb_err_array(x,y)

DESCRIPTION ^

 calculate difference of two arrays
 err = vb_err_array(x,y) 
     = sum( abs(x-y) )/sum( abs(x) )
     = sum( abs(x-y) ) if sum( abs(x) ) == 0
 --- Input
 x, y : numerical array (any size)
 --- Output
 err : normalized error
 --- Error info
 [err, Sx, Sy] = vb_err_array(x,y)

 if size of x & y is different, 
  err = -1 is returned, and error massage is printed
  Sx, Sy = size of x & y

 2006/10/3 M. Sato

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function    [err, Sx, Sy] = vb_err_array(x,y)
0002 % calculate difference of two arrays
0003 % err = vb_err_array(x,y)
0004 %     = sum( abs(x-y) )/sum( abs(x) )
0005 %     = sum( abs(x-y) ) if sum( abs(x) ) == 0
0006 % --- Input
0007 % x, y : numerical array (any size)
0008 % --- Output
0009 % err : normalized error
0010 % --- Error info
0011 % [err, Sx, Sy] = vb_err_array(x,y)
0012 %
0013 % if size of x & y is different,
0014 %  err = -1 is returned, and error massage is printed
0015 %  Sx, Sy = size of x & y
0016 %
0017 % 2006/10/3 M. Sato
0018 %
0019 % Copyright (C) 2011, ATR All Rights Reserved.
0020 % License : New BSD License(see VBMEG_LICENSE.txt)
0021 
0022 Sx = size(x);
0023 Sy = size(y);
0024 Nx = length(Sx);
0025 Ny = length(Sy);
0026 
0027 % Check size of x & y
0028 if Nx ~= Ny | sum(abs(Sx - Sy)) > 0
0029     fprintf('Size of two arrays are different\n')
0030     fprintf('Size = ')
0031     disp(Sx)
0032     fprintf('Size = ')
0033     disp(Sy)
0034     err = -1;
0035     return
0036 end
0037 
0038 xx  = sum(abs(x(:)));
0039 err = sum(abs(x(:)-y(:)));
0040 
0041 if xx > 0,
0042     err = err/xx;
0043 end
0044 
0045 %%% -- END of program
0046 
0047 % if x and y is vector, make it a row vector
0048 %if Nx==2 & Ny==2
0049 %    if Sx(1)==1, Sx(1) = Sx(2); Sx(2) = 1; end;
0050 %    if Sy(1)==1, Sy(1) = Sy(2); Sy(2) = 1; end;
0051 %end

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005