Exemplo n.º 1
0
 def test_generalized_laplacian(self):
     "Generalized Graph Laplacian"
     GL = numpy.array([[1.00, -0.408, -0.408, -0.577, 0.00],
                       [-0.408, 1.00, -0.50, 0.00, 0.00],
                       [-0.408, -0.50, 1.00, 0.00, 0.00],
                       [-0.577, 0.00, 0.00, 1.00, 0.00],
                       [0.00, 0.00, 0.00, 0.00, 0.00]])
     assert_almost_equal(nx.generalized_laplacian(self.G), GL, decimal=3)
Exemplo n.º 2
0
 def test_generalized_laplacian(self):
     "Generalized Graph Laplacian"
     GL=numpy.array([[ 1.00, -0.41, -0.41, -0.58,  0.00],
                     [-0.41,  1.00, -0.50,  0.00 , 0.00], 
                     [-0.41, -0.50,  1.00,  0.00,  0.00], 
                     [-0.58,  0.00,  0.00,  1.00,  0.00],
                     [ 0.00,  0.00,  0.00,  0.00,  0.00]]) 
     assert_almost_equal(nx.generalized_laplacian(self.G),GL,decimal=2)
try:
    from pylab import *
except:
    pass

from graphml import read_graphml

import sys, os

if len(sys.argv) == 2:
    fn = sys.argv[1]
    print "Reading in %s" % fn
    g = read_graphml(fn)
    print "Generating a generalized laplacian"
    l = nx.generalized_laplacian(g)
    print "Calculating eigenvalues"
    e = eigenvalues(l)
    print ("Largest eigenvalue:", max(e))
    print ("Smallest eigenvalue:", min(e))
    # plot with matplotlib if we have it
    # shows "semicircle" distribution of eigenvalues
    try:
        print "Trying to plot semicircle of eigenvalues"
        hist(e, bins=100)  # histogram with 100 bins
        xlim(0, 2)  # eigenvalues between 0 and 2
        show()
        # plt.savefig("%s.eigen.png" % fn)
    except:
        pass
Exemplo n.º 4
0
    session = Session()
    query = session.query(Title)
    for x in query.filter(Title.title.like('%air%')):
        print(x)
        
if __name__ == '__main__':
    for file in util.dir2files('/home/luoxing/data/KB'):
        IdName.addColums(file)
    
import networkx
import numpy.linalg
import pylab
n = 100
m = 500
g = networkx.gnm_random_graph(n, m)
l = networkx.generalized_laplacian(g)
e = numpy.linalg.eigvals(l)
max(e), min(e)
pylab.hist(e, bins=10)
pylab.xlim(0, 2)
pylab.show()

import networkx as nx
import db
s = db.getSession()
def makeGraph(session):
    g = nx.DiGraph()
    for src, dest in session.query(db.Anchor.source, db.Anchor.destination):
        g.add_edge(src, dest)
    return g
try:
    from pylab import *
except:
    pass

from graphml import read_graphml

import sys, os

if len(sys.argv) == 2:
    fn = sys.argv[1]
    print "Reading in %s" % fn
    g = read_graphml(fn)
    print "Generating a generalized laplacian"
    l = nx.generalized_laplacian(g)
    print "Calculating eigenvalues"
    e = eigenvalues(l)
    print("Largest eigenvalue:", max(e))
    print("Smallest eigenvalue:", min(e))
    # plot with matplotlib if we have it
    # shows "semicircle" distribution of eigenvalues
    try:
        print "Trying to plot semicircle of eigenvalues"
        hist(e, bins=100)  # histogram with 100 bins
        xlim(0, 2)  # eigenvalues between 0 and 2
        show()
        #plt.savefig("%s.eigen.png" % fn)
    except:
        pass