Tutorial 2 - Using your model#
In this notebook, we show how to use the models discussed in Tutorial 1. Note that we only discuss the necessary inputs here since they are what will be needed in most cases. For full documentation of the following functions and their uses, see the Documentation for Precoded functions.
If you have not done so already, look at Tutorial 1 to learn how to use the model you are interested in. Once you have done this, import PyBEAM’s precoded submodule.
[1]:
# import PyBEAM's precoded submodule
import pybeam.precoded as pbp
We will for this example use the simpleDDM model discussed in Tutorial 1a.
[2]:
# call simpleDDM model
model = pbp.simpleDDM()
As demonstrated in Tutorial 1, we can check which parameters our model uses. We should find that it uses the following four parameters:
'tnd': non-decision time
'w': relative start point
'mu': drift rate
'b': decision threshold location (upper is at b, lower is at -b; separation is 2b)
[3]:
# check which parameters your model uses
model.parameters()
[3]:
['tnd', 'w', 'mu', 'b']
Now that we have defined our model and checked which parameters it uses, we can now use PyBEAM’s main functions.
The first is simulate, a function which simulates data from your model. This requires three inputs:
N_sims (int): Sets number of simulated data points.
model (class): Model class (in this case it will be the simpleDDM).
phi (dict): Contains model parameters. Keys are model parameters, values of keys set the respective
parameter values. In this case, keys are 't_nd', 'w', 'mu', and 'b'.
Two optional inputs are also available for this funtion. These are:
seed (int): sets the random number generator seed.
dt (float): sets the simulation time step (default dt = 0.0001).
This function outputs the following:
(dict) containing two keys, 'rt_upper' and 'rt_lower'. Correspond to simulated reaction time data for the
upper and lower decision thresholds, respectively.
[4]:
# parameters for model
phi = {'tnd' : 0.25, # non-decision time
'w' : 0.5, # relative start point
'mu' : 1.0 , # drift rate
'b' : 0.75} # decision threshold location
# simulate data from the model
rt = pbp.simulate(N_sims = 100, # number of data points to simulate
model = model, # dictionary containing model information
phi = phi) # parameters used to simulate data
rt
[4]:
{'rt_upper': array([0.3927, 0.593 , 0.6824, 0.6374, 0.4187, 0.5223, 1.6286, 0.7293,
0.705 , 0.5184, 0.8433, 1.5621, 0.4723, 1.1496, 0.4048, 0.3759,
1.95 , 0.3884, 0.4122, 0.4249, 0.381 , 0.7034, 0.4485, 0.6932,
1.1674, 0.7885, 0.6222, 0.5114, 1.2133, 0.3283, 0.6566, 0.4966,
0.7804, 0.8639, 0.4298, 1.1579, 0.3209, 1.0558, 0.8261, 0.427 ,
0.6858, 0.4843, 1.9283, 0.3728, 0.8186, 0.487 , 0.467 , 1.0879,
0.8673, 0.5058, 0.3951, 0.9303, 0.6357, 0.4305, 0.5141, 0.5477,
0.5805, 1.0475, 0.9042, 0.7556, 0.4036, 0.5537, 1.0348, 1.2858,
0.3934, 1.2214, 0.419 , 0.8649, 0.4016, 0.5418, 0.3665, 0.635 ,
1.0925, 0.8127, 0.7287, 0.5753, 0.4006, 0.3785, 0.6231, 1.5738]),
'rt_lower': array([0.8989, 1.1257, 0.5579, 0.3219, 0.6665, 0.8706, 0.4653, 0.3307,
0.5298, 1.1274, 1.5193, 1.4173, 0.4244, 0.8172, 0.6073, 0.8609,
0.9728, 0.4611, 0.4576, 1.0662])}
The next function we introduce is likelihood. likelihood takes the input model and calculates its likelihood function (i.e. the model’s predicted rt distribution). It has three required inputs:
model (class): Model class (in this case it will be the simpleDDM).
phi (dict): Contains model parameters. Keys are model parameters, values of keys set the respective
parameter values. In this case, keys are 't_nd', 'w', 'mu', and 'b'.
rt_max (float): Sets max time to solve likleihood function to.
likelihood also has several optional inputs. In general, these should not need to be touched, but they are available in case your model has a difficult to calculate likelihood:
N_tnd (int): Number of integration points for non-decision time distribution. Defualts to 50.
N_mu (int): Number of integration points for drift rate distribution. Defaults to 10.
x_res (str,int): Spatial resolution of solver. Sets number of spatial mesh points in finite difference
grid. Four pre-set options are available: 'default' (101 mesh points), 'high' (151 mesh
points), 'very_high' (251 mesh points), and 'max' (501 mesh points). Can also be set to an
integer value between 101 and 501. Default should be used for nearly all cases.
t_res (str): Temporal resolution of sovler. Four options are available: 'default', 'high', 'very_high',
and 'max'. Default should be used for nearly all cases.
Other optional inputs are available for this function, but they are only necessary in niche applications and are thus discussed in the Precoded functions documentation.
This function outputs the following:
(dict) containing three keys: 'time', 'rt_upper' and 'rt_lower'. 'time' is the time for each point
in the distribution, while 'rt_upper' and 'rt_lower' are the proabiblity for upper and lower threshold
crossings, respectively, for each value in the 'time' array.
[5]:
lh = pbp.likelihood(model = model,
phi = phi,
rt_max = 3.0)
lh
[5]:
{'time': array([0. , 0.0111875, 0.022375 , 0.0335625, 0.04475 , 0.0559375,
0.067125 , 0.0783125, 0.0895 , 0.1006875, 0.111875 , 0.1230625,
0.13425 , 0.1454375, 0.156625 , 0.1678125, 0.179 , 0.1901875,
0.201375 , 0.2125625, 0.22375 , 0.2349375, 0.246125 , 0.2573125,
0.2685 , 0.2796875, 0.290875 , 0.3020625, 0.31325 , 0.3244375,
0.335625 , 0.3468125, 0.358 , 0.3691875, 0.380375 , 0.3915625,
0.40275 , 0.4139375, 0.425125 , 0.4363125, 0.4475 , 0.4586875,
0.469875 , 0.4810625, 0.49225 , 0.5034375, 0.514625 , 0.5258125,
0.537 , 0.5481875, 0.559375 , 0.5705625, 0.58175 , 0.5929375,
0.604125 , 0.6153125, 0.6265 , 0.6376875, 0.648875 , 0.6600625,
0.67125 , 0.6824375, 0.693625 , 0.7048125, 0.716 , 0.7271875,
0.738375 , 0.7495625, 0.76075 , 0.7719375, 0.783125 , 0.7943125,
0.8055 , 0.8166875, 0.827875 , 0.8390625, 0.85025 , 0.8614375,
0.872625 , 0.8838125, 0.895 , 0.9061875, 0.917375 , 0.9285625,
0.93975 , 0.9509375, 0.962125 , 0.9733125, 0.9845 , 0.9956875,
1.006875 , 1.0180625, 1.02925 , 1.0404375, 1.051625 , 1.0628125,
1.074 , 1.0851875, 1.096375 , 1.1075625, 1.11875 , 1.1299375,
1.141125 , 1.1523125, 1.1635 , 1.1746875, 1.185875 , 1.1970625,
1.20825 , 1.2194375, 1.230625 , 1.2418125, 1.253 , 1.2641875,
1.275375 , 1.2865625, 1.29775 , 1.3089375, 1.320125 , 1.3313125,
1.3425 , 1.3536875, 1.364875 , 1.3760625, 1.38725 , 1.3984375,
1.409625 , 1.4208125, 1.432 , 1.4431875, 1.454375 , 1.4655625,
1.47675 , 1.4879375, 1.499125 , 1.5103125, 1.5215 , 1.5326875,
1.543875 , 1.5550625, 1.56625 , 1.5774375, 1.588625 , 1.5998125,
1.611 , 1.6221875, 1.633375 , 1.6445625, 1.65575 , 1.6669375,
1.678125 , 1.6893125, 1.7005 , 1.7116875, 1.722875 , 1.7340625,
1.74525 , 1.7564375, 1.767625 , 1.7788125, 1.79 , 1.8011875,
1.812375 , 1.8235625, 1.83475 , 1.8459375, 1.857125 , 1.8683125,
1.8795 , 1.8906875, 1.901875 , 1.9130625, 1.92425 , 1.9354375,
1.946625 , 1.9578125, 1.969 , 1.9801875, 1.991375 , 2.0025625,
2.01375 , 2.0249375, 2.036125 , 2.0473125, 2.0585 , 2.0696875,
2.080875 , 2.0920625, 2.10325 , 2.1144375, 2.125625 , 2.1368125,
2.148 , 2.1591875, 2.170375 , 2.1815625, 2.19275 , 2.2039375,
2.215125 , 2.2263125, 2.2375 , 2.2486875, 2.259875 , 2.2710625,
2.28225 , 2.2934375, 2.304625 , 2.3158125, 2.327 , 2.3381875,
2.349375 , 2.3605625, 2.37175 , 2.3829375, 2.394125 , 2.4053125,
2.4165 , 2.4276875, 2.438875 , 2.4500625, 2.46125 , 2.4724375,
2.483625 , 2.4948125, 2.506 , 2.5171875, 2.528375 , 2.5395625,
2.55075 , 2.5619375, 2.573125 , 2.5843125, 2.5955 , 2.6066875,
2.617875 , 2.6290625, 2.64025 , 2.6514375, 2.662625 , 2.6738125,
2.685 , 2.6961875, 2.707375 , 2.7185625, 2.72975 , 2.7409375,
2.752125 , 2.7633125, 2.7745 , 2.7856875, 2.796875 , 2.8080625,
2.81925 , 2.8304375, 2.841625 , 2.8528125, 2.864 , 2.8751875,
2.886375 , 2.8975625, 2.90875 , 2.9199375, 2.931125 , 2.9423125,
2.9535 , 2.9646875, 2.975875 , 2.9870625, 2.99825 , 3.0094375]),
'lh_upper': array([1.00000000e-05, 1.00000000e-05, 1.00000000e-05, 1.00000000e-05,
1.00000000e-05, 1.00000000e-05, 1.00000000e-05, 1.00000000e-05,
1.00000000e-05, 1.00000000e-05, 1.00000000e-05, 1.00000000e-05,
1.00000000e-05, 1.00000000e-05, 1.00000000e-05, 1.00000000e-05,
1.00000000e-05, 1.00000000e-05, 1.00000000e-05, 1.00000000e-05,
1.00000000e-05, 1.00000000e-05, 1.00000000e-05, 1.00000000e-05,
5.75865816e-04, 1.58738122e-02, 8.76467710e-02, 2.40602297e-01,
4.52375778e-01, 6.82872349e-01, 9.01356427e-01, 1.09040481e+00,
1.24491768e+00, 1.36499996e+00, 1.45378017e+00, 1.51611461e+00,
1.55661170e+00, 1.57936778e+00, 1.58779559e+00, 1.58478696e+00,
1.57306857e+00, 1.55476852e+00, 1.53117048e+00, 1.50371422e+00,
1.47347189e+00, 1.44120104e+00, 1.40757004e+00, 1.37308891e+00,
1.33814843e+00, 1.30306231e+00, 1.26808986e+00, 1.23340197e+00,
1.19912430e+00, 1.16541881e+00, 1.13233714e+00, 1.09990535e+00,
1.06818990e+00, 1.03725900e+00, 1.00709595e+00, 9.77685836e-01,
9.49033928e-01, 9.21140716e-01, 8.94047048e-01, 8.67728273e-01,
8.42145425e-01, 8.17282963e-01, 7.93127856e-01, 7.69665926e-01,
7.46882129e-01, 7.24760784e-01, 7.03285759e-01, 6.82440634e-01,
6.62208825e-01, 6.42573700e-01, 6.23517308e-01, 6.05023049e-01,
5.87075145e-01, 5.69657903e-01, 5.52755992e-01, 5.36354449e-01,
5.20438688e-01, 5.04994503e-01, 4.90008065e-01, 4.75465921e-01,
4.61354991e-01, 4.47662561e-01, 4.34376279e-01, 4.21484141e-01,
4.08974494e-01, 3.96836018e-01, 3.85057724e-01, 3.73628942e-01,
3.62539317e-01, 3.51778795e-01, 3.41337619e-01, 3.31206318e-01,
3.21375704e-01, 3.11836855e-01, 3.02581117e-01, 2.93600090e-01,
2.84885623e-01, 2.76429806e-01, 2.68224964e-01, 2.60263649e-01,
2.52538634e-01, 2.45042906e-01, 2.37769660e-01, 2.30712293e-01,
2.23864398e-01, 2.17219757e-01, 2.10772339e-01, 2.04516290e-01,
1.98445929e-01, 1.92555745e-01, 1.86840391e-01, 1.81294677e-01,
1.75913568e-01, 1.70692179e-01, 1.65625769e-01, 1.60709737e-01,
1.55939621e-01, 1.51311089e-01, 1.46819939e-01, 1.42462094e-01,
1.38233596e-01, 1.34130607e-01, 1.30149400e-01, 1.26286362e-01,
1.22537986e-01, 1.18900866e-01, 1.15371703e-01, 1.11947290e-01,
1.08624519e-01, 1.05400373e-01, 1.02271925e-01, 9.92363342e-02,
9.62908445e-02, 9.34327814e-02, 9.06595502e-02, 8.79686328e-02,
8.53575860e-02, 8.28240392e-02, 8.03656921e-02, 7.79803125e-02,
7.56657347e-02, 7.34198572e-02, 7.12406409e-02, 6.91261072e-02,
6.70743361e-02, 6.50834647e-02, 6.31516856e-02, 6.12772447e-02,
5.94584401e-02, 5.76936205e-02, 5.59811835e-02, 5.43195743e-02,
5.27072843e-02, 5.11428496e-02, 4.96248497e-02, 4.81519065e-02,
4.67226825e-02, 4.53358801e-02, 4.39902402e-02, 4.26845410e-02,
4.14175970e-02, 4.01882579e-02, 3.89954075e-02, 3.78379627e-02,
3.67148727e-02, 3.56251178e-02, 3.45677085e-02, 3.35416848e-02,
3.25461151e-02, 3.15800955e-02, 3.06427488e-02, 2.97332240e-02,
2.88506954e-02, 2.79943615e-02, 2.71634451e-02, 2.63571915e-02,
2.55748688e-02, 2.48157666e-02, 2.40791958e-02, 2.33644876e-02,
2.26709930e-02, 2.19980824e-02, 2.13451449e-02, 2.07115876e-02,
2.00968352e-02, 1.95003297e-02, 1.89215294e-02, 1.83599088e-02,
1.78149579e-02, 1.72861821e-02, 1.67731011e-02, 1.62752492e-02,
1.57921743e-02, 1.53234379e-02, 1.48686142e-02, 1.44272905e-02,
1.39990659e-02, 1.35835517e-02, 1.31803706e-02, 1.27891566e-02,
1.24095544e-02, 1.20412194e-02, 1.16838172e-02, 1.13370232e-02,
1.10005226e-02, 1.06740098e-02, 1.03571885e-02, 1.00497709e-02,
9.75147800e-03, 9.46203887e-03, 9.18119074e-03, 8.90867862e-03,
8.64425509e-03, 8.38768006e-03, 8.13872059e-03, 7.89715062e-03,
7.66275082e-03, 7.43530838e-03, 7.21461678e-03, 7.00047566e-03,
6.79269058e-03, 6.59107289e-03, 6.39543953e-03, 6.20561287e-03,
6.02142056e-03, 5.84269537e-03, 5.66927502e-03, 5.50100206e-03,
5.33772371e-03, 5.17929171e-03, 5.02556222e-03, 4.87639567e-03,
4.73165661e-03, 4.59121363e-03, 4.45493922e-03, 4.32270965e-03,
4.19440486e-03, 4.06990836e-03, 3.94910710e-03, 3.83189142e-03,
3.71815488e-03, 3.60779423e-03, 3.50070924e-03, 3.39680271e-03,
3.29598029e-03, 3.19815043e-03, 3.10322432e-03, 3.01111576e-03,
2.92174113e-03, 2.83501928e-03, 2.75087147e-03, 2.66922130e-03,
2.58999463e-03, 2.51311953e-03, 2.43852621e-03, 2.36614694e-03,
2.29591599e-03, 2.22776961e-03, 2.16164592e-03, 2.09748488e-03,
2.03522825e-03, 1.97481949e-03, 1.91620375e-03, 1.85932782e-03,
1.80414006e-03, 1.75059036e-03]),
'lh_lower': array([1.00000000e-05, 1.00000000e-05, 1.00000000e-05, 1.00000000e-05,
1.00000000e-05, 1.00000000e-05, 1.00000000e-05, 1.00000000e-05,
1.00000000e-05, 1.00000000e-05, 1.00000000e-05, 1.00000000e-05,
1.00000000e-05, 1.00000000e-05, 1.00000000e-05, 1.00000000e-05,
1.00000000e-05, 1.00000000e-05, 1.00000000e-05, 1.00000000e-05,
1.00000000e-05, 1.00000000e-05, 1.00000000e-05, 1.00000000e-05,
1.30955262e-04, 3.53883482e-03, 1.95465558e-02, 5.36676249e-02,
1.00915041e-01, 1.52342956e-01, 2.01092552e-01, 2.43275342e-01,
2.77752792e-01, 3.04547959e-01, 3.24358727e-01, 3.38268599e-01,
3.47305812e-01, 3.52384377e-01, 3.54265783e-01, 3.53595290e-01,
3.50981316e-01, 3.46898717e-01, 3.41633919e-01, 3.35508192e-01,
3.28760773e-01, 3.21560692e-01, 3.14057092e-01, 3.06363780e-01,
2.98567949e-01, 2.90739600e-01, 2.82936597e-01, 2.75197069e-01,
2.67549061e-01, 2.60028709e-01, 2.52647539e-01, 2.45411363e-01,
2.38335011e-01, 2.31433707e-01, 2.24703723e-01, 2.18141732e-01,
2.11748911e-01, 2.05525369e-01, 1.99480220e-01, 1.93607965e-01,
1.87899909e-01, 1.82352586e-01, 1.76963088e-01, 1.71728252e-01,
1.66644720e-01, 1.61708995e-01, 1.56917478e-01, 1.52266503e-01,
1.47752372e-01, 1.43371373e-01, 1.39119501e-01, 1.34993053e-01,
1.30988507e-01, 1.27102364e-01, 1.23331201e-01, 1.19671680e-01,
1.16120548e-01, 1.12674633e-01, 1.09330851e-01, 1.06086201e-01,
1.02937763e-01, 9.98827009e-02, 9.69182586e-02, 9.40417583e-02,
9.12505994e-02, 8.85422564e-02, 8.59142773e-02, 8.33642817e-02,
8.08899588e-02, 7.84890656e-02, 7.61594250e-02, 7.38989241e-02,
7.17055123e-02, 6.95771995e-02, 6.75120545e-02, 6.55082031e-02,
6.35638267e-02, 6.16771605e-02, 5.98464919e-02, 5.80701592e-02,
5.63465499e-02, 5.46740991e-02, 5.30512887e-02, 5.14766454e-02,
4.99487395e-02, 4.84661840e-02, 4.70276327e-02, 4.56317798e-02,
4.42773577e-02, 4.29631369e-02, 4.16879241e-02, 4.04505616e-02,
3.92499258e-02, 3.80849268e-02, 3.69545067e-02, 3.58576392e-02,
3.47933284e-02, 3.37606080e-02, 3.27585404e-02, 3.17862157e-02,
3.08427511e-02, 2.99272900e-02, 2.90390012e-02, 2.81770782e-02,
2.73407384e-02, 2.65292225e-02, 2.57417936e-02, 2.49777369e-02,
2.42363585e-02, 2.35169855e-02, 2.28189645e-02, 2.21416619e-02,
2.14844627e-02, 2.08467702e-02, 2.02280055e-02, 1.96276066e-02,
1.90450285e-02, 1.84797422e-02, 1.79312346e-02, 1.73990074e-02,
1.68825776e-02, 1.63814763e-02, 1.58952484e-02, 1.54234526e-02,
1.49656604e-02, 1.45214561e-02, 1.40904366e-02, 1.36722104e-02,
1.32663977e-02, 1.28726303e-02, 1.24905505e-02, 1.21198114e-02,
1.17600764e-02, 1.14110189e-02, 1.10723220e-02, 1.07436781e-02,
1.04247890e-02, 1.01153649e-02, 9.81512503e-03, 9.52379675e-03,
9.24111555e-03, 8.96682477e-03, 8.70067537e-03, 8.44242570e-03,
8.19184129e-03, 7.94869461e-03, 7.71276491e-03, 7.48383797e-03,
7.26170594e-03, 7.04616714e-03, 6.83702587e-03, 6.63409223e-03,
6.43718199e-03, 6.24611635e-03, 6.06072183e-03, 5.88083012e-03,
5.70627787e-03, 5.53690661e-03, 5.37256255e-03, 5.21309649e-03,
5.05836362e-03, 4.90822347e-03, 4.76253971e-03, 4.62118007e-03,
4.48401621e-03, 4.35092359e-03, 4.22178137e-03, 4.09647228e-03,
3.97488257e-03, 3.85690183e-03, 3.74242295e-03, 3.63134198e-03,
3.52355806e-03, 3.41897334e-03, 3.31749286e-03, 3.21902448e-03,
3.12347879e-03, 3.03076905e-03, 2.94081108e-03, 2.85352320e-03,
2.76882616e-03, 2.68664307e-03, 2.60689929e-03, 2.52952244e-03,
2.45444225e-03, 2.38159056e-03, 2.31090123e-03, 2.24231006e-03,
2.17575479e-03, 2.11117498e-03, 2.04851200e-03, 1.98770896e-03,
1.92871064e-03, 1.87146349e-03, 1.81591552e-03, 1.76201631e-03,
1.70971690e-03, 1.65896983e-03, 1.60972901e-03, 1.56194973e-03,
1.51558862e-03, 1.47060357e-03, 1.42695376e-03, 1.38459953e-03,
1.34350245e-03, 1.30362520e-03, 1.26493156e-03, 1.22738641e-03,
1.19095566e-03, 1.15560623e-03, 1.12130603e-03, 1.08802391e-03,
1.05572966e-03, 1.02439395e-03, 9.93988331e-04, 9.64485201e-04,
9.35857770e-04, 9.08080046e-04, 8.81126808e-04, 8.54973585e-04,
8.29596630e-04, 8.04972903e-04, 7.81080047e-04, 7.57896368e-04,
7.35400817e-04, 7.13572969e-04, 6.92393006e-04, 6.71841698e-04,
6.51900384e-04, 6.32550960e-04, 6.13775857e-04, 5.95558029e-04,
5.77880934e-04, 5.60728523e-04, 5.44085222e-04, 5.27935921e-04,
5.12265956e-04, 4.97061101e-04, 4.82307549e-04, 4.67991906e-04,
4.54101173e-04, 4.40622739e-04, 4.27544366e-04, 4.14854180e-04,
4.02540659e-04, 3.90592622e-04])}
The next function we introduce is loglikelihood. loglikelihood takes the input model and calculates the loglikelihood of input data. It has three required inputs:
model (class): Model class (in this case it will be the simpleDDM).
phi (dict): Contains model parameters. Keys are model parameters, values of keys set the respective
parameter values. In this case, keys are 't_nd', 'w', 'mu', and 'b'.
rt (dict): Dictionary containing rt data. Requires two keys, 'rt_upper' and 'rt_lower', whose values
are python lists/numpy arrays containing the rt data for the upper and lower thresholds,
respectively.
loglikeliood also has several optional inputs. In general, these should not need to be touched, but they are available in case your model has a difficult to calculate likelihood:
pointwise (True/False): If False, outputs the total loglikelihood. If True, outputs arrays containing
the loglikelihood of each individual point. Defaults to False.
N_tnd (int): Number of integration points for non-decision time distribution. Defualts to 50.
N_mu (int): Number of integration points for drift rate distribution. Defaults to 10.
x_res (str,int): Spatial resolution of solver. Sets number of spatial mesh points in finite difference
grid. Four pre-set options are available: 'default' (101 mesh points), 'high' (151 mesh
points), 'very_high' (251 mesh points), and 'max' (501 mesh points). Can also be set to an
integer value between 101 and 501. Default should be used for nearly all cases.
t_res (str): Temporal resolution of sovler. Four options are available: 'default', 'high', 'very_high',
and 'max'. Default should be used for nearly all cases.
Other optional inputs are available for this function, but they are only necessary in niche applications and are thus discussed in the Precoded functions documentation.
This function outputs:
if pointwise = False (default behavior):
(float) corresponding to the summed loglikelihood of all input data points.
if pointwise = True (default behavior):
(dict) with two keys, 'llh_upper' and 'llh_lower'. Values contain arrays with the loglikelihood
of each indiviudal data point for the upper and lower thresholds, respectively.
[6]:
llh = pbp.loglikelihood(model = model,
phi = phi,
rt = rt)
llh
[6]:
-61.90619558910997
[7]:
llh_pointwise = pbp.loglikelihood(model = model,
phi = phi,
rt = rt,
pointwise = True)
llh_pointwise
[7]:
{'llh_upper': array([ 0.41886308, 0.15292192, -0.08204097, 0.03734768, 0.45929366,
0.32491632, -2.62872024, -0.20736638, -0.14237091, 0.33356449,
-0.5137885 , -2.44962268, 0.42213805, -1.33867084, 0.44518668,
0.34943647, -3.49435377, 0.40446048, 0.4547844 , 0.46223988,
0.3765597 , -0.13805452, 0.45198782, -0.11084631, -1.38659201,
-0.36633462, 0.0773128 , 0.3487288 , -1.51020349, -0.27667055,
-0.01329987, 0.37906919, -0.34458186, -0.56927146, 0.46155451,
-1.36099527, -0.49431423, -1.08602156, -0.46754142, 0.46202901,
-0.09102216, 0.40210114, -3.43590047, 0.33193879, -0.4473564 ,
0.39720698, 0.42998521, -1.17249763, -0.5783893 , 0.36053683,
0.4245615 , -0.74807995, 0.04186528, 0.46143585, 0.34298544,
0.26588974, 0.18478037, -1.06366771, -0.67778928, -0.27790296,
0.44362157, 0.25140448, -1.02945625, -1.70554882, 0.42052848,
-1.53206604, 0.45943642, -0.57194456, 0.4398336 , 0.27997348,
0.28979487, 0.04371955, -1.18486645, -0.43144138, -0.20577366,
0.19793783, 0.43749918, 0.36387949, 0.07494843, -2.4811402 ]),
'llh_lower': array([-2.16352522, -2.77432183, -1.25890298, -1.96127955, -1.5396172 ,
-2.08736241, -1.0677333 , -1.71684588, -1.19209313, -2.77892739,
-3.83442792, -3.55968821, -1.03805207, -1.94367648, -1.3839215 ,
-2.06129462, -2.36261612, -1.06200054, -1.05757907, -2.61408492])}
PyBEAM also contains a plotting utility, plot_rt. It generates a figure which can plot just the likelihood function or the likelihood function overlaying rt data. It has three required inputs:
model (class): Model class (in this case it will be the simpleDDM).
phi (dict): Contains model parameters. Keys are model parameters, values of keys set the respective
parameter values. In this case, keys are 't_nd', 'w', 'mu', and 'b'.
rt_max (float): Sets max time to solve likleihood function to.
If a histogram of rt data is desired on the figure, the following optional input can be used:
rt (dict): Dictionary containing rt data. Requires two keys, 'rt_upper' and 'rt_lower', whose values
are python lists/numpy arrays containing the rt data for the upper and lower thresholds,
respectively.
The histogram is set to have 25 bins by default, but can be set by the user with:
bins (int): Number of histogram bins for the rt data.
plot_rt also has several optional inputs. In general, these should not need to be touched, but they are available in case your model has a difficult to calculate likelihood:
N_tnd (int): Number of integration points for non-decision time distribution. Defualts to 50.
N_mu (int): Number of integration points for drift rate distribution. Defaults to 10.
x_res (str,int): Spatial resolution of solver. Sets number of spatial mesh points in finite difference
grid. Four pre-set options are available: 'default' (101 mesh points), 'high' (151 mesh
points), 'very_high' (251 mesh points), and 'max' (501 mesh points). Can also be set to an
integer value between 101 and 501. Default should be used for nearly all cases.
t_res (str): Temporal resolution of sovler. Four options are available: 'default', 'high', 'very_high',
and 'max'. Default should be used for nearly all cases.
This functions outputs:
(fig) containing the model likelihood function and (optionally) a histogram containing the rt data
(negative times are the lower threshold crossing data points, positive times are the upper threshold
crossing data points).
[8]:
# plot data and model likelihood function
fig = pbp.plot_rt(model = model, # dictionary containing model information
phi = phi, # parameters used for model rt distribution
rt_max = 3.0, # dictionary of simulated rt data
rt = rt); # dictionary of simulated rt data