theislab / scCODA

A Bayesian model for compositional single-cell data analysis
BSD 3-Clause "New" or "Revised" License
142 stars 23 forks source link

Error in samle_hmc() #8

Closed le-ander closed 4 years ago

le-ander commented 4 years ago

Hey there, I have successfully used this tool on my data a couple of months ago. unfortunately I now get the following error (both for the model with ans without baseline):

MCMC sampling finished. (189.715 sec)
Acceptance rate: 45.1%

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-65-b8c3ad8ee3bd> in <module>
      7 for i in range(5):
      8     ca = mod.CompositionalAnalysis(a, "condition", baseline_index=baseline)
----> 9     params_mcmc = ca.sample_hmc()
     10     thisgrp = [i[1] for i in params_mcmc.summary_prepare()[1][params_mcmc.summary_prepare()[1]['final_parameter'] != 0]['final_parameter'].index]
     11     print('Significant:', thisgrp)

/storage/groups/ml01/workspace/leander.dony/projects/organoids_chronic/git/SCDCdm_public/scdcdm/model/dirichlet_models.py in sample_hmc(self, num_results, n_burnin, num_leapfrog_steps, step_size)
    224                                      dims=dims,
    225                                      coords=coords).to_result_data(sampling_stats=sampling_stats,
--> 226                                                                    model_specs=model_specs)
    227 
    228     def sample_nuts(self, num_results=int(10e3), n_burnin=int(5e3), max_tree_depth=10, step_size=0.01):

/storage/groups/ml01/workspace/leander.dony/projects/organoids_chronic/git/SCDCdm_public/scdcdm/util/result_classes.py in to_result_data(self, sampling_stats, model_specs)
     33                 "sample_stats_prior": ssp,
     34                 "prior_predictive": prip,
---> 35                 "observed_data": obs,
     36             }
     37         )

/storage/groups/ml01/workspace/leander.dony/projects/organoids_chronic/git/SCDCdm_public/scdcdm/util/result_classes.py in __init__(self, sampling_stats, model_specs, **kwargs)
     78         self.model_specs = model_specs
     79 
---> 80         intercept_df, effect_df = self.summary_prepare()
     81 
     82         self.intercept_df = intercept_df

/storage/groups/ml01/workspace/leander.dony/projects/organoids_chronic/git/SCDCdm_public/scdcdm/util/result_classes.py in summary_prepare(self, *args, **kwargs)
    132         hpds_new = hpds.str.replace("hpd_", "HPD ")
    133 
--> 134         intercept_df = intercept_df.loc[:, ["final_parameter", hpds[0], hpds[1], "sd", "expected_sample"]]
    135         intercept_df = intercept_df.rename(columns=dict(zip(
    136             intercept_df.columns,

/opt/python/lib/python3.7/site-packages/pandas/core/indexes/base.py in __getitem__(self, key)
   3927         if is_scalar(key):
   3928             key = com.cast_scalar_indexer(key)
-> 3929             return getitem(key)
   3930 
   3931         if isinstance(key, slice):

IndexError: index 0 is out of bounds for axis 0 with size 0
johannesostner commented 4 years ago

Hi, it seems that the data frame with the information about the intercepts is empty (has no rows). This might be an issue with some recent package updates. Can you tell me which versions of tensorflow, tensorflow-probability and arviz you are running?

johannesostner commented 4 years ago

UPDATE: The latest release of arviz caused the issue. The newest commit should fix it.

b-schubert commented 4 years ago

@johannesostner Thanks!