Ejemplo n.º 1
0
def preferential_attachment_prediction(trainGraph, testGraph, mode, layer2,
                                       type):

    adjacencyMatrix = testGraph.get_adjacency()
    if mode == "multilayer":
        PAMatrix = multilayer_preferential_attachment_score(
            trainGraph, layer2, type)
    if mode == "normal":
        PAMatrix = preferential_attachment_score(trainGraph)
    PAMatrix = np.array(PAMatrix)
    i = (-PAMatrix).argsort(axis=None, kind='mergesort')
    j = np.unravel_index(i, PAMatrix.shape)
    sortedIndices = np.vstack(j).T
    total = len(PAMatrix) * len(PAMatrix)

    sortedList = np.sort(np.array(PAMatrix).ravel())

    roc_auc = calculate_auroc(sortedList[::-1], sortedIndices, adjacencyMatrix)

    #roc_auc = auc(fpr, tpr)
    #print ("Area under the ROC curve : %f" % roc_auc)

    #return roc_auc,fpr,tpr
    #return roc_auc,precision,recall
    return roc_auc, sortedIndices
Ejemplo n.º 2
0
def common_neighbors_prediction(trainGraph,testGraph,mode,layer2,type):

    adjacencyMatrix = testGraph.get_adjacency()
    if mode == "multilayer":
        CNMatrix = multilayer_common_neighbors_score(trainGraph,layer2,type)
    if mode == "normal":
        CNMatrix = common_neighbors_score(trainGraph)

    CNMatrix  = np.array(CNMatrix)
    i = (-CNMatrix ).argsort(axis=None, kind='mergesort')
    j = np.unravel_index(i, CNMatrix .shape)
    sortedIndices = np.vstack(j).T

    sortedList = np.sort(np.array(CNMatrix).ravel())
    roc_auc = calculate_auroc(sortedList[::-1],sortedIndices,adjacencyMatrix)

    #roc_auc = auc(fpr, tpr)
    #print ("Area under the ROC curve : %f" % roc_auc)

    #return roc_auc,fpr,tpr
    #return roc_auc,precision,recall
    return roc_auc,sortedIndices
Ejemplo n.º 3
0
    pairs = []
    scores = []

    N = tradesTrainGraph.vcount()
    for v in range(N):
        for w in range(N):
            pairs.append((v, w))
            if v in tradeNodeRates:
                scores.append(
                    tradeNodeRates.get(v) + (tradeLayerWeights[0] * 1))
            else:
                scores.append(0)

    sortedIndices, sortedList = memScoreMatch(pairs, scores)
    adjacencyMatrix = tradesTrainGraph.get_adjacency()
    auroc = calculate_auroc(sortedList, sortedIndices, adjacencyMatrix)
    print(auroc)

    scores = []
    pairs = []
    N = messagesTrainGraph.vcount()
    for v in range(N):
        for w in range(N):
            pairs.append((v, w))
            if v in messageNodeRates:
                scores.append(
                    messageNodeRates.get(v) + (messageLayerWeights[0] * 1))
            else:
                scores.append(0)

    sortedIndices, sortedList = memScoreMatch(pairs, scores)