Skip to content

Commit

Permalink
catch for singular matrix MIX2
Browse files Browse the repository at this point in the history
  • Loading branch information
rutgerfick committed Oct 5, 2018
1 parent fbac002 commit d86bc78
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions dmipy/optimizers/mix.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,16 @@ def __call__(self, data, x0_vector=np.array([np.nan])):
quantity="stochastic cost function", **parameters)
try:
phi_inv = np.dot(np.linalg.inv(np.dot(phi.T, phi)), phi.T)
vf_x0 = np.dot(phi_inv, data)
vf_x0 /= np.sum(np.clip(vf_x0, 0, np.inf))
vf = fmin_cobyla(self.cobyla_cost_function, x0=vf_x0,
cons=[cobyla_positivity_constraint,
cobyla_unity_constraint],
args=(phi, data),
maxfun=2000)
except np.linalg.linalg.LinAlgError:
# happens when models have the same signal attenuations.
# happens when models have the same signal attenuations.
vf = np.ones(self.Nmodels) / float(self.Nmodels)
vf_x0 = np.dot(phi_inv, data)
vf_x0 /= np.sum(np.clip(vf_x0, 0, np.inf))
vf = fmin_cobyla(self.cobyla_cost_function, x0=vf_x0,
cons=[cobyla_positivity_constraint,
cobyla_unity_constraint],
args=(phi, data),
maxfun=2000)

vf_nested = np.ones(len(vf) - 1)
vf_nested[0] = vf[0]
for i in np.arange(1, len(vf_nested)):
Expand Down

0 comments on commit d86bc78

Please sign in to comment.