def channel_capacity(n, m, sum_x=1):
 if ((n * m) == 0):
  print 'The range of both input and output values must be greater than zero'
  return ('failed', np.nan, np.nan)
 P = np.ones((m, n))
 x = cvx.Variable(rows=n, cols=1)
 y = (P * x)
 c = np.sum((P * np.log2(P)), axis=0)
 I = ((c * x) + cvx.sum_entries(cvx.entr(y)))
 obj = cvx.Minimize((- I))
 constraints = [(cvx.sum_entries(x) == sum_x), (x >= 0)]
 prob = cvx.Problem(obj, constraints)
 prob.solve()
 if (prob.status == 'optimal'):
  return (prob.status, prob.value, x.value)
 else:
  return (prob.status, np.nan, np.nan)

def channel_capacity ( n , m , sum_x = 1 ) : if ( ( n * m ) == 0 ) : print 'The range of both input and output values must be greater than zero' return ( 'failed' , np . nan , np . nan ) P = np . ones ( ( m , n ) ) x = cvx . Variable ( rows = n , cols = 1 ) y = ( P * x ) c = np . sum ( ( P * np . log2 ( P ) ) , axis = 0 ) I = ( ( c * x ) + cvx . sum_entries ( cvx . entr ( y ) ) ) obj = cvx . Minimize ( ( - I ) ) constraints = [ ( cvx . sum_entries ( x ) == sum_x ) , ( x >= 0 ) ] prob = cvx . Problem ( obj , constraints ) prob . solve ( ) if ( prob . status == 'optimal' ) : return ( prob . status , prob . value , x . value ) else : return ( prob . status , np . nan , np . nan )
boyd and vandenberghe .