49
Counting Triangles and other Subgraphs in Data Streams Stefano Leonardi 1 Joint work with: Luciana Salete Buriol 2 , Gereon Frahling 3 , Alberto Marchetti-Spaccamela 1 , Christian Sohler 4 1 Univ. of Rome “La Sapienza” 2 Univ. of Porto Alegre 3 Google 4 Heinz Nixdorf Institute, Univ. of Paderborn

Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

Counting Triangles and other Subgraphsin Data Streams

Stefano Leonardi1

Joint work with: Luciana Salete Buriol2, Gereon Frahling3, Alberto

Marchetti-Spaccamela1, Christian Sohler4

1 Univ. of Rome “La Sapienza”2 Univ. of Porto Alegre

3Google4 Heinz Nixdorf Institute, Univ. of Paderborn

Page 2: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

Counting Subgraphs

Several applications:

– Network analysis: Computation of indices, e.g. the clusteringcoefficient

– Network modelling: Frequent small subgraphs or motifs areconsidered as building blocks of universal classes of complexnetworks [Itzkovits et al, Science 298]

– Community detection: Occurrence of a large number of specificsubgraphs, e.g. bipartite cliques, has been observed in theWebgraph [Kumar et al, 1999]

– Indexing: identify the most frequent patterns in a graphicaldatabase [Yan, Yu and Han, 2004]

Page 3: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

Most basic problem:Counting Triangles in a Graph

• Exact computation reduces to matrix multiplication:unfeasible for networks even of medium size

• Several heuristics have been proposed and tested(Schank and Wagner, 2005, Latapy 2006)

• Resort to the Data Stream Model:

• Data arrives one item at a time. The algorithmshave the task of handling the computation in smallspace and computational time per item.

Page 4: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

Main applications:

• When the streams are not stored and must be processed on thefly as they are produced (more than 20 exabytes are createdevery year, most of them are forgotten);

• When the memory or time for storing or processing the streamis limited;

• When an exact computation is too time consuming and just agood estimation of the underlying data is required.

Page 5: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

Data Stream Sampling Algorithms

• Selection of a subset of items and check some specificproperty on them;

• Define the kind of sample and the sample size

• Results: Algorithms that produce an (1±ε)approximation of the number of subgraphs in the graphwith probability at least 1-δ by using O(s) memory cells

• s is usually the number of samples needed to achieve agiven precision

Page 6: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

Counting Triangles in Data Streams

Let’s T0, T1, T2 and T3 represent the set of triples that have 0, 1, 2 and 3 edges, respectively.

• Given a graph G=(V,E), where V is the set of verticesand E the set of edges, consider all triples of nodesof V;

• We can find four type of structures depending on thenumber of edges connecting them

Page 7: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

Naive Sampling

• r independent samples of three distinct vertices(a,b,c) from the graph

• For the ith sample, if (a,b,c) is a triangle thenoutput βi=1 else output βi=0.

• E[βi] = T3 / (T0 +T1 + T2 + T3 )

• T3 = (T0 +T1 + T2 + T3 ) = (|V|*|V-1|*|V-2|) / 6

Page 8: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

Naive sampling

• Use Σi βi/r as an estimator of E[βi]

• Output T’3 = T3 * Σi βi/r

• By Chernoff bounds:

• If r= O(log (1/ δ) 1/ε2 ((T0 +T1 + T2 + T3 ) / T3))

then (1-ε) T3 <T’3 < T3 (1+ ε) with pb > 1- δ

• Number of samples is prohibitive if T3= o(n2)

Page 9: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

The Graph as a Stream

• Adjancency Stream model: Each item of the stream is an arc ofthe graph

Depending on the application, we can consider some order in thestream.

• Incidence Stream model: The entire incidence list of outgoingarcs of each node is extracted consecutively.

Page 10: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

Our result for the Adjacency Streammodel

Previous best results:

s=O(log (1/ δ) 1/ε2 ((T1 + T2 + T3 )3 / T3) log |V|)

[Bar-Yossef, Kumar and Sivakumar, Reductions inStreaming Algorithms, with an Application to CountingTriangles in Graphs, SODA 2002]

Theorem 1: There exists a 1-pass streaming algorithmwhich needs s=O(log (1/ δ) 1/ε2 ((T1 + T2 + T3 ) / T3))memory cells and O(1+ s log |E|/|E|)) update time peritem

Page 11: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

Idea of the algorithm for the Adjacency Stream model

• We take an edge e=(a,b) ∈ E and a node v ∈V \ {a,b}, and look for the missing edges.

• The following property holds for any graph:

T1 + 2T2 + 3T3 = |E|(|V|-2)

• Triples belonging to T0 are not considered.

?

?a

b

v|E|(|V|-2)

Page 12: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

A 3-pass streaming algorithm

1. 1st Pass: count the number of edges |E| in thestream

2. 2nd Pass: sample an edge e=(a,b) uniformly chosenamong all edges from the stream.Choose a node v uniformly from V\{a,b}

3. 3rd Pass: Test if edges (a,v) and (b,v) are presentin the stream.If (a,v) ∈ E and (b,v) ∈ E then output β=1 elseoutput β=0.

Page 13: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

A 3-pass streaming algorithm

• The streaming algorithm outputs a value βhaving expected value:

321

3

32

3][

TTT

TE

++=!

3

)2|(|||].[3

!=

VEET

"

• Furthermore:

Page 14: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

A 3-pass streaming algorithm

• There is a streaming algorithm that outputs avalue T’3 satisfying (1-ε) T <T’ < T (1+ ε) withprobability 1-δ

• We start r parallel instances of the 3-passalgorithm, and each one outputs a value βi

)1

ln(322

3

321

2 !" T

TTTr

++=

Page 15: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

A 3-pass streaming algorithm

• We use as an estimator for

• We estimate T3 as:

! =

r

i i

r1

1"

!

T '3 =1

r"i

i=1

r

#$

% &

'

( ) .| E | (|V |*2)

3

321

3

32

3][

TTT

TE

++=!

Page 16: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

A 3-pass streaming algorithm

• Proof by Chernoff Bounds

• Setting

both probabilities together are bounded by δ

3/].[.

1

2

][)1(1

Pr rEr

i ieE

r

!"!"! #

=$%&

'()

*++,

2/].[.

1

2

][)1(1

Pr rEr

i ieE

r

!"!"! #

=$%&

'()

*#$+

)1

ln(322

3

321

2 !" T

TTTr

++=

Page 17: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

A 3-pass streaming algorithm

• We suppose that the events within the brackets donot occur. In this case:

• Same argument to obtain

][)1(1

1

!"! Er

r

i

i+<#

=

3

)2|(|||][)1(

3

)2|(|||1

1

!+<

!" #

=

VEE

VE

r

r

i

i$%$

!

" T '3< (1+ #)T

3

!

" T '3> (1+ #)T

3

Page 18: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

One pass algorithm

• A uniform choice of an edge in one pass can be donewith reservoir sampling: choose the first edge as asample edge and replacing this edge by the i-th edgeof the stream with probability 1/i.

• When choosing a sample, it can happen that wealready miss some arcs. We have 1/3 of probability ofnot doing that.

Page 19: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

Sample one-pass

i←1;for each edge es=(as,bs) in the stream do:

flip a coin. With probability 1/i do:a ← as; b ← bs;v ← node uniformly chosen from V \ {a,b}x ←false; y ←false;

end do

if es = (a,v) then x ←true;If es = (b,v) then y ←true;

end forif x=true and y=true return β=1 else return β=0

a

b

v

Page 20: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

Sample one-pass

321

3

32

3][

TTT

TE

++=!

• The streaming algorithm outputs a value b havingexpected value:

)1

ln(326

3

321

2 !" T

TTTr

++=

• The size of the sample

!

3T ' =1

r"i

i=1

r

#$

% &

'

( ) . | E | (|V |*2)

• We estimate T3 as:

Page 21: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

Results for a sample set of size 100

Page 22: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

Considering a structured stream

• Which kind of structure can benefit the algorithm and still be anatural and good representation of the graph?

• Consider the Incidence Stream model, where the adjacency listsof nodes are stored in sequence in the stream

• No order is required within each adjacency list

• Each arc is seen twice in the stream

Page 23: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

Results on Incidence Stream

• Our result:

• Previous best results from Yossef, Kumar andSivakumar: Reductions in Streaming Algorithms, withan Application to Counting Triangles in Graphs, 2002

!!"

#$$%

&!!"

#$$%

&+!

"

#$%

&

3

2

21.

1log.

1

T

TO

'(

!

O1

"2.log

1

#

$

% & '

( ) . 1+

T2

T3

$

% &

'

( )

2

logn + d logn

$

%

& &

'

(

) )

Page 24: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

Incidence streams

• Sample from all possible Vs, i.e., combinations of two arcs leavinga node

• For each node i, where di is its degree, the number of V’s, havingnode i in common is:

i i

A V

!"

#$%

& '=!!

"

#$$%

&

2

1.

2

i

i

i dd

d

Page 25: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

Counting triangles in incidence streams

• In this case our sample is a V, and we check if thethird arc is later seen in the stream

• It holds for any graph:

! ="#

$%&

' (=+

||

1322

1.3

V

i

i

i

ddTT

Page 26: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

Incidence 3-pass algorithm

• 1st Pass: count the number of Vs of the stream

• 2nd Pass: uniformly choose one V among all of them.Let us call it (a,b,c)

• 3rd Pass: Test if edge (a,c) is present in the stream.If (a,c) ∈ E then output β=1 else output β=0;

a

bc

Page 27: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

Computational Experiments

• Optimized implementation of the algorithms

• Experiments on large Webgraphs, Wikigraphs,collaboration between scientists and actors

• Adjacency list model: accurate estimation fors = 106

• Incidence list model: accurate estimation fors = 104

Page 28: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

Results for the Incidence List model

Page 29: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

Dimension of somegraphs extracted from

different sorces

Number of trianglesof the graphs

Page 30: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

Comparing with the optimal computation[Schank and Wagner, 2004]

Page 31: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

Clustering Coefficient

• Graph G = (V, E) V: set of n vertices E: set of m edges

• N(v) = set of vertices adjacent to v

•Local Clustering Coefficient of vertex

probability that any two vertices in N(v) are connected

C(v) = |{(u,v) ∈ E : u,v ∈ N(v) }|/ (N(v) *( N(v) -1))/2)

•Clustering Coefficient of a graph:

C(G)= 1/n ∑ C(v)

V

C(v)=3/6

Page 32: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

Transitivity Coefficient

• Transitivity Coefficient:

probability that any two vertices adjacent to a third vertex inthe graph are connected

T(G) = ∑v|{(u,w) ∈ E : u,w ∈ N(v) }|/ (∑v N(v) *( N(v) -1))/2)

• Reduce to counting numberof triangles in the graph

T(G)=9/14

Page 33: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

Computing the Clustering Coefficient

• Our results:There is a 1-pass streaming algorithm whichwith pb (1-δ) returns an ε-approximation ofC(G) when the graph is given as an incidencestream that uses

O(log (1/ δ) log n/ ε2 C(G)) memory cells.

• C(G) is usually in [10-1,10-5]: feasible fornetworks of any size.

Page 34: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

A 2-pass streaming algorithm

1. Sample s vertices w1, ….., ws.

2. for i = 1 to s do

sample at random pair (u,v), u ≠ v, of points of N(wi)

If (u,v) ∈ E then Xi = 1else Xi = 0

3. Output X= 1/s ∑i Xi

Page 35: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

Counting k3,3 in Data Streams

• Let k3,3 denote the number of k3,3 minorsand k3,1 denote the number of k3,1 minors

• We assume the outdegree of the graphbounded by d

• The edges are sorted by destination nodes• We do not assume any order by source nodes

Page 36: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

Sample

• Sample a k3,1 and 2 nodes not belonging tothe k3,1

w

v

b

c

a

u

Page 37: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

Counting k3,3 in Data Streams

b

c

a

u

• From all k3,1 occuring in the stream, chose oneuniformly

• Let the three edges be (a,u), (b,u) and (c,u)

Page 38: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

Counting k3,3 in Data Streams

• From all k3,1 occuring in the stream, chose one uniformly• Let the three edges be (a,u), (b,u) and (c,u)• Select uniformly x1, x2 ∈ {a,b,c}• Choose uniformly random variables k1, k2 ∈ {1,2,…,d}• If k1=k2 and x1=x2 then output β = 0• Go on passing over the stream• Select the (x1,v) as the k1-th edge (x1, ) after selecting the k3,1

v

b

x1

a

u

c

x2

Page 39: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

Counting k3,3 in Data Streams

• From all k3,1 occuring in the stream, chose one uniformly• Let the three edges be (a,u), (b,u) and (c,u)• Select uniformly x1, x2 ∈ {a,b,c}• Choose uniformly random variables k1, k2 ∈ {1,2,…,d}• If k1=k2 and x1=x2 then output β = 0• Go on passing over the stream• Select the (x1,v) as the k1-th edge (x1, ) after selecting the k3,1• Select the (x2,w) as the k2-th edge (x2, ) after selecting the

k3,1

v

b

c

a

u

w x2

x1

Page 40: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

Counting k3,3 in Data Streams

• From all k3,1 occuring in the stream, chose one uniformly• Let the three edges be (a,u), (b,u) and (c,u)• Select uniformly x1, x2 ∈ {a,b,c}• Choose uniformly random variables k1, k2 ∈ {1,2,…,d}• If k1=k2 and x1=x2 then output β = 0• Go on passing over the stream• Select the (x1,v) as the k1-th edge (x1, ) after selecting the k3,1• Select the (x2,w) as the k2-th edge (x2, ) after selecting the

k3,1• From the time of selecting (x1,v): check if (a,v), (b,v), (c,v) are

present in the stream

v c

w

b

a

u

Page 41: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

One-pass algorithm

• From the time of selecting (x2,w): check if (a,w), (b,w), (c,w) arepresent in the stream

• In this case output β = 1 else output β = 0

• From all k3,1 occuring in the stream, chose one uniformly• Let the three edges be (a,u), (b,u) and (c,u)• Select uniformly x1, x2 ∈ {a,b,c}• Choose uniformly random variables k1, k2 ∈ {1,2,…,d}• If k1=k2 and x1=x2 then output β = 0• Go on passing over the stream• Select the (x1,v) as the k1-th edge (x1, ) after selecting the k3,1• Select the (x2,w) as the k2-th edge (x2, ) after selecting the

k3,1• From the time of selecting (x1,v): check if (a,v), (b,v), (c,v) are

present in the stream

Page 42: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

Probability of finding a k3,3

• The k3,3 will be chosen in case the following eventsoccur:– Nodes a,b,c,u are chosen as the k3,1 with u being the

destination node Pr = 1/k3,1– v and w must be chosen Pr = 1/d*1/d– x1 must be the first within the incidence list of v

Pr = 1/3– x2 must be the first within the incidence list of w

Pr = 1/3

Page 43: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

Counting k3,3 in Data Streams

• The algorithm outputs a value β such that:

1,3

2

3,3

9][

kd

kE =!

The following property holds for any graph:

!=

""=##

$

%&&'

(=

||

1 6

)2)(1(

31,3

V

i

iiii ddddk

Page 44: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

Counting k3,3 in Data Streams

• Number of samples:

• Approximation:

!"

1ln.

..

1

3,3

2

1,3

2k

dkr =

!!"

#$$%

&!!"

#$$%

&''!

"

#$%

&= ((

== 6

9.)2).(1.(.

1~2||

113,3

dddd

rK

V

i

iiii

r

i)

Page 45: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

1-Pass algorithm for counting K3,3

• There is a one pass algorithm that counts thenumber of k3,3 of a graph in incidencestreams ordered by destination nodes withoutdegree bounded by d up to a multiplicativeerror of ε with probability at least 1-δ, whichspace is

!!

"

#

$$

%

&

'(

1ln.

..

1|).log(|

3,3

2

1,3

2k

dkVO

Page 46: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

Counting other Subgraphs(with Ilaria Bordino and Debora Donato)

Page 47: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

Experimental results

Page 48: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

Experimental results

Page 49: Counting Triangles and other Subgraphs in Data Streams · –Network analysis: Computation of indices, e.g. the clustering coefficient –Network modelling: Frequent small subgraphs

Conclusions and Open Problems

• Random Sampling Data Stream Algorithms forcounting the number of some minors in a graph.

• Algorithms scale up to networks of any size for graphminors of size 3 and 4.

• Automatically select the best strategy for each givengraph minor

• Counting on streams of insertions and deletions