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

slpwcomp_blks

PURPOSE ^

SLPWCOMP_BLKS Computes pairwise value matrix

SYNOPSIS ^

function slpwcomp_blks(X1, X2, ps, dstpath, compfunc, varargin)

DESCRIPTION ^

SLPWCOMP_BLKS Computes pairwise value matrix

 $ Syntax $
   - slpwcomp_blks(X1, X2, ps, dstpath, compfunc, ...)

 $ Arguments $
   - X1:           the first source sample matrix
   - X2:           the second source sample matrix
   - ps:           the partition structure of the target value matrix
   - dstpath:      the destination path
   - compfunc:     the normal pairwise computing function
   
 $ Description $
   - slpwcomp_blks(X1, X2, ps, dstpath, compfunc, ...) computes the 
     large scale pairwise value matrix in a block-wise way. Suppose
     X1 has n1 columns, while X2 has n2 columns, it will produce a
     n1 x n2 matrix, when both n1 and n2 are large, then the huge
     value matrix may not be held entirely in the memory. The function
     partition the value matrix into several blocks according to 
     the partition structure specified in ps, which can be obtained 
     by slpartition. Then for each block, the function will select
     corresponding section of samples from X1 and X2, then compute the
     corresponding value block and store it to an array file. 
     The name of core output file is <dstname>.mat, so you need not
     to add .mat when you input dstname. Please note that the core
     mat file does not contain the actual value matrix, but some 
     information for retrievaling them. There are following variables
     in the mat file:
       - 'parstruct':      the partition structure
       - 'blocks':         the 2D cell array of block limits
       - 'data':           the 2D cell array of filenames of array data
       - 'matsize':        the whole size of the value matrix
  
 $ Remarks $
   - compfunc is the underlying pairwise value matrix computation
     function. It has a form f(X1, X2, ...), when it inputs X1 and
     X2 with n1 and n2 columns respectively, it outputs an n1 x n2
     value matrix. It can be function name, inline function or
     function handle.
     
 $ History $
   - Created by Dahua Lin, on Aug 8th, 2006

CROSS-REFERENCE INFORMATION ^

This function calls:
  • slfilepart SLFILEPARTS Extracts a specified part of a file path string
  • slwritearray SLWRITEARRAY Writes an array to an array file
  • raise_lackinput RAISE_LACKINPUT Raises an error indicating lack of input argument
  • sladdpath SLADDPATH Adds dirpath to precede the filenames
  • slignorevars SLIGNOREVARS Ignores the input variables
  • slparblocks SLPARBLOCKS Gets the blocks from partition structure
This function is called by:
  • slmetric_pw_blks SLMETRIC_PW_BLKS Compute the pairwise metrics in a blockwise manner

SOURCE CODE ^

0001 function slpwcomp_blks(X1, X2, ps, dstpath, compfunc, varargin)
0002 %SLPWCOMP_BLKS Computes pairwise value matrix
0003 %
0004 % $ Syntax $
0005 %   - slpwcomp_blks(X1, X2, ps, dstpath, compfunc, ...)
0006 %
0007 % $ Arguments $
0008 %   - X1:           the first source sample matrix
0009 %   - X2:           the second source sample matrix
0010 %   - ps:           the partition structure of the target value matrix
0011 %   - dstpath:      the destination path
0012 %   - compfunc:     the normal pairwise computing function
0013 %
0014 % $ Description $
0015 %   - slpwcomp_blks(X1, X2, ps, dstpath, compfunc, ...) computes the
0016 %     large scale pairwise value matrix in a block-wise way. Suppose
0017 %     X1 has n1 columns, while X2 has n2 columns, it will produce a
0018 %     n1 x n2 matrix, when both n1 and n2 are large, then the huge
0019 %     value matrix may not be held entirely in the memory. The function
0020 %     partition the value matrix into several blocks according to
0021 %     the partition structure specified in ps, which can be obtained
0022 %     by slpartition. Then for each block, the function will select
0023 %     corresponding section of samples from X1 and X2, then compute the
0024 %     corresponding value block and store it to an array file.
0025 %     The name of core output file is <dstname>.mat, so you need not
0026 %     to add .mat when you input dstname. Please note that the core
0027 %     mat file does not contain the actual value matrix, but some
0028 %     information for retrievaling them. There are following variables
0029 %     in the mat file:
0030 %       - 'parstruct':      the partition structure
0031 %       - 'blocks':         the 2D cell array of block limits
0032 %       - 'data':           the 2D cell array of filenames of array data
0033 %       - 'matsize':        the whole size of the value matrix
0034 %
0035 % $ Remarks $
0036 %   - compfunc is the underlying pairwise value matrix computation
0037 %     function. It has a form f(X1, X2, ...), when it inputs X1 and
0038 %     X2 with n1 and n2 columns respectively, it outputs an n1 x n2
0039 %     value matrix. It can be function name, inline function or
0040 %     function handle.
0041 %
0042 % $ History $
0043 %   - Created by Dahua Lin, on Aug 8th, 2006
0044 %
0045 
0046 %% parse and verify input arguments
0047     
0048 if nargin < 5
0049     raise_lackinput('slpwcomp_blks', 5);
0050 end
0051 if ~isnumeric(X1) || ndims(X1) ~= 2 || ~isnumeric(X2) || ndims(X2) ~= 2
0052     error('sltoolbox:invalidargs', ...
0053         'X1 and X2 should be 2D numeric matrices');
0054 end
0055 if ~isstruct(ps) || length(ps) ~= 2
0056     error('sltoolbox:invalidargs', ...
0057         'ps should be a struct array with 2 elements');
0058 end
0059 
0060 n1 = size(X1, 2);
0061 n2 = size(X2, 2);
0062 
0063 parstruct = ps;
0064 matsize = [n1, n2];
0065 
0066 slignorevars(matsize);
0067 
0068 %% Prepare Blocks
0069 
0070 blocks = slparblocks(parstruct);
0071 [nrows, ncols] = size(blocks);
0072 nblocks = nrows * ncols;
0073 
0074 %% Prepare Filenames
0075 
0076 len1 = length(int2str(n1));
0077 len2 = length(int2str(n2));
0078 
0079 dstcorepath = [dstpath, '.mat'];
0080 dstdir = slfilepart(dstpath, 'parent');
0081 dsttitle = slfilepart(dstpath, 'name');
0082 arrnamepat = sprintf('%s.c%%0%dd-%%0%dd.r%%0%dd-%%0%dd.arr', dsttitle, len1, len1, len2, len2);
0083 
0084 data = cell(nrows, ncols);
0085 for i = 1 : nrows
0086     for j = 1 : ncols
0087         cb = blocks{i, j};
0088         data{i, j} = sprintf(arrnamepat, cb(1, 1), cb(2, 1), cb(1, 2), cb(2, 2));
0089     end
0090 end
0091 
0092 %% Compute and store (blockwise)
0093 
0094 if ~isempty(dstdir) && ~exist(dstdir, 'dir')
0095     mkdir(dstdir);
0096 end
0097 
0098 for k = 1 : nblocks
0099     curblock = blocks{k};
0100     curpath = sladdpath(data{k}, dstdir);
0101     
0102     curX1 = X1(:, curblock(1,1):curblock(2,1));
0103     curX2 = X2(:, curblock(1,2):curblock(2,2));
0104     
0105     M = feval(compfunc, curX1, curX2, varargin{:});
0106     
0107     slwritearray(M, curpath);
0108 end
0109 
0110 %% Save core file
0111 save(dstcorepath, 'parstruct', 'blocks', 'data', 'matsize', '-v6');
0112 
0113

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

Contact us at files@mathworks.com