option to keep original order of obs_descriptor (i.e., the order of RDM rows and cols)
@@ -14,7 +14,7 @@ from pyrsa.util.matrix import pairwise_contrast_sparse
def calc_rdm(dataset, method='euclidean', descriptor=None, noise=None,
- cv_descriptor=None, prior_lambda=1, prior_weight=0.1):
+ cv_descriptor=None, prior_lambda=1, prior_weight=0.1, sort_desc=True):
"""
calculates an RDM from an input dataset
@@ -59,7 +59,8 @@ def calc_rdm(dataset, method='euclidean', descriptor=None, noise=None,
rdm = calc_rdm_mahalanobis(dataset, descriptor, noise)
elif method == 'crossnobis':
rdm = calc_rdm_crossnobis(dataset, descriptor, noise,
- cv_descriptor)
+ cv_descriptor,
+ sort_desc=sort_desc)
elif method == 'poisson':
rdm = calc_rdm_poisson(dataset, descriptor,
prior_lambda=prior_lambda,
@@ -68,7 +69,8 @@ def calc_rdm(dataset, method='euclidean', descriptor=None, noise=None,
rdm = calc_rdm_poisson_cv(dataset, descriptor,
cv_descriptor=cv_descriptor,
prior_lambda=prior_lambda,
- prior_weight=prior_weight)
+ prior_weight=prior_weight,
+ sort_desc=sort_desc)
else:
raise(NotImplementedError)
return rdm
@@ -171,7 +173,7 @@ def calc_rdm_mahalanobis(dataset, descriptor=None, noise=None):
def calc_rdm_crossnobis(dataset, descriptor, noise=None,
- cv_descriptor=None):
+ cv_descriptor=None, sort_desc=True):
"""
calculates an RDM from an input dataset using Cross-nobis distance
This performs leave one out crossvalidation over the cv_descriptor.
@@ -217,6 +219,7 @@ def calc_rdm_crossnobis(dataset, descriptor, noise=None,
cv_desc = _gen_default_cv_descriptor(dataset, descriptor)
dataset.obs_descriptors['cv_desc'] = cv_desc
cv_descriptor = 'cv_desc'
+ if sort_desc:
dataset.sort_by(descriptor)
cv_folds = np.unique(np.array(dataset.obs_descriptors[cv_descriptor]))
weights = []
@@ -276,7 +279,7 @@ def calc_rdm_crossnobis(dataset, descriptor, noise=None,
def calc_rdm_poisson(dataset, descriptor=None, prior_lambda=1,
- prior_weight=0.1):
+ prior_weight=0.1, sort_desc=True):
"""
calculates an RDM from an input dataset using the symmetrized
KL-divergence assuming a poisson distribution.
@@ -336,6 +339,7 @@ def calc_rdm_poisson_cv(dataset, descriptor=None, prior_lambda=1,
cv_desc = _gen_default_cv_descriptor(dataset, descriptor)
dataset.obs_descriptors['cv_desc'] = cv_desc
cv_descriptor = 'cv_desc'
+ if sort_desc:
dataset.sort_by(descriptor)
cv_folds = np.unique(np.array(dataset.obs_descriptors[cv_descriptor]))
for i_fold in range(len(cv_folds)):
