Ejemplo n.º 1
0
def embeddingNoteVector(FilePath, DiDr, r, d):
    '''
	:param FilePath: 节点路径文件的路径
	:param DiDr:游走完后的拼接矩阵
	:return:
	'''
    embeddingVector_list = []
    Pst_array = np.array(RFTL.readFileToList(FilePath, 1))
    flag = False
    if Pst_array.shape[0] != 0:  #文件不为空
        for i in range(Pst_array.shape[0]):
            mid_list = []
            if Pst_array[i][1] == r and Pst_array[i][3] == d:
                mid_list.append([Pst_array[i][1],
                                 Pst_array[i][3]])  # 起始药物ID和终止疾病ID
                flag = True
            if flag == True:
                mid_list.append(DiDr[Pst_array[i][1]])  # 第一种药物
                if Pst_array[i][0] == 0:
                    mid_list.append(DiDr[Pst_array[i][2]])
                    mid_list.append([0] * DiDr.shape[0])
                    mid_list.append([0] * DiDr.shape[0])  #最后元素补0
                    embeddingVector_list.append(mid_list)
                if Pst_array[i][0] == 1:  # r-r-d
                    mid_list.append(DiDr[Pst_array[i][2]])  #第二种药物
                    mid_list.append(DiDr[Pst_array[i][3] + 763])  #第一种疾病
                    mid_list.append([0] * DiDr.shape[0])  #最后元素补0
                    embeddingVector_list.append(mid_list)
                if Pst_array[i][0] == 2:  # r-d-d
                    mid_list.append(DiDr[Pst_array[i][2] + 763])  #第一种疾病
                    mid_list.append(DiDr[Pst_array[i][3] + 763])  #第二种疾病
                    mid_list.append([0] * DiDr.shape[0])  # 最后元素补0
                    embeddingVector_list.append(mid_list)

            flag = False
    return embeddingVector_list
Ejemplo n.º 2
0
            else:
                FPR_num += 1 / total_FPR
                TPR.append(TPR_num)
                FPR.append(FPR_num)
                PRE.append(ipre_a / ipre_b)

        TPR_Data.append(TPR)
        FPR_Data.append(FPR)
        PRE_Data.append(PRE)

    return TPR_Data, FPR_Data, PRE_Data


x_FPR, y_TPR, y_PRE = [], [], []
# predict_list = np.load('..\data\Batch50E10LR0.001.pkl.npy')
predict_list = RFTL.readFileToList('..\data\prediction.txt', 0)
train_list = RFTL.readFileToList('..\data\第一份训练数据.txt', 1)
test_list = RFTL.readFileToList('..\data\第一份测试数据.txt', 1)

TPR, FPR, PRE = PlotRoc(np.array(predict_list), np.array(train_list),
                        np.array(test_list), [], [], [])
# TPR,FPR,PRE = PlotRoc(predict_list,np.array(train_list),np.array(test_list),[],[],[])
x_FPR.append(np.array(FPR).sum(axis=0) / np.array(FPR).shape[0])
y_TPR.append(np.array(TPR).sum(axis=0) / np.array(TPR).shape[0])
y_PRE.append(np.array(PRE).sum(axis=0) / np.array(PRE).shape[0])
print('ROC_AUC:', auc(x_FPR[0], y_TPR[0]))
print('PR_AUC:', auc(y_TPR[0], y_PRE[0]) + y_TPR[0][0] * y_PRE[0][0])
plot(x_FPR[0], y_TPR[0], "r")
plot(y_TPR[0], y_PRE[0], "b")
show()
Ejemplo n.º 3
0
        x = self.conv2(x)  #torch.Size([1, 32, 2, 348])
        x = x.view(x.size(0), -1)
        output = self.out1(x)
        output = self.out2(output)
        return output


cnn = CNN()
if torch.cuda.is_available():
    cnn.cuda()
optimizer = torch.optim.Adam(cnn.parameters(), lr=0.001)
loss_func = nn.CrossEntropyLoss()
#--------------------------CNN模型结束-------------------------------------
EPOCH = 10
if __name__ == "__main__":
    DrugSim_list = RFTL.readFileToList("..\data\drugSim.txt", 0)
    DisSim_list = RFTL.readFileToList("..\data\disSim.txt", 0)
    DiDr_list = RFTL.readFileToList('..\data\DiDrAMat.txt', 1)
    DiDrSplit_list = RFTL.splitArray("..\data\DiDrAMat.txt")  #所有1的坐标的list

    DiDr_array, DiDr_testArray = RFTL.ChangeArray(np.array(DiDr_list),
                                                  DiDrSplit_list,
                                                  0)  # 第一份1做test
    np.savetxt('..\data\第一份训练数据_cnn.txt',
               DiDr_array,
               fmt=['%s'] * DiDr_array.shape[1],
               newline='\n')
    np.savetxt('..\data\第一份测试数据_cnn.txt',
               DiDr_testArray,
               fmt=['%s'] * DiDr_testArray.shape[1],
               newline='\n')
Ejemplo n.º 4
0
#_Author_:Monkey
#!/usr/bin/env python
#-*- coding:utf-8 -*-

import numpy as np
import function as FUN

FileC_Path = '..\data\Batch50E10LR0.001.pkl.npy'
FileG_Path = '..\data\GRUM.txt'

cnn_list = np.load(FileC_Path)
gru_list = FUN.readFileToList(FileG_Path, 0)

predict = 0.6 * cnn_list + 0.4 * np.array(gru_list)

np.savetxt('..\data\prediction.txt',
           predict,
           fmt=['%s'] * predict.shape[1],
           newline='\n')