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

plot_posterior_predictive plot nothing when using HDDMRegressor #93

Open
const7 opened this issue Aug 29, 2022 · 2 comments
Open

plot_posterior_predictive plot nothing when using HDDMRegressor #93

const7 opened this issue Aug 29, 2022 · 2 comments

Comments

@const7
Copy link

const7 commented Aug 29, 2022

plot_posterior_predictive plot nothing when using HDDMRegressor with only a hint like <Figure size 576x432 with 0 Axes> in at least both HDDM 0.8.0 & 0.9.7.

Minimal code to reproduce:

import hddm
data, params = hddm.generate.gen_rand_data(params={'easy': {'v': 1, 'a': 2, 't': .3},
                                                   'hard': {'v': 1, 'a': 2, 't': .3}})
m = hddm.HDDMRegressor(data, 'v ~ condition')
m.sample(1000, burn=20)
m.plot_posterior_predictive()

When I traced the code I found that model nodes generated by HDDMRegressor don't have the pdf method. Not sure whether it's normal.
https://github.com/hddm-devs/kabuki/blob/50afecf96796b426d3191d31b7665bcb4aad8e2f/kabuki/analyze.py#L577-L580

@promitmoitra
Copy link

Since this has remained unanswered for so long, here is a minimal working example tracing the problem to the issue mentioned above.

import hddm
data, params = hddm.generate.gen_rand_data(params={'easy': {'v': 1, 'a': 2, 't': .3},
                                                   'hard': {'v': 1, 'a': 2, 't': .3}})

## Defining m_reg using HDDMRegressor class:
m_reg = hddm.HDDMRegressor(data, 'v ~ condition',include=['v'])
m_reg.sample(1000, burn=20)

## Code adapted from kabuki/kabuki/analyze.py (50afecf):
## plot_posterior_predictive() L575-L580
## _plot_posterior_pdf_node() L466

m_reg_obs = m_reg.get_observeds()
m_reg_grp = m_reg_obs.groupby('tag')
m_reg_nodes = list(m_reg_grp.groups.values())
if hasattr(m_reg_obs['node'].loc[m_reg_nodes[0][0]],'pdf')
    print("Node in {0} has pdf".format(type(m_reg)))
else:
    print("Node in {0} does not have pdf".format(type(m_reg)))

## Defining m using HDDM class
m = hddm.HDDM(data,include=['v'],depends_on={'v':'condition'})
m.sample(1000,burn=20)

m_obs = m.get_observeds()
grp = m_obs.groupby('tag')
nodes = list(grp.groups.values())
if hasattr(m_obs['node'].loc[nodes[0][0]],'pdf')
    print("Node in {0} has pdf".format(type(m)))
else:
    print("Node in {0} does not have pdf".format(type(m)))

## This is why plot_posterior_predictive() is generating an empty plot 
## for nodes in models defined by HDDMRegressor class.

Nodes in models defined by HDDM are Wfpt objects, with a pdf method.
Nodes in models defined by HDDMRegressor are WfptReg objects, which do not have a pdf method.

@hcp4715
Copy link
Contributor

hcp4715 commented Sep 2, 2023

@const7 @promitmoitra

Thanks for reporting this issue. I think Alex is busy with the release of the new HSSM. However, @Asynchro-Epool and I are working on a docker image that keep the funcationality of HDDM, we will try to figure this issue when we wrap the HDDM 0.9.8 into the docker image, but we are still working on it, will update our progress here.

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