Suporte para Escrita Delta


In [ ]:
import sys
sys.path.append('..')

import socnet as sn

Calculando centralidade degree do nó n do grafo g:


In [ ]:
d = g.degree(n)

Calculando centralidade closeness do nó n do grafo g:


In [ ]:
sn.build_closeness(g)

c = g.nodes[n]['theoretical_closeness']

Calculando centralidade betweenness do nó n do grafo g:


In [ ]:
sn.build_betweenness(g)

b = g.nodes[n]['theoretical_betweenness']

Calculando restrição de Burt do nó n do grafo g:


In [ ]:
def calculate_constraint(g, n):
    degree_n = g.degree(n)

    if degree_n == 0:
        return 2

    neighbors2 = set(g.neighbors(n))

    for m in g.neighbors(n):
        for l in g.neighbors(m):
            if n != l:
                neighbors2.add(l)

    constraint = 0

    for m in neighbors2:
        if g.has_edge(n, m):
            sub_constraint = 1 / degree_n
        else:
            sub_constraint = 0

        for l in g.neighbors(n):
            if m != l and g.has_edge(m, l):
                sub_constraint += (1 / degree_n) * (1 / g.degree(l))

        constraint += sub_constraint ** 2

    return constraint


b = calculate_constraint(g, n)