aboutsummaryrefslogtreecommitdiffstats
path: root/src/convex_optimization.py
diff options
context:
space:
mode:
authorjeanpouget-abadie <jean.pougetabadie@gmail.com>2015-02-01 16:33:04 -0500
committerjeanpouget-abadie <jean.pougetabadie@gmail.com>2015-02-01 16:33:04 -0500
commite8369874088c0ae4b1d98f79f5bae3319de2ac6d (patch)
tree1ab49efbcdab69a7eaad354bb869883b769ab9c9 /src/convex_optimization.py
parent0991a13214af4023259465f132f09e6c66f3895c (diff)
downloadcascades-e8369874088c0ae4b1d98f79f5bae3319de2ac6d.tar.gz
updating code to Python 3
Diffstat (limited to 'src/convex_optimization.py')
-rw-r--r--src/convex_optimization.py12
1 files changed, 6 insertions, 6 deletions
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()