Recover Dynamics ValueError
See original GitHub issueHi Volker,
I tried to use the very new dynamical model on one of my datasets.
I get an ValueError
after 73% of the recovering dynamics step.
Traceback:
ValueError Traceback (most recent call last)
<ipython-input-8-5a274db81b65> in <module>
89 #test
90
---> 91 scv.tl.recover_dynamics(adata)
92 scv.tl.velocity(adata, mode='dynamical')
93
/miniconda/lib/python3.7/site-packages/scvelo/tools/dynamical_model.py in recover_dynamics(data, var_names, n_top_genes, max_iter, assignment_mode, t_max, fit_time, fit_scaling, fit_steady_states, fit_connected_states, fit_basal_transcription, use_raw, load_pars, return_model, plot_results, steady_state_prior, add_key, copy, **kwargs)
331 dm = DynamicsRecovery(adata, gene, use_raw=use_raw, load_pars=load_pars, max_iter=max_iter, fit_time=fit_time,
332 fit_steady_states=fit_steady_states, fit_connected_states=conn, fit_scaling=fit_scaling,
--> 333 fit_basal_transcription=fit_basal_transcription, steady_state_prior=steady_state_prior, **kwargs)
334 if dm.recoverable:
335 dm.fit(assignment_mode=assignment_mode)
/miniconda/lib/python3.7/site-packages/scvelo/tools/dynamical_model.py in __init__(self, adata, gene, load_pars, **kwargs)
21 self.load_pars(adata, gene)
22 elif self.recoverable:
---> 23 self.initialize()
24
25 def initialize(self):
/miniconda/lib/python3.7/site-packages/scvelo/tools/dynamical_model.py in initialize(self)
46
47 # initialize switching from u quantiles and alpha from s quantiles
---> 48 tstat_u, pval_u, means_u = test_bimodality(u_w, kde=True)
49 tstat_s, pval_s, means_s = test_bimodality(s_w, kde=True)
50 self.pval_steady = max(pval_u, pval_s)
/miniconda/lib/python3.7/site-packages/scvelo/tools/utils.py in test_bimodality(x, bins, kde, plot)
266
267 grid = np.linspace(np.min(x), np.percentile(x, 99), bins)
--> 268 kde_grid = gaussian_kde(x)(grid) if kde else np.histogram(x, bins=grid, density=True)[0]
269
270 idx = int(bins / 2) - 2
/miniconda/lib/python3.7/site-packages/scipy/stats/kde.py in __init__(self, dataset, bw_method, weights)
206 self._neff = 1/sum(self._weights**2)
207
--> 208 self.set_bandwidth(bw_method=bw_method)
209
210 def evaluate(self, points):
/miniconda/lib/python3.7/site-packages/scipy/stats/kde.py in set_bandwidth(self, bw_method)
538 raise ValueError(msg)
539
--> 540 self._compute_covariance()
541
542 def _compute_covariance(self):
/miniconda/lib/python3.7/site-packages/scipy/stats/kde.py in _compute_covariance(self)
550 bias=False,
551 aweights=self.weights))
--> 552 self._data_inv_cov = linalg.inv(self._data_covariance)
553
554 self.covariance = self._data_covariance * self.factor**2
/miniconda/lib/python3.7/site-packages/scipy/linalg/basic.py in inv(a, overwrite_a, check_finite)
943
944 """
--> 945 a1 = _asarray_validated(a, check_finite=check_finite)
946 if len(a1.shape) != 2 or a1.shape[0] != a1.shape[1]:
947 raise ValueError('expected square matrix')
/miniconda/lib/python3.7/site-packages/scipy/_lib/_util.py in _asarray_validated(a, check_finite, sparse_ok, objects_ok, mask_ok, as_inexact)
237 raise ValueError('masked arrays are not supported')
238 toarray = np.asarray_chkfinite if check_finite else np.asarray
--> 239 a = toarray(a)
240 if not objects_ok:
241 if a.dtype is np.dtype('O'):
/miniconda/lib/python3.7/site-packages/numpy/lib/function_base.py in asarray_chkfinite(a, dtype, order)
494 if a.dtype.char in typecodes['AllFloat'] and not np.isfinite(a).all():
495 raise ValueError(
--> 496 "array must not contain infs or NaNs")
497 return a
498
ValueError: array must not contain infs or NaNs
Versions:
scvelo==0.1.24.dev6+geb35fe8 scanpy==1.4.4 anndata==0.6.22.post1 loompy==2.0.17 numpy==1.17.0 scipy==1.2.1 matplotlib==3.0.2 sklearn==0.21.3 pandas==0.25.1
Best, Tobi
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (5 by maintainers)
Top Results From Across the Web
Excel #value error. - Microsoft Community
Excel #value error. ... appears warning that data may be lost. Is there any simple way (I am not computer savvy) to recover...
Read more >Microsoft Dynamics CRM Forum
Retrieve Dynamics 365 Accounts with multiple columns using C# - Object reference not to an instance. Suggested Answer. Hi everyone,.
Read more >Problem with "Rejecting initial value:..." error while fitting an ODE
The simple solution is to fix (one or more, or all) the initial parameter values to make sure the output isn't too far...
Read more >Google PubSub Subscription cannot recover from StatusCode ...
Google Pubsub Python Client library subscriber crashes randomly seems to be the same cause but the use case is different. The answer (provided ......
Read more >Reply To: The truth value error - Ansys Learning Forum
... acp-ansys, acp-compositematerials, acp-error, acp-explicit-dynamics, acp-pre ... record-session, recovery-structure-workbench, rectangle, rectangular ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for your quick support, I really appreciate this. Unfortunately your added line did not fix my problem (same error and stacktrace).
But I found the culprit. For one gene, the following code
https://github.com/theislab/scvelo/blob/6dbaafa725c1d1af981ac836e7c9d458310eb70f/scvelo/tools/dynamical_model.py#L25-L33
is only selecting zeroes for
u_w
. The initialself.u
may contain a lot of zeros (~99.5% of the values), but its not completely zero (otherwise it would have been filtered out). The NaNs are produced when dividing byscaling
, which subsequently is also 0.The error is resolved when I remove the gene in question from the
var_names
- which is totally fine for me at the moment. Nevertheless I would suggest to implement a check to prevent the division by zero.Best, Tobi
It worked, at least in the data set I have. Great job!