예제 #1
0
def cache_x_clustering_geral(todos_artistas, todos_caches):
    counter_geral = 0
    lista_clustering = []
    node = nx.DiGraph()

    for id_artista in todos_artistas:
        artista = get_name(api, id_artista)
        print(artista)
        try:
            g = fm.load('GMLS/{0}.gml'.format(artista))
            clustering = nx.average_clustering(g)
            lista_clustering.append(clustering)
        except:
            print("{0} FAIL".format(artista))

    #PLOTS

    colors = (0, 0, 0)
    area = np.pi * 3

    ppv = pearsonr(lista_clustering, todos_caches)

    # Plot Scatter Clustering x Cache
    plt.scatter(lista_clustering, todos_caches, s=area, alpha=0.5)
    plt.suptitle('Scatter Clustering x Cache')
    plt.title('Pvalue: {0} / Cf de Correlação de Pearson: {1}'.format(
        ppv[1], ppv[0]))
    plt.xlabel('Clustering')
    plt.ylabel('Cache')
    plt.show()

    return lista_clustering
예제 #2
0
def cache_x_indegree_geral(todos_artistas, todos_caches):
    lista_indegree = []
    for id_artista in todos_artistas:
        artista = get_name(api, id_artista)
        print(artista)
        try:
            g = fm.load('GMLS/{0}.gml'.format(artista))
            indegrees = g.in_degree()
            for x in indegrees:
                if (id_artista in x):
                    indegree = x[1]
                    print(indegree)
                    lista_indegree.append(indegree)
        except:
            print("{0} FAIL".format(artista))

    #PLOTS

    colors = (0, 0, 0)
    area = np.pi * 3
    ppv = pearsonr(lista_indegree, todos_caches)

    plt.scatter(lista_indegree, todos_caches, s=area, alpha=0.5)
    plt.suptitle('Scatter Indegree x Cache ')
    plt.title(
        'Pvalue: {0} and Coeficiente de Correlação de Pearson: {1}'.format(
            ppv[1], ppv[0]))
    plt.xlabel('Indegree')
    plt.ylabel('Cache')
    plt.show()

    return lista_indegree
예제 #3
0
def cache_x_densidade_geral(todos_artistas, todos_caches):
    #counter_geral = 0
    lista_densidade = []
    node = nx.DiGraph()

    for id_artista in todos_artistas:
        artista = get_name(api, id_artista)
        print(artista)
        try:
            g = fm.load('GMLS/{0}.gml'.format(artista))
            densidade = nx.density(g)
            lista_densidade.append(densidade)
        except:
            print("{0} FAIL".format(artista))

    #PLOTS

    colors = (0, 0, 0)
    area = np.pi * 3

    ppv = pearsonr(lista_densidade, todos_caches)

    # Plot Scatter Densidade x Cache
    #    plt.scatter(lista_densidade,todos_caches, s=area, alpha=0.5)
    #    plt.suptitle('Scatter Densidade x Cache')
    #    plt.title('Pvalue: {0} / Cf de Correlação de Pearson: {1}'.format(ppv[1],ppv[0]))
    #    plt.xlabel('Densidade')
    #    plt.ylabel('Cache')
    #    plt.show()

    return lista_densidade
예제 #4
0
def network_nx(network):  

    g = fm.load(network)
    g.label_nodes('name')
    g.set_all_nodes(size=10, labpos='hover')
    g.draw()
    return g
예제 #5
0
def cache_x_indegree_genero(lista_geral_id, lista_geral_caches):
    counter_geral = 0
    for lista_genero in lista_geral_id:
        lista_indegree = []
        node = nx.DiGraph()
        for id_artista in lista_genero:
            artista = get_name(api, id_artista)
            print(artista)
            try:
                g = fm.load('GMLS/{0}.gml'.format(artista))
                indegrees = g.in_degree()
                for x in indegrees:
                    if (id_artista in x):
                        indegree = x[1]
                        print(indegree)
                        lista_indegree.append(indegree)
            except:
                print("{0} FAIL".format(artista))

        #PLOTS

        colors = (0, 0, 0)
        area = np.pi * 3

        ppv = pearsonr(lista_indegree, lista_geral_caches[counter_geral])

        # Plot Scatter Indegree x Cache
        lista_caches = lista_geral_caches[counter_geral]
        plt.scatter(lista_indegree, lista_caches, s=area, alpha=0.5)
        plt.suptitle('Scatter Indegree x Cache- ' + generos[counter_geral])
        plt.title(
            'Pvalue: {0} and Coeficiente de Correlação de Pearson: {1}'.format(
                ppv[1], ppv[0]))
        plt.xlabel('Indegree')
        plt.ylabel('Cache')
        plt.show()

        counter_geral += 1
예제 #6
0
def load(name):
    g = fm.load('{}.gml'.format(name))

    # Remover todas as arestas com peso menor ou igual a 0.5.
    # Precisamos de dois loops, pois não é uma boa ideia
    # tirar algo de um conjunto enquanto iteramos nele.
    removed = []
    for n, m in g.edges:
        if g.edges[n, m]['weight'] <= 0.5:
            removed.append((n, m))
    for n, m in removed:
        g.remove_edge(n, m)

    # Remover todos os nós que ficaram isolados depois da
    # remoção das arestas, para melhorar a visualização.
    removed = []
    for n in g.nodes:
        if not g.degree(n):
            removed.append(n)
    for n in removed:
        g.remove_node(n)

    return g
예제 #7
0
def cache_x_densidade_genero(lista_geral_id, lista_geral_caches):
    counter_geral = 0
    for lista_genero in lista_geral_id:
        lista_densidade = []
        counter = 0
        node = nx.DiGraph()
        for id_artista in lista_genero:
            artista = get_name(api, id_artista)
            print(artista)
            try:
                g = fm.load('GMLS/{0}.gml'.format(artista))
                densidade = nx.density(g)
                lista_densidade.append(densidade)
            except:

                print("{0} FAIL".format(artista))

            counter += 1
        #PLOTS

        colors = (0, 0, 0)
        area = np.pi * 3
        ppv = pearsonr(lista_geral_caches[counter_geral], lista_densidade)

        # Plot Scatter Densidade x Cache
        plt.scatter(lista_densidade,
                    lista_geral_caches[counter_geral],
                    s=area,
                    alpha=0.5)
        plt.suptitle('Scatter Densidade x Cache - ' + generos[counter_geral])
        plt.title('Pvalue: {0} / Cf de Correlação de Pearson: {1}'.format(
            ppv[1], ppv[0]))
        plt.xlabel('Densidade')
        plt.ylabel('Cache')
        plt.show()

        counter_geral += 1
예제 #8
0
        cache = row[2]
        lista_ids.append(id_artista)
        lista_nomes.append(nome)
        lista_caches.append(cache)
    csvfile.close()

lista_nomes.pop(0)
lista_ids.pop(0)
lista_caches.pop(0)

counter = 0
node = nx.DiGraph()
print(lista_nomes)
for artista in lista_nomes:
    try:
        g = fm.load('{0}.gml'.format(artista))
        indegree = g.in_degree(lista_ids[counter])
        lista_indegree.append(indegree)
    except:
        print("{0} FAIL".format(artista))

    counter += 1

print(lista_indegree)

colors = (0, 0, 0)
area = np.pi * 3

# Plot
plt.scatter(lista_caches, lista_indegree, s=area, alpha=0.5)
plt.title('Scatter Indegree x Cache')