11.07.2015 Views

Sample solution to Homework 2

Sample solution to Homework 2

Sample solution to Homework 2

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Aufgabe 2:A degree of funIn G, calculate exactly:1) the expected degree of a UIS node (i.e., the average node degree),2) the expected average degree of neighbors of a UIS node,3) the expected degree of a WIS node,4) the expected degree of end-nodes of a UIS edge.Verify all of the above by sampling. Finally, implement RW and report the observed average node degree.Summarize the exact and sampled expected degrees in a table. Show how the variance of each sampleevolves with sample size, using, for example, box plots.Solution:N = number of nodes, E = number of edges, d i = degree of node iUISnUISWISeUISFormula Form. result <strong>Sample</strong> result∑E[D UIS ] = N 1N · d i 4.726 4.734i=1 ( )∑E[D nUIS ] = N d i1∑1N d j· d i 13.210 13.198i=1E[D WIS ] = N ∑i=1E[D eUIS ] = N ∑i=1j=1d PN i· dj=1 d i 11.604 11.596jd i2E · d i 11.604 11.650RW – – 11.6051412degree statistics1086UISnUISWISeUISRW420 1000 2000 3000 4000 5000 6000 7000sample size3


Aufgabe 3:BFSPlot the mean degree among nodes sampled by: (i) BFS, and (ii) DFS, as a function of the fraction ofsampled nodes. Average the plot over 100 different seed nodes, selected by UIS.What can you say about the BFS and DFS exploration processes from these plots?Solution:20BFS and DFS traversalsBFSDFS15average degree105010000 20000 30000 40000 50000# of samples per sourceBoth BFS and DFS first explore high degree nodes and then low degree nodes. This does not seem <strong>to</strong>depend on the starting node at all.Approaching the real average degree requires the exploration of almost the entire network.4


Aufgabe 4:Graph sizeRecall the graph size estimation formulas in slides 23–24 of the second lecture in Chapter 2 (Nov 12).Apply the corresponding formula <strong>to</strong> nodes collected by:1) UIS WOR,2) UIS WR,3) WIS WR,4) RW (using all nodes, or “SimpleThinning” as in slide 32 of the above-mentioned lecture).For RW, plot the estimated graph size versus the thinning fac<strong>to</strong>r k.What do you observe?Solution:n = number of samples, c = number of collisionsMethod Formula Size estimateReal – N = 62 ′ 586UIS WOR – ˆN = ∞UIS WR ˆN =n 2WIS WRRW WR2cˆN =Ψ 1 Ψ −12cˆN =Ψ 1 Ψ −12cˆN = 64 ′ 002ˆN = 62 ′ 306ˆN = 24 ′ 963180000Network size from thinned RW160000estimated network size1400001200001000008000060000400002000000 10 20 30 40 50thinning fac<strong>to</strong>r5


Importing the graph✞1 def l o a d _ g r a p h ( fname ) :2 f r = open ( fname , ’r’ )3 G = {} # d i c t i o n a r y : node −> s e t of n e i g h b o r s4 f o r l i n e in f r :5 i f not l i n e . s t a r t s w i t h ( ’#’ ) :6 a , b = map ( i n t , l i n e . s p l i t ( ) )7 i f a not in G: G[ a ] = s e t ( )8 i f b not in G: G[ b ] = s e t ( )9 G[ a ] . add ( b )10 G[ b ] . add ( a )11 f r . c l o s e ( )12 return G1314 G = l o a d _ g r a p h ( "p2p-Gnutella31.txt" )15 p r i n t G[ 4 2 ] # Neighbors of node 42✡✝✆Alternatively, you can use the networkx Python module.✞1 import networkx as nx23 G = nx . r e a d _ e d g e l i s t ( "p2p-Gnutella31.txt" , d e l i m i t e r =’\t’ , n o d e t y p e = i n t )✡✝✆6

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!