SUM_SQUAREFORM - sparse matrix that sums the squareform of a vector
Usage
[S, St] = sum_squareform(n)
[S, St] = sum_squareform(n, mask)
Output parameters
S |
matrix so that S*w = sum(W) for vector w = squareform(W) |
St |
the adjoint of S |
Description
- Creates sparse matrices S, St = S' so that
- S*w = sum(W), where w = squareform(W)
The mask is used for large scale computations where only a few
non-zeros in W are to be summed. It needs to be the same size as w,
n(n-1)/2 elements. See the example below for more details of usage.
Properties of S:
* size(S) = [n, (n(n-1)/2)] % if no mask is given.
* size(S, 2) = nnz(w) % if mask is given
* norm(S)^2 = 2(n-1)
* sum(S) = 2*ones(1, n*(n-1)/2)
* sum(St) = sum(squareform(mask)) -- for full mask = (n-1)*ones(n,1)
- Example::
- % if mask is given, the resulting S are the ones we would get with the
% following operations (but memory efficiently):
[S, St] = sum_squareform(n);
[ind_i, ~, w] = find(mask(:));
% get rid of the columns of S corresponding to zeros in the mask
S = S(:, ind_i);
St = St(ind_i, :);