Skip to content

Commit

Permalink
mix catch for singular matrix inversion
Browse files Browse the repository at this point in the history
  • Loading branch information
rutgerfick committed Feb 27, 2018
1 parent 754ef58 commit 6c7b092
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions dmipy/optimizers/mix.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,13 @@ def stochastic_objective_function(self, optimized_parameter_vector,
phi_x = self.model(acquisition_scheme,
quantity="stochastic cost function",
**parameters)
phi_inv = np.dot(np.linalg.inv(np.dot(phi_x.T, phi_x)), phi_x.T)
vf = np.dot(phi_inv, data)
A = np.dot(phi_x.T, phi_x)
try:
phi_inv = np.dot(np.linalg.inv(A), phi_x.T)
vf = np.dot(phi_inv, data)
except np.linalg.linalg.LinAlgError:
# happens when models have the same signal attenuations.
vf = np.ones(self.Nmodels) / float(self.Nmodels)
E_hat = np.dot(phi_x, vf)
objective = np.dot(data - E_hat, data - E_hat).squeeze()
return objective * 1e5
Expand Down

0 comments on commit 6c7b092

Please sign in to comment.