A short demo of how easy you can fit DDM models using fastdm and Python, on multiple cores
import fastdm
import pandas
%load_ext autoreload
%autoreload 2
load in data
data = pandas.load('/home/gdholla1/data/tdcs/data/leiden/leiden.pandas')
/usr/local/lib/python2.7/dist-packages/pandas/core/common.py:2769: FutureWarning: load is deprecated, use read_pickle warnings.warn("load is deprecated, use read_pickle", FutureWarning)
Set up the model. We feed in:
model = fastdm.FastDM(data,
depends_on={'a':['acc_spd', 'stimulation'],
't0':['acc_spd', 'stimulation'],},
method='ml')
We fit using 10 CPU cores at the same time
model.fit(nproc=10)
Running fast-dm on experiment_2.ctl Running fast-dm on experiment_1.ctl Running fast-dm on experiment_4.ctl Running fast-dm on experiment_7.ctl Running fast-dm on experiment_5.ctl Running fast-dm on experiment_3.ctl Running fast-dm on experiment_6.ctl
Now we can extract a FastDMResult-object
pars = model.get_parameters()
/usr/local/lib/python2.7/dist-packages/pandas/io/parsers.py:615: ParserWarning: Falling back to the 'python' engine because the 'c' engine does not support regex separators; you can avoid this warning by specifying engine='python'. ParserWarning)
That has a dataframe parameters as an attribute
pars.parameters
a_acc_anodal | a_acc_sham | a_spd_anodal | a_spd_sham | d | fit | method | penalty | st0 | sv | szr | t0_acc_anodal | t0_acc_sham | t0_spd_anodal | t0_spd_sham | time | v | subj_idx | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
subj_idx | ||||||||||||||||||
2 | NaN | 1.2304 | NaN | 0.8493 | -0.0036 | 0.3139 | KS | 0 | 0.1019 | 0.4961 | 0.4870 | NaN | 0.4718 | NaN | 0.4259 | 11.58 | 1.4959 | 2 |
1 | 2.0622 | NaN | 1.0335 | NaN | 0.0385 | 0.1232 | KS | 0 | 0.0786 | 1.0405 | 0.3692 | 0.4299 | NaN | 0.3931 | NaN | 27.44 | 2.6697 | 1 |
4 | NaN | 0.8207 | NaN | 0.7250 | -0.0145 | 0.4445 | KS | 0 | 0.1906 | 0.6474 | 0.3718 | NaN | 0.3533 | NaN | 0.3469 | 6.93 | 0.1914 | 4 |
7 | 1.1676 | NaN | 1.1529 | NaN | -0.0145 | 0.1342 | KS | 0 | 0.1796 | 0.8161 | 0.3894 | 0.2723 | NaN | 0.2697 | NaN | 22.65 | 0.4535 | 7 |
5 | 1.5793 | NaN | 0.8046 | NaN | 0.0079 | 0.4626 | KS | 0 | 0.1140 | 0.5652 | 0.4924 | 0.5314 | NaN | 0.4500 | NaN | 10.56 | 2.0744 | 5 |
3 | 1.2111 | NaN | 0.7283 | NaN | -0.0202 | 0.8502 | KS | 0 | 0.2516 | 1.0173 | 0.1926 | 0.5259 | NaN | 0.3912 | NaN | 17.28 | 0.3991 | 3 |
6 | NaN | 0.7969 | NaN | 0.6579 | -0.0094 | 0.0999 | KS | 0 | 0.1201 | 1.2397 | 0.3093 | NaN | 0.3737 | NaN | 0.3776 | 6.58 | 3.0034 | 6 |
You can also make a 'melted' dataframe for a single parameter
p = pars.melted_parameters('t0')
p
subj_idx | t0 | acc_spd | stimulation | |
---|---|---|---|---|
1 | 1 | 0.4299 | acc | anodal |
3 | 7 | 0.2723 | acc | anodal |
4 | 5 | 0.5314 | acc | anodal |
5 | 3 | 0.5259 | acc | anodal |
7 | 2 | 0.4718 | acc | sham |
9 | 4 | 0.3533 | acc | sham |
13 | 6 | 0.3737 | acc | sham |
15 | 1 | 0.3931 | spd | anodal |
17 | 7 | 0.2697 | spd | anodal |
18 | 5 | 0.4500 | spd | anodal |
19 | 3 | 0.3912 | spd | anodal |
21 | 2 | 0.4259 | spd | sham |
23 | 4 | 0.3469 | spd | sham |
27 | 6 | 0.3776 | spd | sham |
Let's make some nice plots using seaborn
import seaborn as sns
p = pars.melted_parameters('t0')
sns.factorplot('acc_spd', 't0', hue='stimulation', data=p, units='subj_idx',)
<seaborn.axisgrid.FacetGrid at 0x48e6c90>
p = pars.melted_parameters('a')
sns.factorplot('stimulation', 'a', hue='acc_spd', data=p, units='subj_idx',)
<seaborn.axisgrid.FacetGrid at 0x6f01490>