Closed hyang336 closed 2 weeks ago
Hello,
In HSSM 0.2.2, we added the ability for the users to specify the number of choices in the HSSM class. You can use the “choices” argument to specify the number of choices that you have. We did it so that we can more robustly check the issues in the dataset the users provide.
Let me know if this works for you. Thanks!
http://ccv.brown.edu/ Paul Xu, PhD https://github.com/digicosmos86
Lead Data Scientist Center for Computation and Visualization Brown University | OIT Pronouns: he/him/his
On Sat, Jun 15, 2024 at 7:43 PM hyang336 @.***> wrote:
Describe the bug When running the same model that worked on 0.2.1, the following error occurred:
Traceback (most recent call last): File "/home/hyang336/PPCPRC/analyses/test_phase/HSSM/Simulations.py", line 199, in model_race4nba_v_true = hssm.HSSM( ^^^^^^^^^^ File "/home/hyang336/HSSM022_tempENV/lib/python3.11/site-packages/hssm/hssm.py", line 383, in init self._post_check_data_sanity() File "/home/hyang336/HSSM022_tempENV/lib/python3.11/site-packages/hssm/hssm.py", line 1685, in _post_check_data_sanity raise ValueError( ValueError: Invalid responses found in your dataset: [0, 2, 3]
HSSM version 0.2.2
To Reproduce a0=0 b0=1
intercept0=np.log(1/beta(a0,b0))
intercept0=0.85
a1=1.5 b1=3
intercept1=np.log(1/beta(a1,b1))
intercept1=2.1
a2=3 b2=1.5
intercept2=np.log(1/beta(a2,b2))
intercept2=2.1
a3=1 b3=0
intercept3=np.log(1/beta(a3,b3))
intercept3=0.85
n_subjects=30 #number of subjects n_trials=200 #number of trials per subject param_sv=0.2 #standard deviation of the subject-level parameters Save trial-level parameters for each subject
subject_params={ "v0": np.array([]), "v1": np.array([]), "v2": np.array([]), "v3": np.array([]), "simneural": np.array([]), "subID": np.array([]) } simulated data list
sim_data=[] Generate subject-level parameters
for i in range(n_subjects):
set the seed for each subject deterministically so all models are based
on the same data np.random.seed(i)
generate neural data
simneural=np.random.uniform(0, 1, size=n_trials)
Whether to include subject-specific slope, default is False
if SubSlope:
generate v0, v1, v2, v3
v0=np.exp(np.random.normal(intercept0, param_sv) + np.random.normal(a0, param_sv)
np.log(simneural) + np.random.normal(b0, param_sv)np.log(1-simneural)) v1=np.exp(np.random.normal(intercept1, param_sv) + np.random.normal(a1, param_sv)np.log(simneural) + np.random.normal(b1, param_sv)np.log(1-simneural)) v2=np.exp(np.random.normal(intercept2, param_sv) + np.random.normal(a2, param_sv)np.log(simneural) + np.random.normal(b2, param_sv)np.log(1-simneural)) v3=np.exp(np.random.normal(intercept3, param_sv) + np.random.normal(a3, param_sv)np.log(simneural) + np.random.normal(b3, param_sv)np.log(1-simneural)) else: # generate v0, v1, v2, v3 v0=np.exp(np.random.normal(intercept0, param_sv) + a0np.log(simneural) + b0np.log(1-simneural)) v1=np.exp(np.random.normal(intercept1, param_sv) + a1np.log(simneural) + b1np.log(1-simneural)) v2=np.exp(np.random.normal(intercept2, param_sv) + a2np.log(simneural) + b2np.log(1-simneural)) v3=np.exp(np.random.normal(intercept3, param_sv) + a3np.log(simneural) + b3np.log(1-simneural))
IMPORTANT: for interpretable param rec test, make sure generate params within training bounds of LAN
only keep entries in subject_data that are in bounds
v0_inb= np.where(np.logical_and(v0>= 0,v0<= 2.5)) v1_inb= np.where(np.logical_and(v1>= 0,v1<= 2.5)) v01_inb=np.intersect1d(v0_inb[0],v1_inb[0])
v2_inb= np.where(np.logical_and(v2>= 0,v2<= 2.5)) v3_inb= np.where(np.logical_and(v3>= 0,v3<= 2.5)) v23_inb=np.intersect1d(v2_inb[0],v3_inb[0])
v0123_inb=np.intersect1d(v01_inb,v23_inb)#indices of elements that are in bound for all 4 arrays
only keep inbound elements
simneural=simneural[v0123_inb] v0=v0[v0123_inb] v1=v1[v0123_inb] v2=v2[v0123_inb] v3=v3[v0123_inb]
save to subject_params
subject_params["v0"]=np.append(subject_params["v0"],v0) subject_params["v1"]=np.append(subject_params["v1"],v1) subject_params["v2"]=np.append(subject_params["v2"],v2) subject_params["v3"]=np.append(subject_params["v3"],v3) subject_params["simneural"]=np.append(subject_params["simneural"],simneural) subject_params["subID"]=np.append(subject_params["subID"],np.repeat(i,len(simneural)))
simulate RT and choices
true_values = np.column_stack( [v0,v1,v2,v3, np.repeat([[2.0, 0.0, 1e-3,0.0]], axis=0, repeats=len(simneural))] )
Get mode simulations
race4nba_v = simulator.simulator(true_values, model="race_no_bias_angle_4", n_samples=1)
Random regressor as control
rand_x = np.random.uniform(0, 1, size=len(simneural)) sim_data.append( pd.DataFrame( { "rt": race4nba_v["rts"].flatten(), "response": race4nba_v["choices"].flatten(), "x": np.log(simneural), "y": np.log(1-simneural), "rand_x": np.log(rand_x), "rand_y": np.log(1-rand_x), "subID": i } ) )
make a single dataframe of subject-wise simulated data
sim_data_concat=pd.concat(sim_data)
model_race4nba_v_true = hssm.HSSM( data=sim_data_concat, model='race_no_bias_angle_4', a=2.0, z=0.0, include=[ { "name": "v0", "prior":{"name": "Uniform", "lower": 0, "upper": 2.5}, "formula": "v0 ~ 1 + x + y + (1|subID)", "link": "log", }, { "name": "v1", "prior":{"name": "Uniform", "lower": 0, "upper": 2.5}, "formula": "v1 ~ 1 + x + y + (1|subID)", "link": "log", }, { "name": "v2", "prior":{"name": "Uniform", "lower": 0, "upper": 2.5}, "formula": "v2 ~ 1 + x + y + (1|subID)", "link": "log", }, { "name": "v3", "prior":{"name": "Uniform", "lower": 0, "upper": 2.5}, "formula": "v3 ~ 1 + x + y + (1|subID)", "link": "log", } ], )
Screenshots NA
Additional context Add any other context about the problem here, such as the print out of the model.
— Reply to this email directly, view it on GitHub https://github.com/lnccbrown/HSSM/issues/463, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEJNTY32Z3G4GE2IPZTJDA3ZHTGT5AVCNFSM6AAAAABJMCIDGOVHI2DSMVQWIX3LMV43ASLTON2WKOZSGM2TKMZTGA3DSOI . You are receiving this because you are subscribed to this thread.Message ID: @.***>
Describe the bug When running the same model that worked on 0.2.1, the following error occurred:
Traceback (most recent call last): File "/home/hyang336/PPCPRC/analyses/test_phase/HSSM/Simulations.py", line 199, in
model_race4nba_v_true = hssm.HSSM(
^^^^^^^^^^
File "/home/hyang336/HSSM022_tempENV/lib/python3.11/site-packages/hssm/hssm.py", line 383, in init
self._post_check_data_sanity()
File "/home/hyang336/HSSM022_tempENV/lib/python3.11/site-packages/hssm/hssm.py", line 1685, in _post_check_data_sanity
raise ValueError(
ValueError: Invalid responses found in your dataset: [0, 2, 3]
HSSM version 0.2.2
To Reproduce a0=0 b0=1 intercept0=0.85
Screenshots NA
Additional context Add any other context about the problem here, such as the print out of the model.