# Self-defined L1/L2 norm in TFOCS

#1

Hi there, I’m modifying the `prox_l1l2.m` in TFOCS so that I can compute the sum of the L2 norms for intervals in each row.

e.g.

input matrix:

``````x = 1  1  2  2
3  3  4  4
``````

original L1-L2 norm in TFOCS will give `sqrt(1^2 + 1^2 + 2^2 + 2^2) + sqrt(3^2 + 3^2 + 4^2 + 4^2)`

now I will also have a variable `group_len` that determines lengths of groups separated in rows and sum likewise

say `group_len = 2`, then the desired norm value is `sqrt(1^1 + 1^1) + sqrt(2^2 + 2^2) + sqrt(3^2 + 3^2) + sqrt(4^2 + 4^2)`

In `prox_l1_l2.m`, I think the first function `v = f(q,x)` calculates the norm, and I added as follows. I believe this one should be correct. However I’m confused about how to modify `prox_f_bsxfun` (I’m using MATLAB 2018a), I guess this function is to compute the subgradient, but no idea about the correct way to modify this function. I followed my own idea and changed as below, but don’t know about its correctness or how to validate it correctness.

Any suggestions?

``````function v = f(q, group_len, x)
[row_num, col_num] = size(x);
y = reshape(x', group_len, row_num * col_num / group_len)';
v = sum( q.* sqrt(sum(y.^2, 2)) );
end
``````
``````function x = prox_f_bsxfun(q, group_len, x,t)
[row_num, col_num] = size(x);
y = reshape(x', group_len, row_num * col_num / group_len)';
v1 = sqrt( sum(y.^2, 2) );
v2 = reshape(v1', col_num / group_len, row_num);
v = sum(v2, 1)';
s = 1 - 1 ./ max( v ./ ( t .* q ), 1 );
x = bsxfun( @times, x, s ); % Apr 24 2013. Should be faster
end
``````