-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
229 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/usr/bin/env python | ||
import networkx as nx | ||
import csv | ||
import matplotlib.pylab as plt | ||
import os.path | ||
|
||
|
||
## Example by Rob Zinkov | ||
## minor updates by Far McKon | ||
|
||
|
||
|
||
def jaccard(a, b): | ||
c = a.intersection(b) | ||
return float(len(c)) / (len(a) + len(b) - len(c)) | ||
|
||
def show_talk_graph(): | ||
reader = csv.reader(file("talk_presence.csv")) | ||
headers = reader.next() | ||
|
||
talks_seen = {} | ||
G = nx.Graph() | ||
|
||
for line in reader: | ||
if line[0] not in talks_seen: | ||
talks_seen[line[0]] = set(line[1]) | ||
else: talks_seen[line[0]].add(line[1]) | ||
for t in talks_seen: | ||
for u in talks_seen: | ||
if t is not u: | ||
weight = jaccard(talks_seen[t], | ||
talks_seen[u]) | ||
if weight > 0.4: | ||
G.add_edge(t,u,weight=weight) | ||
pos = nx.spring_layout(G,weighted=True) | ||
nx.draw(G, | ||
pos, | ||
edge_color=[float(G[e1][e2]['weight']+0.1) for e1,e2 in G.edges()], | ||
width=4, | ||
node_size=40, | ||
edge_cmap=plt.cm.Blues, | ||
with_labels=False, | ||
|
||
node_color=[float(G.degree(v)) for v in G], | ||
cmap=plt.cm.Blues, | ||
) | ||
print "Nodes:%d Edges: %d\n" % (len(G.nodes()),len(G.edges())) | ||
plt.show() | ||
|
||
if __name__ == "__main__": | ||
|
||
if not os.path.exists("talk_presence.csv"): | ||
print "please download the Last Hope data set unto the same directory as this file" | ||
print "the last hope data set can be found at http://crawdad.org/meta.php?name=hope/amd " | ||
else : | ||
show_talk_graph() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env python | ||
import networkx as nx | ||
import csv | ||
import matplotlib.pylab as plt | ||
import os.path | ||
|
||
## Example by Rob Zinkov | ||
## minor updates by Far McKon | ||
|
||
def load_location_graph(): | ||
reader = csv.reader(file("position_snapshot.csv")) | ||
headers = reader.next() | ||
|
||
last_time = "" | ||
|
||
zones = {} | ||
edges = {} | ||
nodes = {} | ||
|
||
for line in reader: | ||
nodes[line[1]] = nodes.get(line[1],0)+1 | ||
if line[0] != last_time: | ||
for z in zones: | ||
for i in zones[z]: | ||
for j in filter(lambda x: x!=i,zones[z]): | ||
edges[(i,j)] = edges.get((i,j),0)+1 | ||
edges[(j,i)] = edges.get((j,i),0)+1 | ||
last_time = line[0] | ||
zones = {} | ||
else: | ||
zones[line[2]] = zones.get(line[2],set()).union([line[1]]) | ||
G = nx.Graph() | ||
for (e1,e2) in edges: | ||
weight = edges[(e1,e2)]/(nodes[e1]+nodes[e2]-edges[(e1,e2)]) | ||
#alternative weight | ||
# weight = edges[(e1,e2)]/min(nodes[e1],nodes[e2]) | ||
if weight > 0.08: | ||
G.add_edge(e1,e2,weight=weight) | ||
print "Nodes:%d Edges: %d\n" % (len(G.nodes()),len(G.edges())) | ||
|
||
pos = nx.spring_layout(G,weighted=True) | ||
nx.draw(G, | ||
pos, | ||
node_size=40, | ||
with_labels=False, | ||
alhpa = 0.5, | ||
node_color=[float(G.degree(v)) for v in G], | ||
cmap=plt.cm.Greens, | ||
) | ||
plt.show() | ||
|
||
if __name__ == "__main__": | ||
|
||
if not os.path.exists("position_snapshot.csv"): | ||
print "please download the Last Hope data set unto the same directory as this file" | ||
print "the last hope data set can be found at http://crawdad.org/meta.php?name=hope/amd " | ||
else : | ||
show_ping_graph() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
def print_cliques(): | ||
|
||
cliques = sorted(nx.find_cliques(G),key=len,reverse=True)[:10] | ||
for c in cliques: | ||
c = filter(lambda x: name[x] is not "",c) | ||
print map(lambda x: name[x], c) | ||
|
||
|
||
def print_reachable(): | ||
parts = nx.connected_components(G) | ||
for p in parts[:10]: | ||
p = filter(lambda x: name[x] is not "",p) | ||
print map(lambda x: name[x], p) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env python | ||
import networkx as nx | ||
import csv | ||
import matplotlib.pylab as plt | ||
import os.path | ||
|
||
## Example by Rob Zinkov | ||
## minor updates by Far McKon | ||
|
||
|
||
def show_ping_graph(): | ||
reader = csv.reader(file("ping.csv")) | ||
headers = reader.next() | ||
|
||
G = nx.Graph() | ||
|
||
for line in reader: | ||
G.add_edge(line[0],line[1]) | ||
|
||
nx.draw_spring(G, | ||
node_color=[float(G.degree(v)) for v in G], | ||
node_size=40, | ||
with_labels=False, | ||
cmap=plt.cm.Reds, | ||
) | ||
plt.show() | ||
|
||
if __name__ == "__main__": | ||
|
||
if not os.path.exists("ping.csv"): | ||
print "please download the Last Hope data set unto the same directory as this file" | ||
print "the last hope data set can be found at http://crawdad.org/meta.php?name=hope/amd " | ||
else : | ||
show_ping_graph() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
print "pygames will not install on my 10.6 snowlepoard machine." | ||
print "a pygames test/interface/show is left as an exercize to the reader." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.