Norm of group of elements whose position is reported on a cell array

2 ビュー (過去 30 日間)
jason beckell
jason beckell 2018 年 4 月 15 日
編集済み: jason beckell 2018 年 4 月 16 日
Dear all,
I have a vector x containing 4095 unknowns. I know that these unknowns have been already clustered into 115 classes, whose positions are reported in a cell array of length 115 (i.e. at position i of the cell array, there are the indexes of all the elements in the vector x belonging to class i). My questions is the following. Is there a way to get a vector with the 2-norm of the elements of x which belongs to each clusters (hence, a vector of length 115) WITHOUT using any loop? My problem arises since I have to pass such norms as a variable to be optimized by a numerical solver (cvx). Hence, since it will be part of the objective function to be optimized, I cannot put any cycle inside of it. Moreover, my objective function also contains a linear combinations of such unknowns, hence it is not so evident to me if there exist any bounds which may satisfy my request as a work-around. If required, I can pre-transform the cell array into another structure.
Many thanks for the attention and my best regards.
Jason.

採用された回答

Akira Agata
Akira Agata 2018 年 4 月 15 日
編集済み: Akira Agata 2018 年 4 月 15 日
Like this?
% Sample data x and class info cell array g
x = rand(10,1);
g = {[1 3 5 7 9],[2 4 6 8 10]};
% Calculate 2-norm for each class
func = @(idx) norm(x(idx));
d = cellfun(func,g);
  1 件のコメント
jason beckell
jason beckell 2018 年 4 月 16 日
編集済み: jason beckell 2018 年 4 月 16 日
Dear Akira,
many thanks for your answer. I have finally discovered that the expression within a cxvblock must be declared by means of the keyword "expression". Hence, in our instance, the required code turns out to be something like this:
% Sample data x and class info cell array g
n = 10;
x = rand(n,1);
g = {[1 3 5 7 9],[2 4 6 8 10]};
% cvx block
cvx_begin
variable x(n)
expression l(length(g))
func = @(idx) norm(x(idx));
l = cellfun(func,g);
minimize((norm(A*x+b))+l(1))
cvx_end
Many thanks for your help! Best,
Jason.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Identification についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by