示例#1
0
文件: CKA.py 项目: hzhou256/py
def my_HSIC(X, Y):
    if X.ndim == 1:
        temp = X
        t1 = temp.reshape(len(temp), 1)
        t2 = temp.reshape(1, len(temp))
        T_X = np.dot(t1, t2)
    else:
        T_X = mf.tanimoto(X, X)
    if Y.ndim == 1:
        temp = Y
        t1 = temp.reshape(len(temp), 1)
        t2 = temp.reshape(1, len(temp))
        T_Y = np.dot(t1, t2)
    else:
        T_Y = mf.tanimoto(Y, Y)
    return np.sum(centering(T_X) * centering(T_Y))
示例#2
0
    np.set_printoptions(suppress=True)

    K1 = np.zeros((m, m))
    for i in range(m):
        for j in range(m):
            K1[i][j] = round(metrics_function.cosine(data[i], data[j]), 6)
    print(K1)
    with open(
            'D:/Study/Bioinformatics/QSP_new/kernel_matrix/KM_train_cosine/KM_cosine_'
            + name + '_train.csv',
            'w',
            newline='') as csvfile:
        writer = csv.writer(csvfile)
        for row in K1:
            writer.writerow(row)
        csvfile.close()

    K3 = np.zeros((m, m))
    for i in range(m):
        for j in range(m):
            K3[i][j] = round(metrics_function.tanimoto(data[i], data[j]), 6)
    print(K3)
    with open(
            'D:/Study/Bioinformatics/QSP_new/kernel_matrix/KM_train_tanimoto/KM_tanimoto_'
            + name + '_train.csv',
            'w',
            newline='') as csvfile:
        writer = csv.writer(csvfile)
        for row in K3:
            writer.writerow(row)
        csvfile.close()
示例#3
0
    K1 = np.zeros((m, p))
    for i in range(m):
        for j in range(p):
            K1[i][j] = round(metrics_function.cosine(X_test[i], X_train[j]), 6)
    print(K1)
    with open(
            'D:/study/Bioinformatics/AMP/kernel_matrix/KM_test_cosine/KM_cosine_'
            + name + '_test.csv',
            'w',
            newline='') as csvfile:
        writer = csv.writer(csvfile)
        for row in K1:
            writer.writerow(row)
        csvfile.close()

    K3 = np.zeros((m, p))
    for i in range(m):
        for j in range(p):
            K3[i][j] = round(metrics_function.tanimoto(X_test[i], X_train[j]),
                             6)
    print(K3)
    with open(
            'D:/study/Bioinformatics/AMP/kernel_matrix/KM_test_tanimoto/KM_tanimoto_'
            + name + '_test.csv',
            'w',
            newline='') as csvfile:
        writer = csv.writer(csvfile)
        for row in K3:
            writer.writerow(row)
        csvfile.close()
示例#4
0
                    metrics_function.cosine(X_test[i], X_train[j]), 6)
        print(K2)
        with open('D:/study/Bioinformatics/QSP/200p_200n/10_fold/' + name +
                  '/km_test/KM_cosine_' + name + '_test_' + str(k) + '.csv',
                  'w',
                  newline='') as csvfile:
            writer = csv.writer(csvfile)
            for row in K2:
                writer.writerow(row)
            csvfile.close()

        K3 = np.zeros((p, p))
        for i in range(p):
            for j in range(p):
                K3[i][j] = round(
                    metrics_function.tanimoto(X_train[i], X_train[j]), 6)
        print(K3)
        with open('D:/study/Bioinformatics/QSP/200p_200n/10_fold/' + name +
                  '/km_train/KM_tanimoto_' + name + '_train_' + str(k) +
                  '.csv',
                  'w',
                  newline='') as csvfile:
            writer = csv.writer(csvfile)
            for row in K3:
                writer.writerow(row)
            csvfile.close()

        K4 = np.zeros((m, p))
        for i in range(m):
            for j in range(p):
                K4[i][j] = round(