cvxpy norms equivalent

284 views
Skip to first unread message

Glenn

unread,
Jun 22, 2015, 2:31:43 PM6/22/15
to cv...@googlegroups.com
I am trying to implement the Sum Of Norms clustering method ( here is an example in cvx for MATLAB), but I am having an issue with calculating the p-norm along a single dimension of a matrix.  When using cvxpy.pnorm() on a matrix, a scalar value is returned.  Is there a way to tell cvxpy to only take the pnorm along a certain dimension like the norms function in cvx for MATLAB?

Currently, I am using cvxpy.vstack to generate a vector of p-norms with the following code:

a = cvx.vstack(0)

for i in xrange(numColJ):

     a = cvx.vstack(a,cvx.pnorm(J*X[i,:],p=p))


This method works for a small data set, but I get "RuntimeError: maximum recursion depth exceeded in cmp" when I try this on a larger data set.


Thanks

Steven Diamond

unread,
Jun 22, 2015, 2:41:59 PM6/22/15
to cv...@googlegroups.com
You're doing the right thing, except you don't want to stack the norms until the end. Make this change:

elems = []

for i in xrange(numColJ):

     elems += [cvx.pnorm(J*X[i,:],p=p)]

a = cvx.vstack(*elems)

The * unpacks a list into multiple arguments.

Mustafa S Eisa

unread,
May 14, 2017, 4:26:14 PM5/14/17
to cvxpy
Thank you Steven! That is so handy
Reply all
Reply to author
Forward
0 new messages