Code covered by the BSD License  

Highlights from
Statistical Learning Toolbox

from Statistical Learning Toolbox by Dahua Lin
Functions for statistical learning, pattern recognition and computer vision, covering many topics.

Description of sldiscrep
Home > sltoolbox > core > sldiscrep.m

sldiscrep

PURPOSE ^

SLDISCREP Evaluates the discrepancy of two arrays

SYNOPSIS ^

function d = sldiscrep(X1, X2, measure, r1)

DESCRIPTION ^

SLDISCREP Evaluates the discrepancy of two arrays

 $ Syntax $
   - d = sldiscrep(X1, X2, measure)
   - d = sldiscrep(X1, X2, measure, true)

 $ Arguments $
   - X1:       the first array
   - X2:       the second array
   - measure:  the name of measure
   - d:        the measure value

 $ Description $
   - d = sldiscrep(X1, X2, measure) evaluates the discrepancy between
     X1 and X2 according to the specified measure. 

     \*
     \t   Table 1. Discrepancy Measures
     \h    name        &     description
          'fro'        & Compute the Frobenius between two arrays
                         that is to sum the square differences and
                         compute the square root.
          'avgfro'     & Compute the average Frobenius norm between
                         two arrays, that is to average the square
                         differences, and compute the square root.
          'energy'     & Compute the total difference square energy.
          'avgenergy'  & Compute the average difference square energy.
          'maxdiffabs' & Compute the maximum element-wise absolute 
                         difference
          'maxdiffnrm' & Compute the maximum column-wise difference
                         norm.
     \*  

   - d = sldiscrep(X1, X2, measure, true) computes the relative measure
     with X1 as reference. By default, this mode is disabled.

 $ History $
   - Created by Dahua Lin, on Aug 17, 2006

CROSS-REFERENCE INFORMATION ^

This function calls:
  • slnorm SLNORM Compute the Lp-norms
  • raise_lackinput RAISE_LACKINPUT Raises an error indicating lack of input argument
This function is called by:
  • slfmm SLFMM Learns a Finite Mixture Model (FMM)

SOURCE CODE ^

0001 function d = sldiscrep(X1, X2, measure, r1)
0002 %SLDISCREP Evaluates the discrepancy of two arrays
0003 %
0004 % $ Syntax $
0005 %   - d = sldiscrep(X1, X2, measure)
0006 %   - d = sldiscrep(X1, X2, measure, true)
0007 %
0008 % $ Arguments $
0009 %   - X1:       the first array
0010 %   - X2:       the second array
0011 %   - measure:  the name of measure
0012 %   - d:        the measure value
0013 %
0014 % $ Description $
0015 %   - d = sldiscrep(X1, X2, measure) evaluates the discrepancy between
0016 %     X1 and X2 according to the specified measure.
0017 %
0018 %     \*
0019 %     \t   Table 1. Discrepancy Measures
0020 %     \h    name        &     description
0021 %          'fro'        & Compute the Frobenius between two arrays
0022 %                         that is to sum the square differences and
0023 %                         compute the square root.
0024 %          'avgfro'     & Compute the average Frobenius norm between
0025 %                         two arrays, that is to average the square
0026 %                         differences, and compute the square root.
0027 %          'energy'     & Compute the total difference square energy.
0028 %          'avgenergy'  & Compute the average difference square energy.
0029 %          'maxdiffabs' & Compute the maximum element-wise absolute
0030 %                         difference
0031 %          'maxdiffnrm' & Compute the maximum column-wise difference
0032 %                         norm.
0033 %     \*
0034 %
0035 %   - d = sldiscrep(X1, X2, measure, true) computes the relative measure
0036 %     with X1 as reference. By default, this mode is disabled.
0037 %
0038 % $ History $
0039 %   - Created by Dahua Lin, on Aug 17, 2006
0040 %
0041 
0042 %% parse and verify input arguments
0043 
0044 if nargin < 3
0045     raise_lackinput('sldiscrep', 3);
0046 end
0047 
0048 if ~isequal(size(X1), size(X2))
0049     error('sltoolbox:sizmismatch', ...
0050         'The sizes of X1 and X2 are different');
0051 end
0052 
0053 if nargin < 4 || isempty(r1)
0054     r1 = false;
0055 end
0056 
0057 %% compute
0058 
0059 switch measure
0060     case 'fro'
0061         D = X1(:) - X2(:);
0062         d = sqrt(sum(D.^2));
0063         clear D;
0064         if r1
0065             d0 = sqrt(sum(X1(:).^2));
0066             d = d / d0;
0067         end        
0068         
0069     case 'avgfro'
0070         n = numel(X1);
0071         D = X1(:) - X2(:);
0072         d = sqrt(sum(D.^2) / n);
0073         clear D;
0074         if r1
0075             d0 = sqrt(sum(X1(:).^2) / n);
0076             d = d / d0;
0077         end  
0078         
0079     case 'energy'
0080         D = X1(:) - X2(:);
0081         d = sum(D.^2);
0082         clear D;
0083         if r1
0084             d0 = sum(X1(:).^2);
0085             d = d / d0;
0086         end  
0087         
0088     case 'avgenergy'
0089         n = numel(X1);
0090         D = X1(:) - X2(:);
0091         d = sum(D.^2) / n;
0092         clear D;
0093         if r1
0094             d0 = sum(X1(:).^2) / n;
0095             d = d / d0;
0096         end  
0097         
0098     case 'maxdiffabs'
0099         if ~r1
0100             D = X1(:) - X2(:);
0101             d = max(abs(D));
0102         else
0103             D = (X1(:) - X2(:)) ./ X1(:);
0104             d = max(abs(D(:)));
0105         end
0106         
0107     case 'maxdiffnrm'
0108         if ~r1
0109             dn = slnorm(X1 - X2);
0110             d = max(dn(:));
0111         else
0112             dn = slnorm(X1 - X2);
0113             dn1 = slnorm(X1);
0114             d = max(dn(:) ./ dn1(:));
0115         end
0116         
0117     otherwise
0118         error('sltoolbox:invalidarg', ...
0119             'Invalid measure name %s', measure);
0120 end
0121 
0122 
0123     
0124 
0125 
0126

Generated on Wed 20-Sep-2006 12:43:11 by m2html © 2003

Contact us at files@mathworks.com