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 slnorm
Home > sltoolbox > core > slnorm.m

slnorm

PURPOSE ^

SLNORM Compute the Lp-norms

SYNOPSIS ^

function An = slnorm(A, p, d)

DESCRIPTION ^

SLNORM Compute the Lp-norms

 $ Syntax $
   - An = slnorm(A)
   - An = slnorm(A, p)
   - An = slnorm(A, [], d)
   - An = slnorm(A, p, d)

 $ Arguments $
   - A:        the input array
   - p:        the order of the norm (default = 2)
   - d:        the dimension of subarrays (default = 1, column vectors)
   - An:       the resultant array

 $ Description $
   - An = slnorm(A) computes the L2 norm of column vectors of A. If A is
     an array of size d1 x d2 x ... dn, then An would be of size 
     1 x d2 x ... dn. Each value of An is the L2 norm of corresponding
     column vector.

   - An = slnorm(A, p) computes the Lp norm of column vectors of A. If A 
     is an array of size d1 x d2 x ... dn, then An would be of size 
     1 x d2 x ... dn. Each value of An is the Lp norm of corresponding
     column vector.

   - An = slnorm(A, [], d) computes the L2 norm of sub-arrays along the 
     dimensions specified by d. For example, if A is a d1 x d2 x ... dn
     array, and d = [1, 2], then An would be an array of size
     1 x 1 x d3 x ... x dn. Each value of An is the square root of square-
     sum of values in corresponding plane.

   - An = slnorm(A, p, d) computes the Lp norm of sub-arrays along the 
     dimensions specified by d.

 $ Remarks $
   # Lp norm is the pth order-root of the sum of p-th power of all values
     in a subspace. 
   # p can be inf or -inf. If p = inf, then the Lp norm is simply the
     maximum magnitude value; while if p = -inf, then the Lp norm is the 
     minimum magnitude value.

 $ History $
   - Created by Dahua Lin on Nov 19th, 2005

CROSS-REFERENCE INFORMATION ^

This function calls:
  • slmax SLMAX Compute the maximum of values in subarrays
  • slmin SLMIN Compute the minimum of values in subarrays
  • slsum SLSUM Compute the sum of values in subarrays
This function is called by:
  • sldiscrep SLDISCREP Evaluates the discrepancy of two arrays
  • slnormalize SLNORMALIZE Normalize the sub-arrays

SOURCE CODE ^

0001 function An = slnorm(A, p, d)
0002 %SLNORM Compute the Lp-norms
0003 %
0004 % $ Syntax $
0005 %   - An = slnorm(A)
0006 %   - An = slnorm(A, p)
0007 %   - An = slnorm(A, [], d)
0008 %   - An = slnorm(A, p, d)
0009 %
0010 % $ Arguments $
0011 %   - A:        the input array
0012 %   - p:        the order of the norm (default = 2)
0013 %   - d:        the dimension of subarrays (default = 1, column vectors)
0014 %   - An:       the resultant array
0015 %
0016 % $ Description $
0017 %   - An = slnorm(A) computes the L2 norm of column vectors of A. If A is
0018 %     an array of size d1 x d2 x ... dn, then An would be of size
0019 %     1 x d2 x ... dn. Each value of An is the L2 norm of corresponding
0020 %     column vector.
0021 %
0022 %   - An = slnorm(A, p) computes the Lp norm of column vectors of A. If A
0023 %     is an array of size d1 x d2 x ... dn, then An would be of size
0024 %     1 x d2 x ... dn. Each value of An is the Lp norm of corresponding
0025 %     column vector.
0026 %
0027 %   - An = slnorm(A, [], d) computes the L2 norm of sub-arrays along the
0028 %     dimensions specified by d. For example, if A is a d1 x d2 x ... dn
0029 %     array, and d = [1, 2], then An would be an array of size
0030 %     1 x 1 x d3 x ... x dn. Each value of An is the square root of square-
0031 %     sum of values in corresponding plane.
0032 %
0033 %   - An = slnorm(A, p, d) computes the Lp norm of sub-arrays along the
0034 %     dimensions specified by d.
0035 %
0036 % $ Remarks $
0037 %   # Lp norm is the pth order-root of the sum of p-th power of all values
0038 %     in a subspace.
0039 %   # p can be inf or -inf. If p = inf, then the Lp norm is simply the
0040 %     maximum magnitude value; while if p = -inf, then the Lp norm is the
0041 %     minimum magnitude value.
0042 %
0043 % $ History $
0044 %   - Created by Dahua Lin on Nov 19th, 2005
0045 %
0046 
0047 %% parse and verify input arguments
0048 if nargin < 2 || isempty(p)
0049     p = 2;
0050 end
0051 if nargin < 3 || isempty(d)
0052     d = 1;
0053 end
0054 if ~isscalar(p)
0055     error('sltoolbox:notscalar', 'p should be a scalar');
0056 end
0057 if p == 0
0058     error('sltoolbox:zeroerr', 'p should not be zero');
0059 end
0060 
0061 
0062 %% compute
0063 An = abs(A);
0064 if p == 1
0065     An = slsum(An, d);
0066 elseif p == 2
0067     An = sqrt(slsum(An .* An ,d));
0068 elseif p == inf
0069     An = slmax(An, d);
0070 elseif p == (-inf)
0071     An = slmin(An, d);
0072 else
0073     An = slsum(An.^p, d) .^ (1/p);
0074 end
0075 
0076 
0077     
0078 
0079 
0080     
0081     
0082 
0083 
0084 
0085 
0086 
0087

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

Contact us at files@mathworks.com