-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrepeat_FA_cortex.py
42 lines (34 loc) · 1.34 KB
/
repeat_FA_cortex.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import os
import numpy as np
np.random.seed(1234)
import torch
torch.manual_seed(1234)
import pandas as pd
import matplotlib.pyplot as plt
import time
from sklearn.decomposition import PCA
from sklearn.decomposition import FactorAnalysis
from sklearn.metrics import silhouette_score
from sklearn.cluster import KMeans
from sklearn.metrics import normalized_mutual_info_score as NMI
from sklearn.metrics import adjusted_rand_score as ARI
def cluster_scores(latent_space, K, labels_true):
labels_pred = KMeans(K, n_jobs=8, n_init=20).fit_predict(latent_space)
return [silhouette_score(latent_space, labels_true), NMI(labels_true, labels_pred), ARI(labels_true, labels_pred)]
n_celltype = 7
file_name = "CORTEX_FA"
# expression data
data_path = "/home/jzhaoaz/jiazhao/scPI_v2/package/datasets/cortex/"
expression_train = np.log(np.loadtxt(data_path + "data_train", dtype='float32') + 1)
c_train = np.loadtxt(data_path + "label_train")
n_repeat = 10
for i in range(n_repeat):
t0 = time.time()
alg = FactorAnalysis(n_components=10)
alg.fit(expression_train)
latent = alg.transform(expression_train)
np.savetxt(str(i) + file_name + '_time.txt', np.array(time.time()-t0).reshape([-1]))
scores = cluster_scores(latent, n_celltype, c_train)
np.savetxt(str(i) + file_name + '_scores.txt', scores)
if (i==0):
np.savetxt(str(i) + file_name + '_Z.txt', latent)