Пример #1
0
def scores_from_votes(votes):
    
    eliminated_players = votes.columns
    
    # Turn vote matrix into graph object
    v = process_votes.compare_votes(votes)
    
    g = make_graphs.make_graph(v)
    
    # Calculate scores
    scores = network.centrality_scores(votes, g)
    
    # Add votes for and against
    vca = votes_correct_against(votes)
    scores = scores.join(vca, on='name')
    
    # Binary classification of winners (1) and losers (0)
    scores['place'] = np.where(scores['place'] == 1, 1, 0)
    
    # Rearrange columns
    scores = scores[['name','deg','close','btw','eig','page','votes_correct','votes_against','place']]
    
    # Filter out eliminated players
    fltr = [i.strip() not in eliminated_players for i in scores['name']]
    
    return scores.loc[fltr, :]
Пример #2
0
def scores_from_votes(votes):

    eliminated_players = votes.columns

    # Turn vote matrix into graph object
    v = process_votes.compare_votes(votes)

    g = make_graphs.make_graph(v)

    # Calculate scores
    scores = network.centrality_scores(votes, g)

    # Add votes for and against
    vca = votes_correct_against(votes)
    scores = scores.join(vca, on='name')

    # Binary classification of winners (1) and losers (0)
    scores['place'] = np.where(scores['place'] == 1, 1, 0)

    # Rearrange columns
    scores = scores[[
        'name', 'deg', 'close', 'btw', 'eig', 'page', 'votes_correct',
        'votes_against', 'place'
    ]]

    # Filter out eliminated players
    fltr = [i.strip() not in eliminated_players for i in scores['name']]

    return scores.loc[fltr, :]
Пример #3
0
import parser, make_graphs
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.legend_handler import HandlerLine2D

if __name__ == '__main__':
    filenames = ["0301/{}.txt".format(i) for i in range(0, 3)]
    data = parser.Data(filenames)
    graph = make_graphs.make_graph(data)
    print graph.GetNodes()

    #centr_files = ['GetBetweennessCentr-0-2.txt', 'GetClosenessCentr-0-2.txt', 'GetDegreeCentr-0-2.txt']
    centr_files = ['GetDegreeCentr-0-2.txt']
    for centr in centr_files:
        with open(centr) as f:
            contents = f.readlines()
        split = [l.strip().split(' ') for l in contents]
        parsed = [(int(nid), float(centr)) for nid, centr in split]
        results = [(data.lookup[data.videoid[nid]].age, centr)
                   for nid, centr in parsed]
        x, y = zip(*results)
        print y[:20]
        print x[:20]

        #plt.loglog(x, y, 'o')
        plt.title('Degree Centrality vs Age')
        plt.xlabel('age')
        plt.ylabel('centrality score')
        plt.scatter(x, y)
        plt.show()
Пример #4
0
    # example save and load
    #save_graph_data(data, graph, "test")
    #data, graph = load_graph_data("test")

    # example reading and processing
    for n in graph.Nodes():
        nid = n.GetId()
        vid = data.videoid[nid]
        if vid in data.lookup:
            print data.lookup[vid]
'''


filenames = [ "0301/{}.txt".format(i) for i in range(0, 3) ]
data = parser.Data(filenames)
graph = make_graphs.make_graph(data)
Graph = snap.ConvertGraph(snap.PUNGraph, graph)

GraphClustCoeff = snap.GetClustCf (Graph, -1)

print "Average clustering coefficient of the graph is ", GraphClustCoeff

for category in data.categories:
    graph1 = make_graphs.make_graph(data,[category])
    Graph1 = snap.ConvertGraph(snap.PUNGraph, graph1)
    print category, Graph1.GetNodes(), Graph1.GetEdges()
    GraphClustCoeff1 = snap.GetClustCf (Graph1, -1)
    print "Average clustering coefficient of the " +category + " graph is ", GraphClustCoeff1