1def doIt(X, method, ncomponents, nneighbors, njobs, rstate, params):
9 for mod
in [
"numpy",
"scipy",
"sklearn"]:
10 if importlib.util.find_spec(mod)
is None:
12 print(
"[DimensionReduction] Python error: " + mod +
" module not found.")
18 from sklearn
import manifold
19 from sklearn
import decomposition
21 from sys
import platform
23 if platform ==
"darwin":
26 sklearn.utils.parallel_backend(
"threading")
34 if seParams[2] ==
"None":
35 se = manifold.SpectralEmbedding(
36 n_components=ncomponents,
40 n_neighbors=nneighbors,
44 se = manifold.SpectralEmbedding(
45 n_components=ncomponents,
48 eigen_solver=seParams[2],
49 n_neighbors=nneighbors,
52 Y = se.fit_transform(X)
55 lle = manifold.LocallyLinearEmbedding(
56 n_neighbors=nneighbors,
57 n_components=ncomponents,
59 eigen_solver=lleParams[1],
61 max_iter=lleParams[3],
63 hessian_tol=lleParams[5],
64 modified_tol=lleParams[6],
65 neighbors_algorithm=lleParams[7],
68 Y = lle.fit_transform(X)
72 n_components=ncomponents,
75 max_iter=mdsParams[2],
78 dissimilarity=mdsParams[5],
81 Y = mds.fit_transform(X)
83 tsneParams = params[3]
85 n_components=ncomponents,
86 perplexity=tsneParams[0],
87 early_exaggeration=tsneParams[1],
88 learning_rate=tsneParams[2],
90 n_iter_without_progress=tsneParams[4],
91 min_grad_norm=tsneParams[5],
94 verbose=tsneParams[8],
98 Y = tsne.fit_transform(X)
100 isoParams = params[4]
101 iso = manifold.Isomap(
102 n_neighbors=nneighbors,
103 n_components=ncomponents,
104 eigen_solver=isoParams[0],
106 max_iter=isoParams[2],
107 path_method=isoParams[3],
108 neighbors_algorithm=isoParams[4],
112 Y = iso.fit_transform(X)
114 pcaParams = params[5]
115 if pcaParams[4] ==
"auto":
116 pca = decomposition.PCA(
117 n_components=ncomponents,
120 svd_solver=pcaParams[2],
122 iterated_power=
"auto",
125 pca = decomposition.PCA(
126 n_components=ncomponents,
129 svd_solver=pcaParams[2],
131 iterated_power=int(pcaParams[4]),
133 Y = pca.fit_transform(X)
135 L = [Y.shape[0], Y.shape[1], np.ravel(Y,
"F")]
137 except Exception
as inst:
139 "[DimensionReduction] Error: unexpected behaviour detected in the python script."