Open digicosmos86 opened 1 year ago
Our users have reported similar errors with more contextual information. Please see this issue: https://github.com/lnccbrown/HSSM/issues/301
@digicosmos86 thanks for opening the issue and linking the one in HSSM. I'll try to have a look at it soon.
@digicosmos86 do you know in which OS this is happening?
Thanks for looking into this, @tomicapretto! I am using MacOS (ARM64) with Python 3.11, but the user who reported the issue seems to be using linux, with Python versions both 3.9 and 3.11
I'm on Ubuntu 22.04.3 LTS and I get a different error: TypeError: cannot pickle '_hashlib.HMAC' object
. See:
I will keep looking into it.
@digicosmos86 so I think I fixed it. I'm going to tell you about my highly professional debugging process :smile:
File ~/anaconda3/envs/bambi_hssm/lib/python3.10/site-packages/formulae/terms/terms.py:1283, in create_extra_term(term, encoding, data, env)
1281 components = [term.get_component(name) for name in component_names if name in encoding.keys()]
1282 components += [component for component in term.components if component.kind == "numeric"]
-> 1283 extra_term = Term(*deepcopy(components))
1284 extra_term.set_type(data, env)
1285 return extra_term
So I realized the problem is when we try to deepcopy(components)
. Components contains the atomic components of a model term (i.e. a main effect has a single component, an interaction between two variables has two components, etc.). So I...
print(components)
right before line 1283 in that file. I saw the following output[Call(C(conf))]
The problem occurs when it is creating a C(conf)
term. Notice you're not adding it explicitly, but it gets added because of the C(dbs):C(conf)
interaction. Then I noticed conf
is already a categorical variable, so the C()
call is not needed.
C(dbs):C(conf)
for C(dbs):conf
in all places and that's it :) This is the model
model_side = hssm.HSSM(
data=cav_data,
model="ddm",
a = 1,
hierarchical = False,
include=[
{
"name": "v", # Drift rate
"prior": {
"Intercept": {
"name": "Normal",
"sigma": 1,
"mu": 0.0,
}
},
"formula": "v ~ 1 + (stim|subj_idx) + (1|subj_idx) + C(dbs):conf",
"link": "identity",
},
{
"name": "z", # Starting point
"prior": {
"Intercept": {
"name": "Normal",
"sigma": 1,
"mu": 0.0,
}
},
"formula": "z ~ 1 + (stim|subj_idx) + (1|subj_idx) + C(dbs):conf",
"link": "identity",
},
{
"name": "t", # Starting point
"prior": {
"Intercept": {
"name": "Normal",
"sigma": 1,
"mu": 0.0,
}
},
"formula": "t ~ 1 + (stim|subj_idx) + (1|subj_idx) + C(dbs):conf",
"link": "identity",
},
],
)
NOTE I didn't try to fit it. If you do, let me know what happens.
I still think there's a problem because this shouldn't happen. But at least for now, there's a fix. If you have this problem again and you have numeric variables that need to be interpreted as categoric, convert them to object type before creating the model or tell Bambi they're categorical with the categorical
argument.
Thanks @tomicapretto! Looks like this fixed it on my end 👍
The
hssm
package relies onbambi
for model creation. A Type error is thrown during the creation of certain models with certain term combinations:This is the error (Python=3.11, bambi=0.12)