Hi
Thank you for your great work in Gene embedding with GenePT.
When I run aorta_data_analysis.ipynb, it did not work with error of could not find get_similar_vectors function code ? I tried to sovle this problem with scGPT code (get_similar_vectors), it worked, but the accuracy_score was low (sklearn.metrics.accuracy_score(gt_list, pred_list): 0.83), do is right?
when I use follow code, the accuracy_score is 0.87, almost the same to your result.
class Similarity(nn.Module):
'''
Dot product or cosine similarity
'''
def __init__(self, temp):
super().__init__()
self.temp = temp
self.cos = nn.CosineSimilarity(dim=-1)
def forward(self, x, y):
# 将 NumPy 数组转换为 PyTorch 张量
x_tensor = torch.from_numpy(x)
y_tensor = torch.from_numpy(y)
# 计算余弦相似度
cos_sim = self.cos(x_tensor, y_tensor) / self.temp
# 如果需要返回 NumPy 数组,可以在这里进行转换
return cos_sim.numpy()
def get_similar_vectors(vector, ref, top_k=10):
sim = Similarity(temp=0.5)
# sims = cos_sim(vector, ref)
sims=sim(vector, ref)
# cos_sim=torch.mm(vector, ref)
# sims = l2_sim(vector, ref) ###scGPT用的是此函数,但是结果较差
top_k_idx = np.argsort(sims)[::-1][:top_k]
return top_k_idx, sims[top_k_idx]
Yourse
Hi
Thank you for your great work in Gene embedding with GenePT.
When I run aorta_data_analysis.ipynb, it did not work with error of could not find get_similar_vectors function code ? I tried to sovle this problem with scGPT code (get_similar_vectors), it worked, but the accuracy_score was low (sklearn.metrics.accuracy_score(gt_list, pred_list): 0.83), do is right?
when I use follow code, the accuracy_score is 0.87, almost the same to your result.
Yourse