NovembreLab / feems

MIT License
16 stars 14 forks source link

AssertionError: did not converge #30

Open qinshengyuan opened 10 months ago

qinshengyuan commented 10 months ago

I encountered the following errors. What should I do?

Mapping files: 100%|██████████| 3/3 [00:03<00:00, 1.19s/it] mambaforge/lib/python3.10/site-packages/feems/spatial_graph.py:81: RuntimeWarning: divide by zero encountered in divide self.frequencies = self.frequencies / np.sqrt(self.mu (1 - self.mu)) mambaforge/lib/python3.10/site-packages/feems/spatial_graph.py:81: RuntimeWarning: invalid value encountered in divide self.frequencies = self.frequencies / np.sqrt(self.mu (1 - self.mu)) Traceback (most recent call last): File "workspace/test-2.py", line 14, in class TestObjective(unittest.TestCase): File "workspace/test-2.py", line 37, in TestObjective sp_graph.fit(lamb = 20.0) File "mambaforge/lib/python3.10/site-packages/feems/spatial_graph.py", line 377, in fit self.fit_null_model(verbose=verbose) File "mambaforge/lib/python3.10/site-packages/feems/spatial_graph.py", line 313, in fit_null_model assert res.success is True, "did not converge" AssertionError: did not converge

VivaswatS commented 9 months ago

@qinshengyuan FEEMS only works with segregating sites so please ensure to remove invariant sites. Also, try a few different values of lamb in the fit function as there could be poor convergence with some extreme values. Let me know if the problem still persists!

JacobAFW commented 3 months ago

Hi @VivaswatS, I am having a very similar to the user above issue above:

 self.trA = self.sp_graph.S @ self.inv_cov
/home/jwestaway/micromamba/envs/src/feems/feems/objective.py:165: RuntimeWarning: invalid value encountered in matmul
  self.trA = self.sp_graph.S @ self.inv_cov
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
Cell In[43], line 1
----> 1 sp_graph.fit(lamb = float(20))

File ~/micromamba/envs/src/feems/feems/spatial_graph.py:377, in SpatialGraph.fit(self, lamb, w_init, s2_init, alpha, factr, maxls, m, lb, ub, maxiter, verbose)
    374 # init from null model if no init weights are provided
    375 if w_init is None and s2_init is None:
    376     # fit null model to estimate the residual variance and init weights
--> 377     self.fit_null_model(verbose=verbose)            
    378     w_init = self.w0
    379 else:
    380     # check initial edge weights

File ~/micromamba/envs/src/feems/feems/spatial_graph.py:313, in SpatialGraph.fit_null_model(self, verbose)
    311 obj = Objective(self)
    312 res = minimize(neg_log_lik_w0_s2, [0.0, 0.0], method="Nelder-Mead", args=(obj))
--> 313 assert res.success is True, "did not converge"
    314 w0_hat = np.exp(res.x[0])
    315 s2_hat = np.exp(res.x[1])

AssertionError: did not converge

I have tried a range of lambda values with no luck. Can you please clarify what you mean by segregating/invariant sites? I presumed you meant each sample has to be from a unique location?

Any advice would be very much appreciated! Thanks in advance!