to find the fractal dimension of a real-world network, using the box-covering algorithm
Asked Answered
R

0

6

here, in the following code, I get the colors assigned to the vertices, but there is no significance for the length of the box 'l'

I want the colors to be assigned w.r.t. the length of the boxes and the function should output the number of different colors in the network, so that I can use it to determine the fractal dimension of a real-world network, according the law,

NB ~ lB-dB

please, help me in achieving this.

the file dolphin contains two columns each representing the two ends of an edge.

import networkx as nx
import matplotlib.pyplot as plt
G=nx.Graph()

colors = ['c1', 'c2', 'c3', 'c4',  'c5', 'c6', 'c7', 'c8', 'c9', 'c10', 'c11', 'c12']

f = open("real_network/dolphin")
a = [int(n) for n in f.read().split()]
G.add_nodes_from(a)

i = 0
b = []
while i<len(a):
    b.append((a[i],a[i+1]))
    i = i+2

#print b

G.add_edges_from(b)
colors_of_nodes={}


def coloring(node, color):
    for neighbor in G.neighbors(node):
        color_of_neighbor = colors_of_nodes.get(neighbor, None)
        if color_of_neighbor == color:
            return False

    return True

def get_color_for_node(node):
    for color in colors:
        if coloring(node, color):
            return color

def main():
    for node in G.nodes():
        colors_of_nodes[node] = get_color_for_node(node)

    print colors_of_nodes


main()
Resistive answered 21/7, 2012 at 14:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.