0001 function S = slpwscatter(tar, W)
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 if isnumeric(tar)
0045
0046 X = tar;
0047 if ndims(X) ~= 2
0048 error('sltoolbox:invaliddims', ...
0049 'X should be a 2D matrix');
0050 end
0051 m = size(X, 2);
0052
0053 targettype = 1;
0054
0055 elseif iscell(tar)
0056
0057 if length(tar) ~= 2
0058 error('sltoolbox:invalidarg', ...
0059 'For cell target, it should be in the form {X, Y}');
0060 end
0061
0062 X = tar{1};
0063 Y = tar{2};
0064
0065 if ndims(X) ~= 2 || ndims(Y) ~= 2
0066 error('sltoolbox:invaliddims', ...
0067 'X and Y should be a 2D matrices');
0068 end
0069
0070 if size(X, 1) ~= size(Y, 1)
0071 error('sltoolbox:sizmismatch', ...
0072 'The sample dimensions in X and Y are inconsistent');
0073 end
0074
0075 m = size(X, 2);
0076 n = size(Y, 2);
0077
0078 targettype = 2;
0079
0080 else
0081
0082 error('sltoolbox:invalidarg', ...
0083 'The tar should be either X or {X, Y}');
0084
0085 end
0086
0087
0088
0089 if nargin < 2
0090 W = [];
0091 end
0092
0093 if ~isempty(W)
0094 switch targettype
0095 case 1
0096 if ~isequal(size(W), [m, m])
0097 error('sltoolbox:sizmismatch', ...
0098 'The weight matrix W should be an m x m matrix');
0099 end
0100 case 2
0101 if ~isequal(size(W), [m, n])
0102 error('sltoolbox:sizmismatch', ...
0103 'The weight matrix W should be an m x n matrix');
0104 end
0105 end
0106 end
0107
0108
0109
0110
0111 switch targettype
0112
0113 case 1
0114
0115 if isempty(W)
0116 D = diag(m(ones(m, 1)));
0117 W = ones(m, m);
0118 M = 2 * (D - W);
0119
0120 clear D W;
0121 else
0122 D = diag(sum(W,1)' + sum(W,2));
0123 M = D - (W + W');
0124
0125 clear D;
0126 end
0127
0128 S = X * M * X';
0129
0130 case 2
0131
0132 if isempty(W)
0133 S1 = X * diag(m(ones(m, 1))) * X';
0134 S2 = Y * diag(n(ones(n, 1))) * Y';
0135 S12 = S1 + S2;
0136 clear S1 S2;
0137
0138 S3 = X * ones(m, n) * Y';
0139 S34 = S3 + S3';
0140 clear S3;
0141
0142 S = S12 - S34;
0143 else
0144 S1 = X * diag(sum(W, 2)) * X';
0145 S2 = Y * diag(sum(W, 1)) * Y';
0146 S12 = S1 + S2;
0147 clear S1 S2;
0148
0149 S3 = X * W * Y';
0150 S34 = S3 + S3';
0151 clear S3;
0152
0153 S = S12 - S34;
0154 end
0155
0156
0157 end
0158
0159
0160
0161
0162
0163
0164
0165
0166