0001 function T = slgbfe(X, G, Gc, dy, fm, 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 if nargin < 5
0058 raise_lackinput('slgbfe', 5);
0059 end
0060
0061 if ~isnumeric(X) || ndims(X) ~= 2
0062 error('sltoolbox:invalidarg', 'X should be a 2D numeric matrix');
0063 end
0064 n = size(X, 2);
0065
0066 if ~iscell(fm) || length(fm) ~= 2
0067 error('sltoolbox:invalidarg', 'fm should be a length-2 cell array');
0068 end
0069 fg = fm{1};
0070 fc = fm{2};
0071
0072 gi = slgraphinfo(G, {[n, n]});
0073 W = sladjmat(G, ...
0074 'valtype', 'numeric', ...
0075 'sparse', strcmp(gi.form, 'adjmat') && issparse(G));
0076
0077 if strcmp(fc, 'WC') || strcmp(fc, 'LC')
0078 if isempty(Gc)
0079 error('sltoolbox:invalidarg', ...
0080 'When fc is WC or LC, Gc should not be empty');
0081 end
0082 slgraphinfo(Gc, {'adjmat', [n, n]});
0083 if isnumeric(Gc)
0084 Wc = Gc;
0085 else
0086 Wc = double(Gc);
0087 end
0088 else
0089 Wc = [];
0090 end
0091
0092
0093 opts.whparams = {};
0094 opts.skip = 0;
0095 opts = slparseprops(opts, varargin{:});
0096
0097
0098
0099
0100
0101 W = (W + W') * (1/2);
0102 if ~isempty(Wc)
0103 Wc = (Wc + Wc') * (1/2);
0104 end
0105
0106
0107 switch fg
0108 case 'maxW'
0109 R = X * W * X';
0110 rfg = 'maxW';
0111 case 'minW'
0112 R = X * W * X';
0113 rfg = 'minW';
0114 case 'maxL'
0115 R = X * make_Lmat(W) * X';
0116 rfg = 'maxW';
0117 case 'minL'
0118 R = X * make_Lmat(W) * X';
0119 rfg = 'minW';
0120 otherwise
0121 error('sltoolbox:invalidarg', 'Invalid fg name: %s', fg);
0122 end
0123
0124
0125 switch fc
0126 case 'O'
0127 Rc = [];
0128 rfc = 'I';
0129 case 'I'
0130 Rc = X * X';
0131 rfc = 'WC';
0132 case 'WC'
0133 Rc = X * Wc * X';
0134 rfc = 'WC';
0135 case 'LC'
0136 Rc = X * make_Lmat(Wc) * X';
0137 rfc = 'WC';
0138 otherwise
0139 error('sltoolbox:invalidarg', 'Invalid fc name: %s', fc);
0140 end
0141
0142
0143
0144
0145 Y = slgembed(R, Rc, dy, {rfg, rfc}, ...
0146 'inv', opts.whparams, ...
0147 'skip', opts.skip);
0148 T = Y';
0149
0150
0151
0152
0153 function L = make_Lmat(W)
0154
0155 vD = sum(W, 1)';
0156 if issparse(vD)
0157 vD = full(vD);
0158 end
0159
0160 n = size(W, 1);
0161 if issparse(W)
0162 D = sparse((1:n)', (1:n)', vD, n, n, n);
0163 L = D - W;
0164 else
0165 L = -W;
0166 dinds = (1:n)'*(n+1)-n;
0167 L(dinds) = L(dinds) + vD;
0168 end
0169