In [1]:
### IMPORTS
import imp
import networkx as nx
from random import uniform
In [2]:
### CONSTANTS
maximal_entropy = "~/Downloads/maximumEntropyGraph.py"
In [3]:
### SETUP
meg = imp.load_source("meg", maximal_entropy)
In [8]:
### Create a random graph
g = nx.fast_gnp_random_graph(100, 0.05)
for n in nx.nodes_iter(g):
    g.node[n]['weight'] = uniform(1, 10)
In [9]:
### Calculate the entropy
gOut = meg.maximum_entropy_graph(g, 10)
gOutS = meg.serialize_graph(gOut)
In [10]:
### Save the graph
nx.write_graphml(g, "~/Downloads/g.graphml")
nx.write_graphml(gOutS, "~/Downloads/gOutS.graphml")
In [11]:
### TESTING
print(nx.info(g))
print(nx.info(gOutS))
Name: fast_gnp_random_graph(100,0.05)
Type: Graph
Number of nodes: 100
Number of edges: 243
Average degree:   4.8600
Name: fast_gnp_random_graph(100,0.05)
Type: Graph
Number of nodes: 10
Number of edges: 42
Average degree:   8.4000