graphs, edges & nodes: untangling the social web

81
Graphs, Edges & Nodes Untangling the social web. Wednesday, March 9, 2011

Upload: confoo

Post on 11-May-2015

4.571 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Graphs, Edges & Nodes: Untangling the Social Web

Graphs, Edges & Nodes

Untangling the social web.

Wednesday, March 9, 2011

Page 2: Graphs, Edges & Nodes: Untangling the Social Web

What’s a graph?

Wednesday, March 9, 2011

Page 3: Graphs, Edges & Nodes: Untangling the Social Web

Graph

Wednesday, March 9, 2011

Page 4: Graphs, Edges & Nodes: Untangling the Social Web

Graph

Wednesday, March 9, 2011

Page 5: Graphs, Edges & Nodes: Untangling the Social Web

Graph

Wednesday, March 9, 2011

Page 6: Graphs, Edges & Nodes: Untangling the Social Web

Graph

6

73

14

6

4

3

1

4

5 7

13

4

199

12

157 2

10

9

Wednesday, March 9, 2011

Page 7: Graphs, Edges & Nodes: Untangling the Social Web

Graph

6

73

14

6

4

3

1

4

5 7

13

4

199

12

157 2

10

9 13

12

19

10

15

6

11 10

8

17

4

6

2

21

22

9

3

Wednesday, March 9, 2011

Page 8: Graphs, Edges & Nodes: Untangling the Social Web

Simple

At most one edge between any pair of nodes.

Wednesday, March 9, 2011

Page 9: Graphs, Edges & Nodes: Untangling the Social Web

Multigraph

Multiple edges between vertices allowed.

Wednesday, March 9, 2011

Page 10: Graphs, Edges & Nodes: Untangling the Social Web

Pseudograph

Self-loops are permitted.

Wednesday, March 9, 2011

Page 11: Graphs, Edges & Nodes: Untangling the Social Web

G = (V, E)

Wednesday, March 9, 2011

Page 12: Graphs, Edges & Nodes: Untangling the Social Web

Wednesday, March 9, 2011

Page 13: Graphs, Edges & Nodes: Untangling the Social Web

What’s a node?

vertexpoint

junction0-simplex

Wednesday, March 9, 2011

Page 14: Graphs, Edges & Nodes: Untangling the Social Web

Wednesday, March 9, 2011

Page 15: Graphs, Edges & Nodes: Untangling the Social Web

Wednesday, March 9, 2011

Page 16: Graphs, Edges & Nodes: Untangling the Social Web

What’s an edge?

arcbranch

linelink

1-simplex

Wednesday, March 9, 2011

Page 17: Graphs, Edges & Nodes: Untangling the Social Web

Directed

Wednesday, March 9, 2011

Page 18: Graphs, Edges & Nodes: Untangling the Social Web

Wednesday, March 9, 2011

Page 19: Graphs, Edges & Nodes: Untangling the Social Web

Wednesday, March 9, 2011

Page 20: Graphs, Edges & Nodes: Untangling the Social Web

Undirected

Wednesday, March 9, 2011

Page 21: Graphs, Edges & Nodes: Untangling the Social Web

Undirected

Wednesday, March 9, 2011

Page 22: Graphs, Edges & Nodes: Untangling the Social Web

Wednesday, March 9, 2011

Page 23: Graphs, Edges & Nodes: Untangling the Social Web

Wednesday, March 9, 2011

Page 24: Graphs, Edges & Nodes: Untangling the Social Web

Wednesday, March 9, 2011

Page 25: Graphs, Edges & Nodes: Untangling the Social Web

Wednesday, March 9, 2011

Page 26: Graphs, Edges & Nodes: Untangling the Social Web

Data Structures

Wednesday, March 9, 2011

Page 27: Graphs, Edges & Nodes: Untangling the Social Web

1

2

4

3

(Finite simple graph)

Wednesday, March 9, 2011

Page 28: Graphs, Edges & Nodes: Untangling the Social Web

Adjacency Matrix(2d array)

0 1 1 1

1 0 0 0

1 0 0 1

1 0 1 0

vertices

vertices

Wednesday, March 9, 2011

Page 29: Graphs, Edges & Nodes: Untangling the Social Web

Adjacency Matrix(2d array)

0 1 1 1

1 0 0 0

1 0 0 1

1 0 1 0

vertices

vertices

Wednesday, March 9, 2011

Page 30: Graphs, Edges & Nodes: Untangling the Social Web

1

2

4

3

(Finite simple graph)

Wednesday, March 9, 2011

Page 31: Graphs, Edges & Nodes: Untangling the Social Web

[1, 2, 3, 4]234

1 14

13

Array entries (vertices) point to singly linked-lists

Wednesday, March 9, 2011

Page 32: Graphs, Edges & Nodes: Untangling the Social Web

Visualizations

Wednesday, March 9, 2011

Page 33: Graphs, Edges & Nodes: Untangling the Social Web

You are here.

Wednesday, March 9, 2011

Page 34: Graphs, Edges & Nodes: Untangling the Social Web

Wednesday, March 9, 2011

Page 35: Graphs, Edges & Nodes: Untangling the Social Web

(Graph does not include Justin Bieber)

Wednesday, March 9, 2011

Page 36: Graphs, Edges & Nodes: Untangling the Social Web

Social Graphs

Wednesday, March 9, 2011

Page 37: Graphs, Edges & Nodes: Untangling the Social Web

Wednesday, March 9, 2011

Page 38: Graphs, Edges & Nodes: Untangling the Social Web

Wednesday, March 9, 2011

Page 39: Graphs, Edges & Nodes: Untangling the Social Web

Wednesday, March 9, 2011

Page 40: Graphs, Edges & Nodes: Untangling the Social Web

Wednesday, March 9, 2011

Page 41: Graphs, Edges & Nodes: Untangling the Social Web

Wednesday, March 9, 2011

Page 42: Graphs, Edges & Nodes: Untangling the Social Web

Wednesday, March 9, 2011

Page 43: Graphs, Edges & Nodes: Untangling the Social Web

Wednesday, March 9, 2011

Page 44: Graphs, Edges & Nodes: Untangling the Social Web

Wednesday, March 9, 2011

Page 45: Graphs, Edges & Nodes: Untangling the Social Web

Wednesday, March 9, 2011

Page 46: Graphs, Edges & Nodes: Untangling the Social Web

User-based item recommendations

Wednesday, March 9, 2011

Page 47: Graphs, Edges & Nodes: Untangling the Social Web

People

Recommend items to me that are popular amongst my friends

Wednesday, March 9, 2011

Page 48: Graphs, Edges & Nodes: Untangling the Social Web

People

Recommend items to me that are popular amongst my friends

(friends)

Wednesday, March 9, 2011

Page 49: Graphs, Edges & Nodes: Untangling the Social Web

People

Recommend items to me that are popular amongst my friends

Items

(friends)

Wednesday, March 9, 2011

Page 50: Graphs, Edges & Nodes: Untangling the Social Web

People

Recommend items to me that are popular amongst my friends

Items

(friends)

Wednesday, March 9, 2011

Page 51: Graphs, Edges & Nodes: Untangling the Social Web

People

Recommend items to me that are popular amongst my friends

(friends)(me)

Items

Wednesday, March 9, 2011

Page 52: Graphs, Edges & Nodes: Untangling the Social Web

People

Recommend items to me that are popular amongst my friends

(friends)(me)

Items

Wednesday, March 9, 2011

Page 53: Graphs, Edges & Nodes: Untangling the Social Web

People

Recommend items to me that are popular amongst my friends

(friends)(me)

Items

Wednesday, March 9, 2011

Page 54: Graphs, Edges & Nodes: Untangling the Social Web

2-step path on homogeneous bipartitegraph.

Wednesday, March 9, 2011

Page 55: Graphs, Edges & Nodes: Untangling the Social Web

Strong Connection Problem (SCP)

Wednesday, March 9, 2011

Page 56: Graphs, Edges & Nodes: Untangling the Social Web

There are many of these ‘fundamental’ graph units:

- tripartite graphs (user/asset/tag)- folksonomies- multicolor-multiparity graph- etc.

Wednesday, March 9, 2011

Page 57: Graphs, Edges & Nodes: Untangling the Social Web

Graph Storage Engines

Wednesday, March 9, 2011

Page 58: Graphs, Edges & Nodes: Untangling the Social Web

Neo4j“An embedded, disk-based, fully transactional Java persistence engine that

stores data structured in graphs rather than in tables.”

http://neo4j.org

Wednesday, March 9, 2011

Page 59: Graphs, Edges & Nodes: Untangling the Social Web

HypergraphDB“A general purpose, extensible, portable, distributed, embeddable, open-source

data storage mechanism. It is a graph database designed specifically for artificial intelligence and semantic web projects.”

http://kobrix.org/hgdb.jsp

Wednesday, March 9, 2011

Page 60: Graphs, Edges & Nodes: Untangling the Social Web

Special Purpose Storage Engines

Wednesday, March 9, 2011

Page 61: Graphs, Edges & Nodes: Untangling the Social Web

FlockDB“FlockDB is a database that stores graph data, but it isn't a database

optimized for graph-traversal operations. Instead, it's optimized for very large adjacency lists, fast reads and writes, and page-able set arithmetic

queries.”

http://engineering.twitter.com/2010/05/introducing-flockdb.html

Wednesday, March 9, 2011

Page 62: Graphs, Edges & Nodes: Untangling the Social Web

Redis“Redis is an advanced key-value store. [...] the dataset is not volatile, and values can be strings, exactly like in memcached, but also lists, sets, and ordered sets. All this data types can be manipulated with atomic operations to push/pop elements, add/remove elements, perform server side union, intersection, difference between sets, etc.”

http://code.google.com/p/redis

Wednesday, March 9, 2011

Page 63: Graphs, Edges & Nodes: Untangling the Social Web

A Redis Friends/Followers Example

Wednesday, March 9, 2011

Page 64: Graphs, Edges & Nodes: Untangling the Social Web

Redis makes you think in terms of datastructures,and operations on those structures.

Wednesday, March 9, 2011

Page 65: Graphs, Edges & Nodes: Untangling the Social Web

Set:Finite (for our cases) collection of objects in which order has no significance and multiplicity is generally ignored.

S = { Alice, Bob, Carol }

List:Finite (for our cases) collection of objects in which order *is* significant and multiplicity is allowed.

L = [ X, Y, X, Z, Q]

Wednesday, March 9, 2011

Page 66: Graphs, Edges & Nodes: Untangling the Social Web

SET uid:1000:username jperras

Insert a user into a set

Command Key Value

Wednesday, March 9, 2011

Page 67: Graphs, Edges & Nodes: Untangling the Social Web

Use sets for denoting my followers/peopleI follow.

Wednesday, March 9, 2011

Page 68: Graphs, Edges & Nodes: Untangling the Social Web

SADD uid:1000:following 1001SADD uid:1001:followers 1000

Adding a new follower

Command Key Value

Wednesday, March 9, 2011

Page 69: Graphs, Edges & Nodes: Untangling the Social Web

Posting Updates

$r = Redis();$postid = $r->incr("global:nextPostId");$post = $User['id'] ."|". time() ."|". $status;$r->set("post:$postid", $post);$followers = $r->smembers("uid:".$User['id'].":followers");

if ($followers === false) $followers = Array();$followers[] = $User['id']; /* Add the post to our own posts too */

foreach($followers as $fid) {    $r->push("uid:$fid:posts", $postid, false);}# Push the post on the timeline, and trim the timeline to the# newest 1000 elements.$r->push("global:timeline", $postid, false);$r->ltrim("global:timeline",0,1000);

Wednesday, March 9, 2011

Page 70: Graphs, Edges & Nodes: Untangling the Social Web

Common followers? - Set intersections!

SINTER users:1000:followers users:1000:followers

Command Key 1 Key 2

Wednesday, March 9, 2011

Page 71: Graphs, Edges & Nodes: Untangling the Social Web

A MySQL Example

(simplified)

Wednesday, March 9, 2011

Page 72: Graphs, Edges & Nodes: Untangling the Social Web

# Mutual Friendsselect f.friend_id from friends f join friends m on m.user_id = f.friend_id and m.friend_id = f.user_idwhere f.user_id = 1234

# Following (for directed graphs)select f.friend_id from friends f left join friends m on m.user_id = f.friend_id and m.friend_id = f.user_id where f.user_id = 1234 and m.user_id is null;

# Followers (for directed graphs)select m.friend_id from friends f left join friends m on m.user_id = f.friend_id and m.friend_id = f.user_id where f.friend_id = 1234 and m.user_id is null

Wednesday, March 9, 2011

Page 73: Graphs, Edges & Nodes: Untangling the Social Web

Not too bad.

# Mutual Friendsselect f.friend_id from friends f join friends m on m.user_id = f.friend_id and m.friend_id = f.user_idwhere f.user_id = 1234

# Following (for directed graphs)select f.friend_id from friends f left join friends m on m.user_id = f.friend_id and m.friend_id = f.user_id where f.user_id = 1234 and m.user_id is null;

# Followers (for directed graphs)select m.friend_id from friends f left join friends m on m.user_id = f.friend_id and m.friend_id = f.user_id where f.friend_id = 1234 and m.user_id is null

Wednesday, March 9, 2011

Page 74: Graphs, Edges & Nodes: Untangling the Social Web

Relational databases can work for the simplestof cases, but are not always the best solution for

many graph operations/algorithms.

Wednesday, March 9, 2011

Page 75: Graphs, Edges & Nodes: Untangling the Social Web

Graphs and graph-databases are onlygoing to be more and more useful.

Wednesday, March 9, 2011

Page 76: Graphs, Edges & Nodes: Untangling the Social Web

However, graph algorithms are hard.

So don’t write your own.

And make sure you use a persistent storage enginethat is best suited for the type of queries

you will be performing.

Wednesday, March 9, 2011

Page 77: Graphs, Edges & Nodes: Untangling the Social Web

Resources

Wednesday, March 9, 2011

Page 78: Graphs, Edges & Nodes: Untangling the Social Web

The Algorithm Design Manual, Steve S. Skiena

Programming Collective Intelligence, Toby Segaran

Introduction to Algorithms, Cormen, Leiserson, Rivest

Resources

Wednesday, March 9, 2011

Page 79: Graphs, Edges & Nodes: Untangling the Social Web

@jperras

Wednesday, March 9, 2011

Page 80: Graphs, Edges & Nodes: Untangling the Social Web

Graph of the internet, circa 2003: http://www.duniacyber.com/freebies/education/what-is-internet-lookslike/ (built from partial troll of public servers using traceroute)

My real friends for letting me use their Facebook profile images.

Photo Credits

Wednesday, March 9, 2011

Page 81: Graphs, Edges & Nodes: Untangling the Social Web

Large Scale Graph Algorithms (class lectures), Yuri Lifshits, Steklov Institute of Mathematics at St. Petersburg

http://mathworld.wolfram.com/Set.html

Programming Collective Intelligence, Toby Segaran

The Algorithm Design Manual, Steve S. Skiena

References

Wednesday, March 9, 2011