Home > functions > common > utility > vb_err_cell.m

vb_err_cell

PURPOSE ^

calculate difference of two cell arrays

SYNOPSIS ^

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

DESCRIPTION ^

 calculate difference of two cell 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 cell array
 --- Output
 err : normalized error
 --- Error info
 [err , Sx, Sy, indx ] = vb_err_cell(x,y)

 if size of cell array x & y is different, 
   err = -1 is returned, and error massage is printed
   Sx, Sy = size of x & y
   indx = []
 if size of each element in the cell is different, 
   err = -2 is returned, and error massage is printed
   indx   = element index with different 
   Sx, Sy = size of elements x{indx} & y{indx}

 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:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function    [err , Sx, Sy, indx ] = vb_err_cell(x,y)
0002 % calculate difference of two cell 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 cell array
0008 % --- Output
0009 % err : normalized error
0010 % --- Error info
0011 % [err , Sx, Sy, indx ] = vb_err_cell(x,y)
0012 %
0013 % if size of cell array x & y is different,
0014 %   err = -1 is returned, and error massage is printed
0015 %   Sx, Sy = size of x & y
0016 %   indx = []
0017 % if size of each element in the cell is different,
0018 %   err = -2 is returned, and error massage is printed
0019 %   indx   = element index with different
0020 %   Sx, Sy = size of elements x{indx} & y{indx}
0021 %
0022 % 2006/10/3 M. Sato
0023 %
0024 % Copyright (C) 2011, ATR All Rights Reserved.
0025 % License : New BSD License(see VBMEG_LICENSE.txt)
0026 
0027 [N1, M1] = size(x);
0028 [N2, M2] = size(y);
0029 
0030 Sx   = [N1, M1];
0031 Sy   = [N2, M2];
0032 indx = [];
0033 
0034 if N1~=N2 | M1~=M2
0035     print_size_dif(Sx,Sy);
0036     err  = -1;
0037     return
0038 end
0039 
0040 xx  = 0;
0041 err = 0;
0042 
0043 for n=1:N1
0044     for m=1:M1
0045         Sx = size(x{n,m});
0046         Sy = size(y{n,m});
0047         if sum(abs(Sx - Sy)) > 0,
0048             print_insize_dif(Sx,Sy,n,m);
0049             err  = -2;
0050             indx = [n,m];
0051             return
0052         end
0053         xx  = xx  + sum(sum(sum(abs(x{n,m}))));
0054         err = err + sum(sum(sum(abs(x{n,m} - y{n,m}))));
0055     end
0056 end
0057 
0058 if xx > 0,
0059     err = err/xx;
0060 end
0061 
0062 function print_size_dif(Sx,Sy)
0063 
0064 fprintf('Size of two cell arrays are different\n')
0065 fprintf('Size = ')
0066 disp(Sx)
0067 fprintf('Size = ')
0068 disp(Sy)
0069 
0070 function print_insize_dif(Sx,Sy,n,m)
0071 
0072 fprintf('Size of cell element {%d,%d} is different\n', n,m)
0073 fprintf('Size = ')
0074 disp(Sx)
0075 fprintf('Size = ')
0076 disp(Sy)
0077 
0078 
0079 
0080 % if x and y is vector, only check length
0081 %if N1==1
0082 %    x = x';
0083 %end
0084 %if N2==1
0085 %    y = y';
0086 %end
0087 %
0088 %[N1, M1] = size(x);
0089 %[N2, M2] = size(y);

Generated on Tue 27-Aug-2013 11:46:04 by m2html © 2005