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

sample_crp_tablecounts in cstats fails in certain cases #57

Open
jonahpearl opened this issue Jan 6, 2022 · 0 comments
Open

sample_crp_tablecounts in cstats fails in certain cases #57

jonahpearl opened this issue Jan 6, 2022 · 0 comments

Comments

@jonahpearl
Copy link

jonahpearl commented Jan 6, 2022

Trying to model some data with a negative binomial duration distribution...the /util/cstats/sample_crp_tablecounts function was failing because its second argument integral[:,:] customers was being passed in as a float. The numbers being passed in appear to be durations in n_samples, so they're guaranteed to be integers, so I fixed by changing line 31 in pyhsmm/distributions (within the _StartAtOneMixin.resample() method) from
return super(_StartAtOneMixin,self).resample(data-1, *args,**kwargs)
to
return super(_StartAtOneMixin,self).resample((data-1).astype('int'), *args,**kwargs).

If I have time I'll try to track down what caused the error in the first place.

*** Code to reproduce ***


data = np.arange(10).reshape(-1,1)
Nmax = 25

# and some hyperparameters
obs_dim = data.shape[1]
obs_hypparams = {'mu_0':np.zeros(obs_dim),
                'sigma_0':np.eye(obs_dim),
                'kappa_0':0.25,
                'nu_0':obs_dim+2}
obs_distns = [pyhsmm.distributions.Gaussian(**obs_hypparams) for state in range(Nmax)]

dur_hypparams = {'r':3., 'p':0.5, 'k_0':2., 'theta_0':2., 'alpha_0':2., 'beta_0':2.}
dur_distns = [pyhsmm.distributions.NegativeBinomialDuration(**dur_hypparams) for state in range(Nmax)]

posteriormodel = pyhsmm.models.WeakLimitHDPHSMM(
        alpha=6.,gamma=6., # these can matter; see concentration-resampling.py
        init_state_concentration=6., # pretty inconsequential
        obs_distns=obs_distns,
        dur_distns=dur_distns)

posteriormodel.add_data(data, trunc=60) # duration truncation speeds things up when it's possible

for idx in progprint_xrange(150):
    posteriormodel.resample_model()

*** Traceback from error ***

TypeError Traceback (most recent call last)
/tmp/ipykernel_16301/156295421.py in
35
36 for idx in progprint_xrange(150):
---> 37 posteriormodel.resample_model()

~/datta-lab/pyhsmm/pyhsmm/models.py in resample_model(self, num_procs)
454 @line_profiled
455 def resample_model(self,num_procs=0):
--> 456 self.resample_parameters()
457 self.resample_states(num_procs=num_procs)
458

~/datta-lab/pyhsmm/pyhsmm/models.py in resample_parameters(self, **kwargs)
964 @line_profiled
965 def resample_parameters(self,**kwargs):
--> 966 self.resample_dur_distns()
967 super(_HSMMGibbsSampling,self).resample_parameters(**kwargs)
968

~/datta-lab/pyhsmm/pyhsmm/models.py in resample_dur_distns(self)
969 def resample_dur_distns(self):
970 for state, distn in enumerate(self.dur_distns):
--> 971 distn.resample_with_censoring_and_truncation(
972 data=
973 [s.durations_censored[s.untrunc_slice][s.stateseq_norep[s.untrunc_slice] == state]

~/datta-lab/pyhsmm/pyhsmm/basic/abstractions.py in resample_with_censoring_and_truncation(self, data, censored_data, left_truncation_level)
101 rejected_observations = []
102
--> 103 self.resample(data=combinedata((data,filled_in,rejected_observations)))
104
105 @Property

~/datta-lab/pyhsmm/pyhsmm/basic/distributions.py in resample(self, data, *args, **kwargs)
33 else:
34 # return super(_StartAtOneMixin,self).resample([(d-1).astype('int') for d in data],*args,**kwargs)
---> 35 return super(_StartAtOneMixin,self).resample([d-1 for d in data],*args,**kwargs)
36
37 def max_likelihood(self,data,weights=None,*args,**kwargs):

~/miniconda3/envs/dataPy_NWB/lib/python3.9/site-packages/pybasicbayes/distributions/negativebinomial.py in resample(self, data, niter)
113 for itr in range(niter):
114 ### resample r
--> 115 msum = sample_crp_tablecounts(self.r,data).sum()
116 self.r = np.random.gamma(self.k_0 + msum, 1/(1/self.theta_0 - N*np.log(1-self.p)))
117 ### resample p

pybasicbayes/util/cstats.pyx in pybasicbayes.util.cstats.__pyx_fused_cpdef()

TypeError: Function call with ambiguous argument types

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

1 participant