fixing duplicating descriptor bug
@@ -7,6 +7,7 @@ Calculation of RDMs from datasets
from collections.abc import Iterable
import numpy as np
+from copy import deepcopy
from pyrsa.rdm.rdms import RDMs
from pyrsa.rdm.rdms import concat
from pyrsa.data import average_dataset_by
@@ -71,8 +72,6 @@ def calc_rdm(dataset, method='euclidean', descriptor=None, noise=None,
prior_weight=prior_weight)
else:
raise(NotImplementedError)
- rdm.rdm_descriptors = dataset.descriptors
- rdm.rdm_descriptors['index'] = np.array([0])
return rdm
@@ -162,7 +161,7 @@ def calc_rdm_euclid(dataset, descriptor=None):
rdm = np.einsum('ij,ij->i', diff, diff) / measurements.shape[1]
rdm = RDMs(dissimilarities=np.array([rdm]),
dissimilarity_measure='euclidean',
- descriptors=dataset.descriptors)
+ rdm_descriptors=deepcopy(dataset.descriptors))
rdm.pattern_descriptors[descriptor] = desc
return rdm
@@ -190,7 +189,7 @@ def calc_rdm_correlation(dataset, descriptor=None):
rdm = 1 - np.einsum('ik,jk', ma, ma)
rdm = RDMs(dissimilarities=np.array([rdm]),
dissimilarity_measure='correlation',
- descriptors=dataset.descriptors)
+ rdm_descriptors=deepcopy(dataset.descriptors))
rdm.pattern_descriptors[descriptor] = desc
return rdm
@@ -229,7 +228,7 @@ def calc_rdm_mahalanobis(dataset, descriptor=None, noise=None):
rdm = np.einsum('ij,ij->i', diff, diff2) / measurements.shape[1]
rdm = RDMs(dissimilarities=np.array([rdm]),
dissimilarity_measure='Mahalanobis',
- descriptors=dataset.descriptors)
+ rdm_descriptors=deepcopy(dataset.descriptors))
rdm.pattern_descriptors[descriptor] = desc
rdm.descriptors['noise'] = noise
return rdm
@@ -332,7 +331,7 @@ def calc_rdm_crossnobis(dataset, descriptor, noise=None,
rdm = np.einsum('ij->j', rdms)
rdm = RDMs(dissimilarities=np.array([rdm]),
dissimilarity_measure='crossnobis',
- descriptors=dataset.descriptors)
+ rdm_descriptors=deepcopy(dataset.descriptors))
_, desc, _ = average_dataset_by(dataset, descriptor)
rdm.pattern_descriptors[descriptor] = desc
rdm.descriptors['noise'] = noise
@@ -367,7 +366,7 @@ def calc_rdm_poisson(dataset, descriptor=None, prior_lambda=1,
rdm = np.einsum('ij,ij->i', diff, diff_log) / measurements.shape[1]
rdm = RDMs(dissimilarities=np.array([rdm]),
dissimilarity_measure='poisson',
- descriptors=dataset.descriptors)
+ rdm_descriptors=deepcopy(dataset.descriptors))
rdm.pattern_descriptors[descriptor] = desc
return rdm
@@ -423,7 +422,7 @@ def calc_rdm_poisson_cv(dataset, descriptor=None, prior_lambda=1,
/ measurements_train.shape[1]
rdm = RDMs(dissimilarities=np.array([rdm]),
dissimilarity_measure='poisson_cv',
- descriptors=dataset.descriptors)
+ rdm_descriptors=deepcopy(dataset.descriptors))
_, desc, _ = average_dataset_by(dataset, descriptor)
rdm.pattern_descriptors[descriptor] = desc
return rdm
