| Description of slpwmetricgraph |
slpwmetricgraph
PURPOSE 
SLPWMETRICGRAPH Constructs a graph based on pairwise metrics
SYNOPSIS 
function G = slpwmetricgraph(X, varargin)
DESCRIPTION 
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
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
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
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
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
|
|