Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

rsm is changed to handle dset_metric

& hyperalignment measure can return full projection matrix if asked for.
  • Loading branch information...
commit 1a6a299c48fc7a5e557203bd8e55348b07d40652 1 parent c844baf
@swaroopgj authored
Showing with 18 additions and 8 deletions.
  1. +10 −5 mvpa2/measures/hyperalignment.py
  2. +8 −3 mvpa2/measures/rsm.py
View
15 mvpa2/measures/hyperalignment.py
@@ -10,12 +10,14 @@
class HyperalignmentMeasure(Measure):
is_trained=True
def __init__(self, ndatasets=11, scale=0.0, index_attr='index',
- zscore_common=True, combiner1=None, combiner2=None, **kwargs):
+ zscore_common=True, combiner1=None, combiner2=None, rsa=True, full_matrix=False, **kwargs):
Measure.__init__(self, **kwargs)
self.ndatasets = ndatasets
self.scale = scale
self._index_attr = index_attr
self.zscore_common = zscore_common
+ self.rsa = rsa
+ self.full_matrix = full_matrix
if combiner1 is None:
combiner1 = lambda x,y: 0.5*(x+y)
if combiner2 is None:
@@ -24,7 +26,10 @@ def __init__(self, ndatasets=11, scale=0.0, index_attr='index',
self.combiner2 = combiner2
def __call__(self, dataset):
- # create the dissimilarity matrix for the data in the input dataset
+ # compute rsm if requested
+ if self.rsa:
+ rsm = RSMMeasure(dset_metric=None, nsubjs=self.ndatasets, compare_ave=True, k=1)
+ bsc_rsm = np.mean(rsm(dataset))
ds = []
nsamples = dataset.nsamples/self.ndatasets
seed_index = np.where(dataset.fa.roi_seed)
@@ -39,8 +44,9 @@ def __call__(self, dataset):
hyper = Hyperalignment(zscore_common=self.zscore_common, combiner1=self.combiner1,
combiner2=self.combiner2, ref_ds = ref_ds)
mappers = hyper(datasets=ds)
- # Extract only the row/column corresponding to the center voxel
- mappers = [ StaticProjectionMapper(proj=np.asarray([np.squeeze(m.proj[:,seed_index])]).T) for m in mappers]
+ # Extract only the row/column corresponding to the center voxel if full_matrix is False
+ if not self.full_matrix:
+ mappers = [ StaticProjectionMapper(proj=np.asarray([np.squeeze(m.proj[:,seed_index])]).T) for m in mappers]
break
except LinAlgError:
print "SVD didn't converge. Trying with a new reference: %i" %(ref_ds+1)
@@ -54,7 +60,6 @@ def __call__(self, dataset):
else:
print "We are Screwed..."
-
#return Dataset(samples=np.asanyarray([{'proj':mapper,'fsel':StaticFeatureSelection(dataset.fa[self._index_attr].value)} for mapper in mappers]))
return Dataset(samples=np.asanyarray([{'proj': ChainMapper([StaticFeatureSelection(dataset.fa[self._index_attr].value), mapper])} for mapper in mappers]))
# To return such that chain mappers are not combined across feature-dimension (which is apparently dim 2)
View
11 mvpa2/measures/rsm.py
@@ -21,7 +21,7 @@
class RSMMeasure(Measure):
"""RSMMeasure creates a DatasetMeasure object
where metric can be one of 'euclidean', 'spearman', 'pearson'
- or 'confusion' and nsubjs has to be number of subject
+ or 'confusion' and nsubjs has to be number of subjects
and compare_ave flag determines whether to correlate with
average of all other subjects or just one-to-one
k should be 0 to n 0-to use DSM including diagonal
@@ -30,7 +30,6 @@ class RSMMeasure(Measure):
def __init__(self, dset_metric, nsubjs, compare_ave, k, **kwargs):
Measure.__init__(self, **kwargs)
- #self.dsmatrix = dsmatrix
self.dset_metric = dset_metric
self.dset_dsm = []
self.nsubjs = nsubjs
@@ -43,8 +42,14 @@ def __call__(self, dataset):
rsm_all = []
nsubjs = self.nsubjs
# create the dissimilarity matrix for each subject's data in the input dataset
+ ''' TODO: How to handle Nan? should we uncomment the workarounds?
+ '''
for i in xrange(nsubjs):
- self.dset_dsm = np.corrcoef(dataset.samples[i*dataset.nsamples/nsubjs:((i+1)*dataset.nsamples/nsubjs),:])
+ if self.dset_metric == 'pearson':
+ self.dset_dsm = np.corrcoef(dataset.samples[i*dataset.nsamples/nsubjs:((i+1)*dataset.nsamples/nsubjs),:])
+ else:
+ self.dset_dsm = DSMatrix(dataset.samples[i*dataset.nsamples/nsubjs:((i+1)*dataset.nsamples/nsubjs),:], self.dset_metric)
+ self.dset_dsm = self.dset_dsm.full_matrix
orig_dsmatrix = copy.deepcopy(np.matrix(self.dset_dsm))
#orig_dsmatrix[np.isnan(orig_dsmatrix)] = 0
#orig_dsmatrix[orig_dsmatrix == 0] = -2
Please sign in to comment.
Something went wrong with that request. Please try again.