[pymvpa] Dataset with multidimensional feature vector per voxel
Yaroslav Halchenko
debian at onerussian.com
Thu Nov 5 14:52:55 UTC 2015
On Thu, 05 Nov 2015, Ulrike Kuhl wrote:
> Thanks again for your super quick and super helpful reply!
> There is still one thing that I don't quite get at the moment:
> As expected, 'dsall' is a numpy.ndarray of dimensions 1*(numberVoxels*numberSubjects*numberParameters) - so just a really long vector.
> Since this is 'only' a vector, it does not have any attributes or other information associated with it. This information is still contained in 'dss', which is a list of size (numberSubjects*numberParameters) containing the respective datasets.
> I don't see right now how to bridge this information to the 'dsall'-array. After all, 'sphere_searchlight()' should also be called with a dataset, using this dataset's coordinates to determine the local neighborhoods, right?
> So I guess I still need the 'glue' to get it all together... ;-)
> Can you give me a hint on that?
my bad -- I overlooked this by subject construct... you need to vstack those
across subjects while hstacking features within subject
sub_list = [list of subjects]
param_list = [list of parameters]
dss = []
for sub_index, sub in enumerate(sub_list):
# yoh: will contain datasets for different features for the same subject
dss_subj = []
for suf_index, suf in enumerate(param_list):
ds = fmri_dataset('/path/to/image/file',mask='/path/to/mask/file')
# yoh: no need to broadcast -- should do automagically
ds.fa['modality'] = [suf] # for each feature, set the modality attribute
ds.fa['modality_index'] = [suf_index] # this as numeric might come handy for searchlights later
dss_subj.append(ds)
ds_subj = hstack(dss_subj)
if sub.startswith('L'):
learn = 1
elif sub.startswith('N'):
learn = 0
else:
# yoh: make it explicit, otherwise you would assign previous learn to next one not L or N
raise ValueError("Do not know what to do with %s" % sub)
# yoh: seems it was incorrectly indented into elif
ds_subj.sa['targets'] = [learn]
ds_subj.sa['chunks'] = [sub_index]
dss.append(ds_subj)
dsall = vstack(dss)
####################################
> Cheers,
> Ulrike
> ----- Original Message -----
> From: "Yaroslav Halchenko" <debian at onerussian.com>
> To: "pkg-exppsy-pymvpa" <pkg-exppsy-pymvpa at lists.alioth.debian.org>
> Sent: Thursday, 5 November, 2015 15:14:24
> Subject: Re: [pymvpa] Dataset with multidimensional feature vector per voxel
> On Thu, 05 Nov 2015, Ulrike Kuhl wrote:
> > Dear Yaroslav,
> > thanks a lot for your reply.
> > With your snipped it was really easy for me to set up the matrix as you described it. :-)
> > For those interested, this is the code that works for me:
> > sub_list = [list of subjects]
> > param_list = [list of parameters]
> > dss = []
> > for sub_index, sub in enumerate(sub_list):
> > for suf_index, suf in enumerate(param_list):
> > ds = fmri_dataset('/path/to/image/file',mask='/path/to/mask/file')
> > ds.fa['modality'] = [suf] * ds.nfeatures # for each feature, set the modality attribute
> > ds.fa['modality_index'] = [suf_index] * ds.nfeatures # this as numeric might come handy for searchlights later
> > if sub.startswith('L'):
> > learn = 1
> > elif sub.startswith('N'):
> > learn = 0
> > ds.sa['targets'] = [learn]
> > ds.sa['chunks'] = [sub_index]
> > dss.append(ds)
> > dsall = hstack(dss)
> Here is my tune up with # yoh: comments
> sub_list = [list of subjects]
> param_list = [list of parameters]
> dss = []
> for sub_index, sub in enumerate(sub_list):
> for suf_index, suf in enumerate(param_list):
> ds = fmri_dataset('/path/to/image/file',mask='/path/to/mask/file')
> # yoh: no need to broadcast -- should do automagically
> ds.fa['modality'] = [suf] # for each feature, set the modality attribute
> ds.fa['modality_index'] = [suf_index] # this as numeric might come handy for searchlights later
> if sub.startswith('L'):
> learn = 1
> elif sub.startswith('N'):
> learn = 0
> else:
> # yoh: make it explicit, otherwise you would assign previous learn to next one not L or N
> raise ValueError("Do not know what to do with %s" % sub)
> # yoh: seems it was incorrectly indented into elif
> ds.sa['targets'] = [learn]
> ds.sa['chunks'] = [sub_index]
> dss.append(ds)
> dsall = hstack(dss)
> cheers
--
Yaroslav O. Halchenko
Center for Open Neuroscience http://centerforopenneuroscience.org
Dartmouth College, 419 Moore Hall, Hinman Box 6207, Hanover, NH 03755
Phone: +1 (603) 646-9834 Fax: +1 (603) 646-1419
WWW: http://www.linkedin.com/in/yarik
More information about the Pkg-ExpPsy-PyMVPA
mailing list