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

slpweval

PURPOSE ^

SLPWEVAL Perform pairwise computation

SYNOPSIS ^

function M = slpweval(X1, X2, f, varargin)

DESCRIPTION ^

SLPWEVAL Perform pairwise computation

 $ Syntax $
   - M = slpweval(X1, X2, f)
   - M = slpweval(X1, X2, f, ...)

 $ Arguments $
   - X1:       the matrix of vectors serving as first argument of f
   - X2:       the matrix of vectors serving as second argument of f
   - f:        the function maps two vectors to a single scalar value
   - M:        the matrix of pairwise evaluaton results

 $ Description $
   - M = slpweval(X1, X2, f) takes vector arguments from X1 and X2, and 
     computes the pairwise evaluation result with f. The vectors in X1
     and X2 are stored in a column-wise manner. Suppose X1 and X2 have 
     m and n columns respectively, then the resultant matrix M would be
     of size m x n, with the M(i, j) = f(X1(:,i), X2(:,j)). 
   
   - M = slpweval(X1, X2, f, ...) conducts the computation with extra
     parameters to f, i.e. M(i, j) = f(X1(:,i), X2(:,j), ...).

 $ Remarks $
   - The vector length of the vectors in X1 and X2 are not necessarily
     equal. The requirment on their dimensions depends on the callback
     function f.
   - For efficiency, the function would invoke f to evaluate in batch.
     Thus f should support batch-evaluation. When the input arguments
     to f have n columns, f should return an 1 x n row vector.

 $ History $
   - Created by Dahua Lin on Apr 21, 2006
   - Modified by Dahua Lin on Sep 10, 2006
       - make some minor changes to suppress warnings

CROSS-REFERENCE INFORMATION ^

This function calls:
  • raise_lackinput RAISE_LACKINPUT Raises an error indicating lack of input argument
  • slignorevars SLIGNOREVARS Ignores the input variables
This function is called by:
  • slkernel SLKERNEL Computes the kernel for samples

SOURCE CODE ^

0001 function M = slpweval(X1, X2, f, varargin)
0002 %SLPWEVAL Perform pairwise computation
0003 %
0004 % $ Syntax $
0005 %   - M = slpweval(X1, X2, f)
0006 %   - M = slpweval(X1, X2, f, ...)
0007 %
0008 % $ Arguments $
0009 %   - X1:       the matrix of vectors serving as first argument of f
0010 %   - X2:       the matrix of vectors serving as second argument of f
0011 %   - f:        the function maps two vectors to a single scalar value
0012 %   - M:        the matrix of pairwise evaluaton results
0013 %
0014 % $ Description $
0015 %   - M = slpweval(X1, X2, f) takes vector arguments from X1 and X2, and
0016 %     computes the pairwise evaluation result with f. The vectors in X1
0017 %     and X2 are stored in a column-wise manner. Suppose X1 and X2 have
0018 %     m and n columns respectively, then the resultant matrix M would be
0019 %     of size m x n, with the M(i, j) = f(X1(:,i), X2(:,j)).
0020 %
0021 %   - M = slpweval(X1, X2, f, ...) conducts the computation with extra
0022 %     parameters to f, i.e. M(i, j) = f(X1(:,i), X2(:,j), ...).
0023 %
0024 % $ Remarks $
0025 %   - The vector length of the vectors in X1 and X2 are not necessarily
0026 %     equal. The requirment on their dimensions depends on the callback
0027 %     function f.
0028 %   - For efficiency, the function would invoke f to evaluate in batch.
0029 %     Thus f should support batch-evaluation. When the input arguments
0030 %     to f have n columns, f should return an 1 x n row vector.
0031 %
0032 % $ History $
0033 %   - Created by Dahua Lin on Apr 21, 2006
0034 %   - Modified by Dahua Lin on Sep 10, 2006
0035 %       - make some minor changes to suppress warnings
0036 %
0037 
0038 %% parse and verify input arguments
0039 
0040 if nargin < 3
0041     raise_lackinput('slpweval', 3);
0042 end
0043 [d1, n1] = size(X1);
0044 [d2, n2] = size(X2);
0045 slignorevars(d1, d2);
0046 
0047 %% compute
0048 
0049 % prepare output matrix
0050 M = zeros(n1, n2);
0051 
0052 if n1 > n2      % expand each column in X2 to n1 copies
0053  
0054     inds_e = ones(1, n1);
0055     for i = 1 : n2        
0056         x2 = X2(:, i);
0057         X2e = x2(:, inds_e);        
0058         M(:, i) = feval(f, X1, X2e, varargin{:})';            
0059     end
0060     
0061 else            % expand each column in X1 to n2 copies
0062     
0063     inds_e = ones(1, n2);
0064     for i = 1 : n1
0065         x1 = X1(:, i);
0066         X1e = x1(:, inds_e);
0067         M(i, :) = feval(f, X1e, X2, varargin{:});
0068     end    
0069     
0070 end
0071

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

Contact us at files@mathworks.com