From e8369874088c0ae4b1d98f79f5bae3319de2ac6d Mon Sep 17 00:00:00 2001 From: jeanpouget-abadie Date: Sun, 1 Feb 2015 16:33:04 -0500 Subject: updating code to Python 3 --- src/convex_optimization.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/convex_optimization.py') diff --git a/src/convex_optimization.py b/src/convex_optimization.py index 2661e25..02787d3 100644 --- a/src/convex_optimization.py +++ b/src/convex_optimization.py @@ -32,10 +32,10 @@ def sparse_recovery(M_val, w_val, lbda): y = (theta_).norm(1) + lbda * ( tensor.exp(M.dot(theta_)) - (1 - w)).norm(2) - return diff_and_opt(theta, theta_, M, w, lbda, y) + return diff_and_opt(theta, theta_, M, M_val, w, lbda, y) -def diff_and_opt(theta, theta_, M, w, lbda, y): +def diff_and_opt(theta, theta_, M, M_val, w, lbda, y): z = tensor.row().T z_ = z.flatten() @@ -60,15 +60,15 @@ def diff_and_opt(theta, theta_, M, w, lbda, y): cvxopt.matrix(y_diff.astype("float64")).T, \ cvxopt.matrix(y_hess.astype("float64")) - G = cvxopt.spdiag([1 for i in xrange(n)]) + G = cvxopt.spdiag([1 for i in range(n)]) h = cvxopt.matrix(0.0, (n,1)) cvxopt.solvers.options['show_progress'] = False try: theta = cvxopt.solvers.cp(F, G, h)['x'] except ArithmeticError: - print "ArithmeticError thrown, change initial point"+\ - " given to the solver" + print("ArithmeticError thrown, change initial point"+\ + " given to the solver") return 1 - np.exp(theta), theta @@ -83,7 +83,7 @@ def test(): A = cascade_creation.generate_cascades(G, .1, 2000) M_val, w_val = cascade_creation.icc_matrixvector_for_node(A, 0) p_vec, theta = l1obj_l2penalization(M_val, w_val, lbda) - print p_vec + print(p_vec) if __name__=="__main__": test() -- cgit v1.2.3-70-g09d2