[FEAT] enable n-d MDS in vis
@@ -15,8 +15,6 @@ from sklearn.manifold import MDS
from pyrsa.util import Weighted_MDS
sd = np.random.RandomState(seed=1)
-mds_emb = MDS(n_components=2, random_state=sd, dissimilarity="precomputed")
-
def rdm_dimension_reduction(rdms, func, dim=2, weight=None):
""" dimension reduction of RDMs class
@@ -31,13 +29,13 @@ def rdm_dimension_reduction(rdms, func, dim=2, weight=None):
"""
rdmm = rdms.get_matrices()
- drs = np.ndarray((rdms.n_rdm, rdms.n_cond, 2))
+ drs = np.ndarray((rdms.n_rdm, rdms.n_cond, dim))
for i in np.arange(rdms.n_rdm):
drs[i, :, :] = func.fit_transform(rdmm[i, :, :])
return drs
-def mds(rdms):
+def mds(rdms, dim=2):
""" multi-dimensional scaling of RDMs class
Args:
@@ -47,10 +45,13 @@ def mds(rdms):
(numpy.ndarray): an MDS embedding
"""
+ mds_emb = MDS(n_components=dim,
+ random_state=sd,
+ dissimilarity="precomputed")
return rdm_dimension_reduction(rdms, mds_emb)
-def weighted_mds(rdms):
+def weighted_mds(rdms, dim=2, weight=None):
""" multi-dimensional scaling of RDMs class
Args:
@@ -60,4 +61,7 @@ def weighted_mds(rdms):
(numpy.ndarray): an MDS embedding
"""
- return rdm_dimension_reduction(rdms, mds_emb)
\ No newline at end of file
+ wmds_emb = Weighted_MDS(n_components=dim,
+ random_state=sd,
+ dissimilarity="precomputed")
+ return rdm_dimension_reduction(rdms, wmds_emb)
\ No newline at end of file
