Log2 in constraint

74 views
Skip to first unread message

Shahnewaz Sakib

unread,
Oct 23, 2020, 5:22:41 PM10/23/20
to cvxpy
Hi,

I have the following binary channel

P= [ p1 1 - p1; 1 - p2 p2]

Now, I have followed this link to compute mutual information (https://www.cvxpy.org/examples/applications/Channel_capacity_BV4.57.html). However, whenever I try to c=np.sum(Pnp.log2(P),axis=0) , it shows the error ‘‘Variable’ object has no attribute ‘log2’’.

import cvxpy as cp
import numpy as np

p1 = cp.Variable()
p2 = cp.Variable()

p0 = 0.5

P = np.array([[p1, 1- p1],
[1 - p2, p2]])

x = np.array([[p0],
[1 - p0]])

y = P * x

c = np.sum(P*np.log2( P ),axis=0)


I have two questions. 1. Why am I getting the previous error? 2. Is it possible to have optimization variable in log2 term and still solve the optimization problem using cvxpy?

Steven Diamond

unread,
Oct 29, 2020, 8:13:22 PM10/29/20
to cvxpy
You can't use numpy functions on cvxpy objects. You can only use cvxpy functions on cvxpy objects.
Reply all
Reply to author
Forward
0 new messages