예제 #1
0
def read_gml(path, encoding='latin-1', relabel=False, auto_table=False):
    """NetworkX read_gml method and wrap graph to Orange network.
    
    """
    G = _wrap(rwgml.read_gml(path, encoding, relabel))
    if auto_table:
        G.set_items(graph_to_table(G))
    return G
예제 #2
0
def de_main(path, f):
    #接受准则Adapted Kernighan-Lin
    if f == 1:
        G = load_graph(path)
    else:
        G = read_gml(path, label='id')
    dea = DEAlgorithm(G, popSize, generations, sub_dim, 0, G.number_of_nodes())
    r = dea.move_bat()
    return r
예제 #3
0
def gacd_main(path, f):
    #接受准则Adapted Kernighan-Lin
    if f == 1:
        G = load_graph(path)
    else:
        G = read_gml(path, label='id')
    bestScores = []
    avgScores = []
    p = Population(popSize, G)
    bestScores.append(p.getMax().score)
    for i in range(generations):
        p.updatePop()
        bestScores.append(p.getMax().score)
    return bestScores
예제 #4
0
        ind_2 = diccionario[pares_de_metodos[i][1]]   
        matriz_presicion[ind_1,ind_2] = presicion
        matriz_presicion[ind_2,ind_1] = presicion    
    return matriz_presicion

def plot_matrix(matriz, etiquetas=None, annot = False):
    df = pd.DataFrame(matriz, columns=etiquetas, index = etiquetas)
    ax = sns.heatmap(df, annot=annot, fmt=".2f", vmin = 0, vmax=1
                     , square=True)
    for label in ax.get_yticklabels():
            label.set_size(7)
    for label in ax.get_xticklabels():
            label.set_size(7)
#%%
if __name__ == '__main__':
    dolph = read_gml('Tp3/dolphins.gml')    
    lista_de_metodos = ["infomap","label_prop", "fastgreedy", "eigenvector",
                        "louvain", "edge_betweenness", "walktrap"] 
    part_1 = calcular_particion(dolph, method="fastgreedy", only_labels = True)
    part_2 = calcular_particion(dolph, method="walktrap", only_labels = True)
    matriz_confusion, presicion = matriz_de_confusion(part_1,part_2,norm=True)
    lista_de_metodos_chetos = ["Infomap","Label Propagation", "Fastgreedy",
                               "Eigenvector", "Louvain", "Edge Betweenness",
                               "Walktrap"] 
    mp = matriz_de_presiciones(dolph, lista_de_metodos)
    plt.figure()
    plot_matrix(matriz_confusion, annot=True)
    plt.figure()
    plot_matrix(mp, lista_de_metodos_chetos)
#%% Pruebita
    a=[1,1,1,2,2,2]
예제 #5
0
from random import sample

from lectura import ldata
import sys
sys.path.append('./Tp1/')
from dolphins_funciones import (genero_a_color, particionar_por_genero,
                                crear_leyenda, contar_enlaces_internos,
                                contar_enlaces_entre_grupos, contar_clases,
                                p_value, cociente, desarme)
from modularidad import modularidad
from histograma import histograma
from graficar_multipartito import *
from collections import Counter

dolph = read_gml('Tp1/tc01_data/new_dolphins.gml')
genders = dict(ldata('Tp1/tc01_data/dolphinsGender.txt'))
#%%

# Agrego los sexos a los dicts de cada delfín
for nodo, dict_nodo in dict(dolph.nodes).items():
    dict_nodo['gender'] = genders[nodo]  # agrego el sexo del delfín a su dict
#    print('Key = {}, Value = {}'.format(nodo, dict_nodo)) # para chequear que anda

particiones = particionar_por_genero(dolph)
colores = [
    genero_a_color(g)
    for g in nx.get_node_attributes(dolph, "gender").values()
]

# Hay 34 delfines macho, 24 delfines hembra y 4 delfines sin información
from networkx.readwrite.gml import read_gml
from lectura import ldata
from histograma import histograma
from scipy.odr import Model, RealData, ODR
from scipy import stats
from asortatividad_funciones import (linear, ClosestToOne, annd, gamma,
                                     chi2_iterative, ks_iterative)

#%%Importamos las redes
#Mati: Tomi te comente esto porque solo funciona en tu compu, me parece que los
#path que puse aca abajo funcionan en las compus de todes.

#net_science = read_gml('/home/tomas/Desktop/Redes complejas/Urdimbres-Sofisticadas/Tp1/tc01_data/netscience.gml')
#july = read_gml('/home/tomas/Desktop/Redes complejas/Urdimbres-Sofisticadas/Tp1/tc01_data/as-22july06.gml')

net_science = read_gml('tc01_data/netscience.gml')
july = read_gml('tc01_data/as-22july06.gml')
degree_2, annd_2 = annd(net_science)
degree_1, annd_1 = annd(july)

#%%
#En este plot se puede ver que no aparece una recta, por lo que no hay que ajustar aca.

f, ([ax1, ax2], [ax3, ax4]) = plt.subplots(2, 2)
f.tight_layout()

plt.sca(ax1)
ax1.set_title('(a)  Lineal')
ax1.plot(degree_1, annd_1, '.')
ax1.set_ylabel(r'$k_{nn}$')
ax1.set_xlabel('k')
예제 #7
0
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Sun Sep  9 21:45:45 2018

@author: tomas
"""

import networkx as nx
import matplotlib.pyplot as plt
import numpy as np
from networkx.readwrite.gml import read_gml
from histograma import histograma
from __future__ import division

internet = read_gml('Tp1/tc01_data/as-22july06.gml')
nodes = []
degrees = []
for a, b in internet.degree():
    nodes.append(a)
    degrees.append(b)
#%% PUNTO A: Comparación de visualizaciones

# Para comparar los bineados logarítmicos y no logaasdrítmicos, lo justo es
# excluir a los nodos de grado 0 en ambos

fig, axes = plt.subplots(4, 2, figsize=(10, 10))
axes = axes.flatten()
logbinss = [0, 0, 0, 0, 1, 1, 1, 1]
logxs = [0, 0, 1, 1, 0, 0, 1, 1]
logys = [0, 1, 0, 1, 0, 1, 0, 1]
예제 #8
0
def load_graph(name):
    if not name.endswith(".gml"):
        name += ".gml"
    return gml.read_gml(name)