Graph Algorithms. Revised based on the slides by Ruoming Kent State

Similar documents
University of Maryland. Tuesday, March 2, 2010

Jordan Boyd-Graber University of Maryland. Thursday, March 3, 2011

Graph Data Processing with MapReduce

Link Analysis in the Cloud

Data-Intensive Computing with MapReduce

Data-Intensive Distributed Computing

COSC 6339 Big Data Analytics. Graph Algorithms and Apache Giraph

Big Data Infrastructure CS 489/698 Big Data Infrastructure (Winter 2017)

MapReduce Patterns. MCSN - N. Tonellotto - Distributed Enabling Platforms

Map-Reduce Applications: Counting, Graph Shortest Paths

Map-Reduce Applications: Counting, Graph Shortest Paths

Lecture 11: Graph algorithms! Claudia Hauff (Web Information Systems)!

TI2736-B Big Data Processing. Claudia Hauff

Graph Algorithms using Map-Reduce. Graphs are ubiquitous in modern society. Some examples: The hyperlink structure of the web

with MapReduce The ischool University of Maryland JHU Summer School on Human Language Technology Wednesday, June 17, 2009

Centralities (4) By: Ralucca Gera, NPS. Excellence Through Knowledge

Graph Algorithms. Chapter 5

Graphs. The ultimate data structure. graphs 1

CS6200 Information Retreival. The WebGraph. July 13, 2015

CC PROCESAMIENTO MASIVO DE DATOS OTOÑO Lecture 7: Information Retrieval II. Aidan Hogan

L22-23: Graph Algorithms

Unit VIII. Chapter 9. Link Analysis

Mining Web Data. Lijun Zhang

Graphs. The ultimate data structure. graphs 1

CSE 100: GRAPH ALGORITHMS

CS 310 Advanced Data Structures and Algorithms

Introduction To Graphs and Networks. Fall 2013 Carola Wenk

How to organize the Web?

Chapter 4. Distributed Algorithms based on MapReduce. - Applications

INTRODUCTION TO DATA SCIENCE. Link Analysis (MMDS5)

Laboratory Session: MapReduce

CMPUT 396 Sliding Tile Puzzle

CS224W: Social and Information Network Analysis Jure Leskovec, Stanford University

COP 4531 Complexity & Analysis of Data Structures & Algorithms

Implementing Mapreduce Algorithms In Hadoop Framework Guide : Dr. SOBHAN BABU

Graphs (Part II) Shannon Quinn

CS224W: Social and Information Network Analysis Jure Leskovec, Stanford University

Some Extra Information on Graph Search

22.1 Representations of graphs

CS224W: Social and Information Network Analysis Jure Leskovec, Stanford University

COMP 182: Algorithmic Thinking Prim and Dijkstra: Efficiency and Correctness

(Re)Introduction to Graphs and Some Algorithms

Algorithms: Lecture 10. Chalmers University of Technology

CS246: Mining Massive Datasets Jure Leskovec, Stanford University

Tutorial. Question There are no forward edges. 4. For each back edge u, v, we have 0 d[v] d[u].

Graphs and Graph Algorithms. Slides by Larry Ruzzo

Figure 1: A directed graph.

CS200: Graphs. Rosen Ch , 9.6, Walls and Mirrors Ch. 14

Outlines: Graphs Part-2

COMP 4601 Hubs and Authorities

3.1 Basic Definitions and Applications. Chapter 3. Graphs. Undirected Graphs. Some Graph Applications

Shortest Path Routing Communications networks as graphs Graph terminology Breadth-first search in a graph Properties of breadth-first search

Graphs. The ultimate data structure. graphs 1

Chapter 3. Graphs. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Lecture #3: PageRank Algorithm The Mathematics of Google Search

Mining Web Data. Lijun Zhang

Lecture Notes: Social Networks: Models, Algorithms, and Applications Lecture 28: Apr 26, 2012 Scribes: Mauricio Monsalve and Yamini Mule

Graphs Data Structures

Outline. Graphs. Divide and Conquer.

World Wide Web has specific challenges and opportunities

3.1 Basic Definitions and Applications

Routing Outline. EECS 122, Lecture 15

Big Data Infrastructure CS 489/698 Big Data Infrastructure (Winter 2017)

SELF-BALANCING SEARCH TREES. Chapter 11

Graphs. CSE 2320 Algorithms and Data Structures Alexandra Stefan and Vassilis Athitsos University of Texas at Arlington

Graphs. The ultimate data structure. graphs 1

Goals! CSE 417: Algorithms and Computational Complexity!

Scribes: Romil Verma, Juliana Cook (2015), Virginia Williams, Date: May 1, 2017 and Seth Hildick-Smith (2016), G. Valiant (2017), M.

Graph Algorithms. Chapter 22. CPTR 430 Algorithms Graph Algorithms 1

Chapter 3. A problem-solving agent is a kind of goal-based agent. It decide what to do by finding sequences of actions that lead to desirable states.

Information Networks: PageRank

Graph: representation and traversal

CS350: Data Structures Dijkstra s Shortest Path Alg.

Graphs & Digraphs Tuesday, November 06, 2007

Link Structure Analysis

CS 561, Lecture 10. Jared Saia University of New Mexico

Undirected Graphs. DSA - lecture 6 - T.U.Cluj-Napoca - M. Joldos 1

CMPE 150: Introduction to Computer Networks

CS425: Algorithms for Web Scale Data

Spanning Trees, greedy algorithms. Lecture 22 CS2110 Fall 2017

Data-Intensive Computing with MapReduce

Scalable Big Graph Processing in Map Reduce

Network Layer: Routing

Graphs. Terminology. Graphs & Breadth First Search (BFS) Extremely useful tool in modeling problems. Consist of: Vertices Edges

Algorithm Design and Analysis

Page rank computation HPC course project a.y Compute efficient and scalable Pagerank

UNIT Name the different ways of representing a graph? a.adjacencymatrix b. Adjacency list

The Shortest Path Problem

GRAPHS Lecture 17 CS2110 Spring 2014

3.1 Basic Definitions and Applications

Link Analysis and Web Search

PageRank and related algorithms

Data-Intensive Distributed Computing

CS200: Graphs. Prichard Ch. 14 Rosen Ch. 10. CS200 - Graphs 1

Chapter 10. Fundamental Network Algorithms. M. E. J. Newman. May 6, M. E. J. Newman Chapter 10 May 6, / 33

Big Data Infrastructure CS 489/698 Big Data Infrastructure (Winter 2016)

Graphs Introduction and Depth first algorithm

Algorithm Design (8) Graph Algorithms 1/2

Copyright 2000, Kevin Wayne 1

Social Network Analysis

Transcription:

Graph Algorithms Adapted from UMD Jimmy Lin s slides, which is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States. See http://creativecommons.org/licenses/by-nc-sa/3.0/us/ for details Revised based on the slides by Ruoming Jin @ Kent State 1

Outlines Graph problems and representations Parallel breadth first search PageRank 2

What s a graph? G = (V,E), where V represents the set of vertices (nodes) E represents the set of edges (links) Both vertices and edges may contain additional information Different types of graphs: Directed vs. undirected edges Presence or absence of cycles Graphs are everywhere: Hyperlink structure of the Web Physical structure of computers on the Internet Interstate highway system Social networks 3

4

Source: Wikipedia (Königsberg) 5

Some Graph Problems Finding shortest paths Routing Internet traffic and UPS trucks Finding minimum spanning trees Telco laying down fiber Finding Max Flow Airline scheduling Identify special nodes and communities Breaking up terrorist cells, spread of avian flu Bipartite matching Monster.com, Match.com And of course... PageRank 6

Graphs and MapReduce Graph algorithms typically involve: Performing computations at each node: based on node features, edge features, and local link structure Propagating computations: traversing the graph Key questions: How do you represent graph data in MapReduce? How do you traverse a graph in MapReduce? 7

Representing Graphs G = (V, E) Two common representations Adjacency matrix Adjacency list 8

Adjacency Matrices Represent a graph as an n x n square matrix M n = V M ij = 1 means a link from node i to j n1 n2 n3 n4 n2 n1 0 1 0 1 n1 n2 1 0 1 1 n3 n3 1 0 0 0 n4 1 0 1 0 n4

Adjacency Matrices: Critique Advantages: Amenable to mathematical manipulation Iteration over rows and columns corresponds to computations on outlinks and inlinks Disadvantages: Lots of zeros for sparse matrices Lots of wasted space 10

Adjacency Lists Take adjacency matrices and throw away all the zeros n1 n2 n3 n4 n1 0 1 0 1 n2 1 0 1 1 n3 1 0 0 0 n4 1 0 1 0 1: 2, 4 2: 1, 3, 4 3: 1 4: 1, 3

Adjacency Lists: Critique Advantages: Much more compact representation Easy to compute over outlinks Disadvantages: Much more difficult to compute over inlinks 12

Single Source Shortest Path Problem: find shortest path from a source node to one or more target nodes Shortest might also mean lowest weight or cost First, a refresher: Dijkstra s Algorithm 13

Dijkstra s Algorithm 1. Assign to every node a tentative distance value: set it to zero for our initial node and to infinity for all other nodes. 2. Mark all nodes unvisited. Create a set of all the unvisited nodes called the unvisited set. Set the initial node as current. 3. For the current node, consider all of its unvisited neighbors and calculate their tentative distances. Compare the newly calculated tentative distance with the current assigned value, and assign the smaller one. 4. When we are done considering all of the neighbors of the current node, mark the current node as visited and remove it from the unvisited set. A visited node will never be checked again. 5. If all of destination nodes have been marked visited or if the smallest tentative distance among the nodes in the unvisited set is infinity, then stop. The algorithm has finished. 6. Otherwise, select the unvisited node that is marked with the smallest tentative distance, set it as the new "current node", and go back to step 3. 14

Dijkstra s Algorithm Example n2 1 n4 10 0 2 3 9 4 6 n1 5 7 n3 2 n5 Example from CLR

Dijkstra s Algorithm Example n2 10 1 n4 10 0 2 3 9 4 6 n1 5 7 5 n3 2 n5 Example from CLR

Dijkstra s Algorithm Example n2 8 1 n4 14 10 0 2 3 9 4 6 n1 5 7 5 n3 2 7 n5 Example from CLR

Dijkstra s Algorithm Example n2 8 1 n4 13 10 0 2 3 9 4 6 n1 5 7 5 n3 2 7 n5 Example from CLR

Dijkstra s Algorithm Example n2 8 1 n4 9 10 0 2 3 9 4 6 n1 5 7 5 n3 2 7 n5 Example from CLR

Dijkstra s Algorithm Example n2 8 1 n4 9 10 0 2 3 9 4 6 n1 5 7 5 n3 2 7 n5 Example from CLR

Dijkstra s Algorithm

Single Source Shortest Path Problem: find shortest path from a source node to one or more target nodes Shortest might also mean lowest weight or cost Single processor machine: Dijkstra s Algorithm MapReduce: parallel Breadth First Search (BFS) 22

Finding the Shortest Path Consider simple case of equal edge weights (i.e., weight=1) Solution to the problem can be defined inductively Here s the intuition: Define: b is reachable from a if b is on adjacency list of a DISTANCETO(s) = 0 For all nodes p reachable from s, DISTANCETO(p) = 1 For all nodes n reachable from some other set of nodes M, DISTANCETO(n) = 1 + min(distanceto(m), m M) d 1 m 1 s d 2 m 2 n d 3 m 3

Visualizing Parallel BFS n 0 n 1 n 7 n 3 n 2 n 6 n 5 n 4 n 8 n 9

From Intuition to Algorithm Data representation: Key: node n Value: d (distance from start), adjacency list (list of nodes reachable from n) Initialization: for all nodes except for start node, d = Mapper: m adjacency list: emit (m, d + 1) Sort/Shuffle Groups distances by reachable nodes Reducer: Selects minimum distance path for each reachable node Additional bookkeeping needed to keep track of actual path 25

Multiple Iterations Needed Each MapReduce iteration advances the known frontier by one hop Subsequent iterations include more and more reachable nodes as frontier expands Multiple iterations are needed to explore entire graph Preserving graph structure: Problem: Where did the adjacency list go? Solution: mapper emits (n, adjacency list) as well 26

BFS Pseudo Code 27

Stopping Criterion How many iterations are needed in parallel BFS (equal edge weight case)? Convince yourself: when a node is first discovered, we ve found the shortest path Now answer the question... Six degrees of separation? Practicalities of implementation in MapReduce 28

Comparison to Dijkstra Dijkstra s algorithm is more efficient At any step it only pursues edges from the minimum cost path inside the frontier MapReduce explores all paths in parallel Lots of waste Useful work is only done at the frontier Why can t we do better using MapReduce? 29

Weighted Edges Now add positive weights to the edges Why can t edge weights be negative? Simple change: adjacency list now includes a weight w for each edge In mapper, emit (m, d + w p ) instead of (m, d + 1) for each node m That s it? 30

Stopping Criterion How many iterations are needed in parallel BFS (positive edge weight case)? Convince yourself: when a node is first discovered, we ve found the shortest path 31

Additional Complexities search frontier 1 r 10 n 6 n 7 n 8 1 1 1 n 5 n 9 n 1 s p q 1 1 1 n 4 n 1 2 n 3

Stopping Criterion How many iterations are needed in parallel BFS (positive edge weight case)? Practicalities of implementation in MapReduce 33

Graphs and MapReduce Graph algorithms typically involve: Performing computations at each node: based on node features, edge features, and local link structure Propagating computations: traversing the graph Generic recipe: Represent graphs as adjacency lists Perform local computations in mapper Pass along partial results via outlinks, keyed by destination node Perform aggregation in reducer on inlinks to a node Iterate until convergence: controlled by external driver Don t forget to pass the graph structure between iterations 34

A practical implementation Referenced from the following link http://www.johnandcailin.com/blog/cailin/breadt h first graph search using iterative map reducealgorithm A node is represented by a string as follows ID EDGES WEIGHTS DISTANCE_FROM_SOURCE COLOR 35

Three statuses of a node Unvisited Color white Being visited Color gray Visited Color black White Gray Black 36

The mappers All white nodes and black nodes simply reproduce themselves For each gray node (e.g., an exploding node) For each node n in the adjacency list, emit a gray node n null null distance of exploding node + weight gray Turn the color to black and emit itself ID edges weights distance from source black 37

The reducers Receive the data for all copies of each node Construct a new node for each node The non null list of edges and weights The minimum distance from the source The proper color 38

Choose the proper color If only receiving a copy of white node, color is white If only receiving a copy of black node, color is black If receiving copies consisting of white node and gray nodes, color is gray If receiving copies consisting of gray nodes and black node If minimum distance comes from black node, color is black Otherwise, color is gray 39

Random Walks Over the Web Random surfer model: User starts at a random Web page User randomly clicks on links, surfing from page to page Or, sometimes, user jumps to a random page PageRank Characterizes the amount of time spent on any given page Mathematically, a probability distribution over pages PageRank captures notions of page importance Correspondence to human intuition? One of thousands of features used in web search Note: query independent 40

PageRank: Defined Given page x with inlinks t 1 t n, where C(t i ) is the out-degree of t i, i.e., the number of outgoing links from t i is probability of random jump N is the total number of nodes in the graph 1 PR( x) (1 ) N n i i 1 C( ti ) PR( t ) t 1 X t 2 t n

Computing PageRank Properties of PageRank Can be computed iteratively Effects at each iteration are local Sketch of algorithm (ignoring random jump): Start with seed PR i values Each page distributes PR i mass to all pages it links to Each target page adds up mass from multiple inbound links to compute PR i+1 Iterate until values converge 42

Sample PageRank Iteration (1) Iteration 1 n 2 (0.2) n 2 (0.166) n 1 (0.2) 0.1 0.1 0.1 n 1 (0.066) 0.1 0.066 0.066 0.066 n 5 (0.2) 0.2 0.2 n 3 (0.2) n 5 (0.3) n 3 (0.166) n 4 (0.2) n 4 (0.3)

Sample PageRank Iteration (2) Iteration 2 n 2 (0.166) n 2 (0.133) n 1 (0.066) 0.033 0.083 0.083 n 1 (0.1) 0.033 0.1 0.1 0.1 n 5 (0.3) 0.3 0.166 n 3 (0.166) n 5 (0.383) n 3 (0.183) n 4 (0.3) n 4 (0.2)

PageRank in MapReduce n 1 [n 2, n 4 ] n 2 [n 3, n 5 ] n 3 [n 4 ] n 4 [n 5 ] n 5 [n 1, n 2, n 3 ] Map n 2 n 4 n 3 n 5 n 4 n 5 n 1 n 2 n 3 n 1 n 2 n 2 n 3 n 3 n 4 n 4 n 5 n 5 Reduce n 1 [n 2, n 4 ] n 2 [n 3, n 5 ] n 3 [n 4 ] n 4 [n 5 ] n 5 [n 1, n 2, n 3 ]

PageRank Pseudo Code 46

Complete PageRank Two additional complexities What is the proper treatment of dangling nodes? How do we factor in the random jump factor? 47

Dangling nodes A dangling node is a node that has no outgoing edges The adjacency list is empty t 1 X t 2 The PageRank mass of a dangling node will get lost during the mapper stage due to the lack of outgoing edges Solution Reserve a special key (i.e., a special node id) for storing PageRank mass from dangling nodes Mapper: dangling nodes emit the mass with the special key Reducer: sum up all the missing mass with the special key t n

Second pass Second pass to redistribute missing PageRank mass and account for random jumps 1 p ' (1 ) G p is PageRank value from the first pass, p' is updated PageRank value G is the number of nodes in the graph m is the combined missing PageRank mass m G p 49

Complete PageRank One iteration of PageRank requires two passes (i.e., two MapReduce jobs) The first to distribute PageRank mass along graph edges Also take care of the missing mass due to dangling nodes The second to redistribute the missing mass and take into account the random jump factor This job requires no reducers 50

PageRank Convergence Convergence criteria Iterate until PageRank values don t change Fixed number of iterations Convergence for web graphs? 52 iterations for a graph with 322 million edges It is very meaningful for today s web Full of spam and cheating sites 51

Beyond PageRank Link structure is important for web search PageRank is one of many link based features: HITS, SALSA, etc. One of many thousands of features used in ranking Adversarial nature of web search Link spamming Spider traps Keyword stuffing 52