Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AssertionError: did not converge #30

Open
qinshengyuan opened this issue Feb 1, 2024 · 2 comments
Open

AssertionError: did not converge #30

qinshengyuan opened this issue Feb 1, 2024 · 2 comments

Comments

@qinshengyuan
Copy link

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
Copy link
Collaborator

@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
Copy link

JacobAFW commented Aug 9, 2024

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants