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 slpwmetricgraph
Home > sltoolbox > graph > slpwmetricgraph.m

slpwmetricgraph

PURPOSE ^

SLPWMETRICGRAPH Constructs a graph based on pairwise metrics

SYNOPSIS ^

function G = slpwmetricgraph(X, varargin)

DESCRIPTION ^

SLPWMETRICGRAPH Constructs a graph based on pairwise metrics

 $ Syntax $
   - G = slpwmetricgraph(X, ...)
   - G = slpwmetricgraph(X, Xt, ...)

 $ Arguments $
   - X:        The sample matrix with each column as a (source) node
   - Xt:       The sample matrix with each column as a (target) node  
   - G:        The constructed graph
   
 $ Description $
   - G = slpwmetricgraph(X, ...) constructs a graph based on computation
     of pairwise metric between vector samples. You can specify the 
     following properties:
     \*
     \t   The Properties of Graph Matrix construction           \\
     \h      name       &      description
            'sparse'    & whether the target graph G is sparse 
                          (default = true)
            'valtype'   & The type of values in G: 'logical'|'numeric'
                          (default = 'numeric')
                          The value output by evalfunctor should conform
                          to the specified valtype
            'maxblk'    & The maximum number of elements that can be
                          computed in each batch. (default = 1e7)   
            'mfunctor'  & The functor to compute the metrics. In the form:
                          V = f(X1, X2, ...)
                          default = {@slmetric_pw, 'eucdist')
            'tfunctor'  & The functor to transform the metric values,
                          like tv = f(sv, ...)
                          The transform is taken before the threshold 
                          filtering. default = []
            'thres'     & The threshold values. The values not in the
                          valid range set by the threshold is regarded as
                          zeros. 
                          (default = [], means not to use threshold)
            'threstype' & The type of threshold value, (default = 'ub')
                           - 'lb': a lower bound scalar 
                                   valid_range: x >= thres
                           - 'ub': a upper bound scalar
                                   valid_range: x <= thres
                           - 'lub': a vector of lower and upper bounds
                                    valid_range: thres(1) <= x <= thres(2)                           
     \*

   - G = slpwmetricgraph(X, Xt, ...) constructs a bigraph with different
     source and target node set. The properties mentioned above are
     all applicable here.

 $ Remarks $
   - The implementation is based on slpwgraph.

 $ History $
   - Created by Dahua Lin, on Sep 8th, 2006
   - Modified by Dahua Lin, on Sep 10th, 2006
       - Base on upgraded slpwgraph function
       - Add support for bigraph

CROSS-REFERENCE INFORMATION ^

This function calls:
  • slmetric_pw SLMETRIC_PW Compute the metric between column vectors pairwisely
  • slpwgraph SLVALGRAPH Constructs a graph by computing values between nodes pairwisely
  • slevalfunctor SLEVALFUNCTOR Evaluates a functor
  • slparseprops SLPARSEPROPS Parses input parameters
This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function G = slpwmetricgraph(X, varargin)
0002 %SLPWMETRICGRAPH Constructs a graph based on pairwise metrics
0003 %
0004 % $ Syntax $
0005 %   - G = slpwmetricgraph(X, ...)
0006 %   - G = slpwmetricgraph(X, Xt, ...)
0007 %
0008 % $ Arguments $
0009 %   - X:        The sample matrix with each column as a (source) node
0010 %   - Xt:       The sample matrix with each column as a (target) node
0011 %   - G:        The constructed graph
0012 %
0013 % $ Description $
0014 %   - G = slpwmetricgraph(X, ...) constructs a graph based on computation
0015 %     of pairwise metric between vector samples. You can specify the
0016 %     following properties:
0017 %     \*
0018 %     \t   The Properties of Graph Matrix construction           \\
0019 %     \h      name       &      description
0020 %            'sparse'    & whether the target graph G is sparse
0021 %                          (default = true)
0022 %            'valtype'   & The type of values in G: 'logical'|'numeric'
0023 %                          (default = 'numeric')
0024 %                          The value output by evalfunctor should conform
0025 %                          to the specified valtype
0026 %            'maxblk'    & The maximum number of elements that can be
0027 %                          computed in each batch. (default = 1e7)
0028 %            'mfunctor'  & The functor to compute the metrics. In the form:
0029 %                          V = f(X1, X2, ...)
0030 %                          default = {@slmetric_pw, 'eucdist')
0031 %            'tfunctor'  & The functor to transform the metric values,
0032 %                          like tv = f(sv, ...)
0033 %                          The transform is taken before the threshold
0034 %                          filtering. default = []
0035 %            'thres'     & The threshold values. The values not in the
0036 %                          valid range set by the threshold is regarded as
0037 %                          zeros.
0038 %                          (default = [], means not to use threshold)
0039 %            'threstype' & The type of threshold value, (default = 'ub')
0040 %                           - 'lb': a lower bound scalar
0041 %                                   valid_range: x >= thres
0042 %                           - 'ub': a upper bound scalar
0043 %                                   valid_range: x <= thres
0044 %                           - 'lub': a vector of lower and upper bounds
0045 %                                    valid_range: thres(1) <= x <= thres(2)
0046 %     \*
0047 %
0048 %   - G = slpwmetricgraph(X, Xt, ...) constructs a bigraph with different
0049 %     source and target node set. The properties mentioned above are
0050 %     all applicable here.
0051 %
0052 % $ Remarks $
0053 %   - The implementation is based on slpwgraph.
0054 %
0055 % $ History $
0056 %   - Created by Dahua Lin, on Sep 8th, 2006
0057 %   - Modified by Dahua Lin, on Sep 10th, 2006
0058 %       - Base on upgraded slpwgraph function
0059 %       - Add support for bigraph
0060 %
0061 
0062 %% parse and verify input
0063 
0064 if nargin >= 2
0065     if isnumeric(varargin{1})
0066         Xt = varargin{1};
0067         if nargin == 2
0068             params = {};
0069         else
0070             params = varargin(2:end);
0071         end
0072     else
0073         Xt = X;
0074         params = varargin;
0075     end
0076 else
0077     Xt = X;
0078     params = {};
0079 end
0080 
0081 opts.sparse = true;
0082 opts.valtype = 'numeric';
0083 opts.maxblk = 1e7;
0084 opts.mfunctor = {@slmetric_pw, 'eucdist'};
0085 opts.tfunctor = [];
0086 opts.thres = [];
0087 opts.threstype = 'ub';
0088 opts = slparseprops(opts, params{:});
0089 
0090 if ~ismember(opts.threstype, {'lb', 'ub', 'lub'})
0091     error('sltoolbox:invalidarg', ...
0092         'Invalid type of threshold: %s', opts.threstype);
0093 end
0094 
0095 %% Main skeleton
0096 
0097 n = size(X, 2);
0098 nt = size(Xt, 2);
0099 mfunctor = opts.mfunctor;
0100 tfunctor = opts.tfunctor;
0101 filter = getvaluefilter(opts);
0102 evalfunctor = {@metricevalfunc, mfunctor, tfunctor, filter};
0103 
0104 G = slpwgraph(X, Xt, n, nt, evalfunctor, ...
0105     'sparse', opts.sparse, ...
0106     'valtype', opts.valtype, ...
0107     'maxblk', opts.maxblk);
0108 
0109 
0110 %% Core functions
0111 
0112 function V = metricevalfunc(X, Xt, inds1, inds2, mfunctor, tfunctor, filter)
0113 
0114 X1 = X(:, inds1);
0115 X2 = Xt(:, inds2);
0116 V = slevalfunctor(mfunctor, X1, X2);
0117 
0118 if ~isempty(tfunctor)
0119     V = slevalfunctor(tfunctor, V);
0120 end
0121 
0122 if ~isempty(filter)
0123     zero_range = ~filter(V);
0124     V(zero_range) = 0;
0125 end    
0126 
0127 
0128 function filter = getvaluefilter(opts)
0129 
0130 if isempty(opts.thres)
0131     filter = [];
0132 else
0133     thr = opts.thres;
0134     switch opts.threstype
0135         case 'lb'
0136             if ~isscalar(thr)
0137                 error('sltoolbox:invalidarg', 'For lb type, the thres should be a scalar');
0138             end
0139             filter = @(x) x >= thr;
0140         case 'ub'
0141             if ~isscalar(thr)
0142                 error('sltoolbox:invalidarg', 'For ub type, the thres should be a scalar');
0143             end
0144             filter = @(x) x <= thr;
0145         case 'lub'
0146             if ~isvector(thr) || length(thr) ~= 2
0147                 error('sltoolbox:invalidarg', 'For lub type, the thres should be a length-2 vector');
0148             end
0149             filter = @(x) x >= thr(1) & x <= thr(2);
0150     end
0151 end
0152

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

Contact us at files@mathworks.com