From a245c9df987c72d46aa77f1b563e28982776ce46 Mon Sep 17 00:00:00 2001 From: Serge Koudoro Date: Thu, 14 Feb 2019 19:29:22 +0100 Subject: [PATCH 1/2] cvxpy workaround --- dipy/reconst/mapmri.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dipy/reconst/mapmri.py b/dipy/reconst/mapmri.py index 96566f1470..182f0e7449 100644 --- a/dipy/reconst/mapmri.py +++ b/dipy/reconst/mapmri.py @@ -395,6 +395,8 @@ def fit(self, data): data_norm = np.asarray(data / data[self.gtab.b0s_mask].mean()) c = cvxpy.Variable(M.shape[1]) + # workaround for the bug on cvxpy 1.0.15 when lopt = 0 + lopt = lopt or 10e-20 design_matrix = cvxpy.Constant(M) objective = cvxpy.Minimize( cvxpy.sum_squares(design_matrix * c - data_norm) + @@ -457,7 +459,6 @@ def __init__(self, model, mapmri_coef, mu, R, lopt, errorcode=0): that after positivity constraint failed, also matrix inversion failed. """ - self.model = model self._mapmri_coef = mapmri_coef self.gtab = model.gtab From 014b57f8aacb2256aff4ff2411e8266bf50bd481 Mon Sep 17 00:00:00 2001 From: Serge Koudoro Date: Thu, 14 Feb 2019 19:52:04 +0100 Subject: [PATCH 2/2] remove approximation --- dipy/reconst/mapmri.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/dipy/reconst/mapmri.py b/dipy/reconst/mapmri.py index 182f0e7449..83650e24c3 100644 --- a/dipy/reconst/mapmri.py +++ b/dipy/reconst/mapmri.py @@ -395,13 +395,17 @@ def fit(self, data): data_norm = np.asarray(data / data[self.gtab.b0s_mask].mean()) c = cvxpy.Variable(M.shape[1]) - # workaround for the bug on cvxpy 1.0.15 when lopt = 0 - lopt = lopt or 10e-20 design_matrix = cvxpy.Constant(M) - objective = cvxpy.Minimize( - cvxpy.sum_squares(design_matrix * c - data_norm) + - lopt * cvxpy.quad_form(c, laplacian_matrix) - ) + # workaround for the bug on cvxpy 1.0.15 when lopt = 0 + # See https://github.com/cvxgrp/cvxpy/issues/672 + if not lopt: + objective = cvxpy.Minimize( + cvxpy.sum_squares(design_matrix * c - data_norm)) + else: + objective = cvxpy.Minimize( + cvxpy.sum_squares(design_matrix * c - data_norm) + + lopt * cvxpy.quad_form(c, laplacian_matrix) + ) M0 = M[self.gtab.b0s_mask, :] constraints = [(M0[0] * c) == 1, (K * c) >= -0.1]