49
Community detection and clustering Social and Technological Networks Rik Sarkar University of Edinburgh, 2019.

Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

  • Upload
    others

  • View
    12

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

Communitydetectionandclustering

SocialandTechnologicalNetworks

Rik Sarkar

UniversityofEdinburgh,2019.

Page 2: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

Communities

• Groupsoffriends• Colleagues/collaborators• Webpagesonsimilartopics• Biologicalreactiongroups• Similarcustomers/users…

Page 3: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

Otherapplications

• Acoarserrepresentationofnetworks• Oneormoremeta-nodeforeachcommunity• Identifybridges/weak-links• Structuralholes

Page 4: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

Communitydetection

• Givenanetwork• Whatarethe“communities”– Closelyconnectedgroupsofnodes– Relativelyfewedgestooutsidethecommunity

• Similartoclusteringindatasets– Grouptogetherpointsthataremorecloseorsimilartoeachotherthanotherpoints

Page 5: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

Definitionsofcommunities

• Varies.Dependingonapplication

• Generalidea:Densesubgraphs: Morelinkswithincommunity,fewlinksoutside

• Sometypesandconsiderations:– Partitions:Eachnodeinexactlyonecommunity– Overlapping:Eachnodecanbeinmultiplecommunities

–Wewillusuallyconsiderpartitions

Page 6: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

Comment:Findingdensesubgraphs ishardingeneral

• Findinglargestclique– NP-hard– Computationallyintractable

• Decisionversion:Doesacliqueofsizekexist?– AlsoNP-complete– Computationallyintractable– Polynomialtime(efficient)algorithmsunlikelytoexist

• Wewilllookforapproximations

Page 7: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

Densesubgraphs:Fewpreliminarydefinitions

• ForS,Tsubgraphs ofV• e(S,T):SetofedgesfromStoT– e(S)=e(S,S):EdgeswithinS

• dS(v):numberofedgesfromvtoS• EdgedensityofS:|e(S)|/|S|– Largestforcompletegraphsorcliques

Page 8: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

Dense subgraph Problem

• Findthesubgraph withlargestedgedensity• Therealsoexistsadecisionversion:– Isthereasubgraph withedgedensity>α

• CanbesolvedusingMaxFlowalgorithms– O(n2m):inefficientinlargedatasets– Findstheonedensestsubgraph

• Variant:FinddensestScontaininggivensubsetX• Otherversions:Findsubgraphs sizekorless• NP-hard

Page 9: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

EfficientapproximationforfindingdenseScontainingX

• Givesa1/2approximation• EdgedensityofoutputSsetisatleasthalfofoptimalsetS*

• (ProofinKempe 2018:http://www-bcf.usc.edu/~dkempe/teaching/structure-dynamics.pdf ).

Page 10: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

Betweenness &graphpartitioning• Wewanttosplitnetworkintotightlyknitgroups(communitiesetc)

• Idea:Identifytheedgesconnectingdifferentcommunitiesandremovethem

• Theseedgesare“central”tothenetwork– Theylieonshortestpaths

• Betweenness ofedge(e)(canbeconsideredforvertex(v)):– Wesend1unitoftrafficbetweeneverypairofnodesinthenetwork

– measurewhatfractionpassesthroughe,assumingtheflowissplitequallyamongallshortestpaths.

Page 11: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

Computingbetweenness

• Computingallshortestpathsseparatelyisinefficient

• Amoreefficientway:• Fromeachnode:– Step1:ComputeBFStree– Step2:Findnumberofshortestpathstoeachnode

– Step3:Findtheflowthrougheachedge– Seekleinberg-Easleyfordetailedalgorithm

Page 12: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

Partitioning(Girvan-newman)Repeat:• Findedgeeofhighest

betweenness• Removee

• Producesahierarchicparitioning structureasthegraphdecomposesintosmallercomponents

• Networkversionofhierarchicclustering

Page 13: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

Modularity

• Howdoweevaluatethequalityofdetectedcommunities?– Howdoyousaytheverticalcutisbetterthanthehorizontalcut?

• Idea:Maximizeaquantitycalledmodularity

Page 14: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

ConfigurationmodelofRandomgraphs

• Supposewewantagraphthatisrandom• Buthasgivendegreeforeachvertex:

• Ateachvertexi wediopen-edges• Pairuptheedgesrandomly

• GivenagraphG,wecanconstructarandomgraphG’withsamedegreesbutrandomedges

Page 15: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

ModularityofsubsetSofV

• GiventhegraphG• ConsiderarandomG’graphwithsamenodedegrees– NumberofedgesinSinG:|e(S)|G– ExpectednumberofedgesinSinG’:E[|e(S)|G’]– ModularityofS:|e(S)|G - E[|e(S)|G’]– Morecoherentcommunitieshavemoreedgesinsidethanwouldbeexpectedinarandomgraphwithsamedegrees

– Note:modularitycanbenegative

Page 16: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

Modularityofaclustering

• Takeapartition(clustering)ofV:• Writed(Si)forsumofdegreesofallnodesinSi• ItcanbeshownthatE[|e(S)|G’]≈d(Si)2• Definition:Sumoverthepartition:

q(P) =1

m

X

i

|e(Si)|G � 1

4md(si)

2

Page 17: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

• Canbeusedasastoppingcriterion(orfindingrightlevelofpartitioning)inhierarchicmethods– Eg.Girvan-newman

Page 18: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

Modularitybasedclustering• Modularityismeantforusemoreasameasureofquality,notso

muchasaclusteringmethod

• FindingclusteringwithhighestmodularityisNP-hard• Heuristic:Louvainmethod:

– Placeeach node inits own community– For each community,considermergingwith neighbor.

• Make the greedy choice – make the merge that maximizes modularity• Or donotmerge if none increases modularity

– Repeat• Note:Modularityisarelativemeasureforcomparingcommunity

structure.• Notentirelyclearinwhichcasesitmayormaynotgivegoodresults• Athresholdof0.3ormoreissometimesconsideredtogivegood

clustering

Page 19: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

Karateclubhierarchicclustering

• Shapeofnodesgivesactualsplitintheclubduetointernalconflicts– Newman2003

Page 20: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

Correlationclustering• Someedgesareknowntobesimilar/friends/trusted

• marked“+”• Someedgesareknowntobedissimilar/enemies/distrusted

• marked“-”• Maximizethenumberof+edgesinsideclustersand

• Minimizethenumberof-edgesbetweenclusters

Page 21: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

Applications

• Communitydetectionbasedonsimilarpeople/users

• Documentclusteringbasedonknownsimilarityordissimilaritybetweendocuments

• Useofsentimentsand/orotherdivisiveattributes

Page 22: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

Features

• Clusteringwithoutneedtoknownumberofclusters– k-means,medians,clustersetc needtoknownumberofclustersorotherparameterslikethreshold

– Numberofclustersdependsonnetworkstructure• Actually,doesnotneedanyparameter• NPhard• Notethatgraphmaybecompleteornotcomplete– Insomeapplicationswithunlabelededges,itmaybereasonabletochangeedgesto“+”edgesandnon-edgesto“-”edges

Page 23: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

Approximation

• Naive1/2approximation:– Iftherearemore+edges• Putthemallin1cluster

– Iftherearemore- edges• Putnodesinndifferentclusters

• (notveryuseful)!

Page 24: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

Betterapproximations

• 2waysoflookingatit:– MaximizeagreementorMinimizedisagreement– Similaridea,butweknowdifferentapproximationalgorithms

• NikhilBansal etal.developPTAS(polynomialtimeapproximationscheme)formaximizingagreement:– (1-ε)approximation,runningtime

• Min-disagree:– 4-approximation

Page 25: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

Localdetectionofcommunities

• Supposethereisahugegraph,likewww,orfacebook network

• Weoftenwanttofindthecommunitythatcontainsaparticularnodeorgroup– E.g.tomakerecommendations:“yourfriendshavewatchedthismovie…”

– Toinferpreferencesandattributes• Runningafullscalecommunitydetectioniscomputationallyimpractical

• Wedonotknowthenumberofcommunities

Page 26: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

Conductance:measureofedgesinsidecommunityvsoutside

• GivensubsetsS,TinV• e(S,T):setofedgesbetweenSandT• Volumeofedges:

• ConductanceofSisdefinedas:

• Communitiesarelikelytohavelowconductance

vol(S) =X

v2S

d(v)

Page 27: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

Personalised pagerank

• GivenaseedsetX• FindthecommunitySthatcontainsX• Pagerank style:Userandomwalks• Algorithm– Setalimitktonumberofstepsinrandomwalks– Repeat:

• SelectatrandomastartpointfromX• Takekrandomstepsinthegraph

– Counthowfrequentlyeachnodeoccurs– pagerank– Nodesinthecommunityhavehighpagerank

Page 28: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

Personalised pagerank

• AlternativeAlgorithm– Setaprobabilitytoresetrandomwalk– Repeat:• SelectatrandomastartpointfromX• Withprobability1– 𝜀 movetoarandomneighbor• Withprobability𝜀 movetoarandomnodeinX• Counthowfrequentlyeachnodeoccurs– pagerank

– Nodesinthecommunityhavehighpagerank

Page 29: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

Personalised pagerank

• Communitieshavelowconductance• Therefore,shortrandomwalkswillleavethecommunityonlyrarely

• Therefore,nodesinthecommunityofXwillhavehighpagerank comparedtothoseoutside

• ItcanbeprovedthatifXisinalowconductancecommunity,nodesoutsidethiscommunitywilloccurinfrequently.– Wewillomitthisproof

Page 30: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

Communitydetectionbyclustering

• First,defineametricbetweennodes– Eithercomputeintrinsicmetricslikeallpairsshortestpaths[Floyd-Warshall algorithmO(n3)]

– OrembedthenodesinaEuclideanspace,andusethemetricthere• Wewilllaterstudyembeddingmethods

• Applyaclusteringalgorithmwiththemetric

Page 31: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

Clustering

• Acoreproblemofmachinelearning:–Whichitemsareinthesamegroup?

• Identifiesitemsthataresimilarrelativetorestofdata

• Simplifiesinformationbygroupingsimilaritems– Helpsinalltypesofotherproblems

Page 32: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

Clustering• Outlineapproach:• Givenasetofitems– Defineadistancebetweenthem

• E.g.Euclideandistancebetweenpointsinaplane;Euclideandistancebetweenotherattributes;non-euclideandistances;pathlengthsinanetwork;tiestrengthsinanetwork…

– Determineagrouping(partitioning)thatoptimisessomefunction(prefers‘close’itemsinsamegroup).

• Generalreferencesforclustering:– CharuAggarwal:TheDataMiningTextbook,Springer

• FreeonSpringersite(fromuniversitynetwork)– Blumetal.FoundationsofDataScience(freeonline)

Page 33: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

K-meansclustering

• Findk-clusters

–Withcenters

– Thatminimizethesumofsquareddistancesofnodestotheirclustercenters(calledthek-meanscost)

Page 34: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

K-meansclustering:Lloyd’salgorithm

• Therearenitems• Selectk‘centers’– Mayberandomklocationsinspace– Maybelocationofkoftheitemsselectedrandomly– Maybechosenaccordingtosomemethod

• Iteratetillconvergence:– Assigneachitemtotheclusterforitsclosestcenter– Recompute locationofcenterasthemeanlocationofallelementsinthecluster(theircentroid)

– Repeat• Warning:Lloyd’salgorithmisaHeuristic.Doesnotguaranteethatthek-meanscostisminimised

Page 35: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

K-means

• Visualisations• http://stanford.edu/class/ee103/visualizations/kmeans/kmeans.html

• http://shabal.in/visuals/kmeans/1.html

Page 36: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

K-means

• Ward’salgorithm(alsoHeuristic)– Startwitheachnodeasitsowncluster– Ateachround,findtwoclusterssuchthatmergingthemwillreducethek-meanscostthemost

– Mergethesetwoclusters– Repeatuntiltherearek-clusters

Page 37: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

Kmeans:discussion• Triestominimise squaredsumofdistancesofitemsto

clustercenters– NP-hard.Computationallyintractable– Algorithmgiveslocaloptimum

• Dependsoninitialisation (startingsetofcenters)– Cangivepoorresults– Submodular optimisation canhelp

• Theright‘k’maybeunknown– Possiblestrategy:trydifferentpossibilitiesandtakethebest

• Canbeimprovedbyheuristicslikechoosingcenterscarefully– E.g.choosingcenterstobeasfarapartaspossible:chooseone,

choosepointfarthesttoit,choosepointfarthesttoboth(maximisemindistancetoexistingsetetc)…

– Trymultipletimesandtakebestresult..

Page 38: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

K-medoids

• Similar,butnoweachcentermustbeoneofthegivenitems– Ineachcluster,findtheitemthatisthebest‘center’andrepeat

• Usefulwhenthereisnoambientspace(extrinsicmetric)– E.g.Adistancebetweenitemscanbecomputedbetweennodes,buttheyarenotinanyparticularEuclideanspace,sothe‘centroid’inLloyd’salgorithmisnotameaningfulpoint

Page 39: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

Othercenterbasedmethods

• K-center:Minimise maximumdistancetocenter:

• K-median:Minimise sumofdistances:

Page 40: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

Hierarchicalclustering

• Hierarchicallygroupitems• Usingsomestandardclusteringmethod

Page 41: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

Hierarchicalclustering• Topdown(divisive):– Startwitheverythingin1cluster

– Makethebestdivision,andrepeatineachsubcluster

• Bottomup(agglomerative):– Startwithndifferentclusters– Mergetwoatatimebyfindingpairsthatgivethebestimprovement

Page 42: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

Hierarchicalclustering• Givesmanyoptionsforaflatclustering

• Problem:whatisagood‘cut’ofthedendogram?

Page 43: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

Densitybasedclustering

• Groupdenseregionstogether

• Betteratnon-linearseparations

• Workswithunknownnumberofclusters

Page 44: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

DBSCAN• Densityatadatapoint:

– NumberofdatapointswithinradiusEps• Acorepoint:

– Pointwithdensityatleastτ• Borderpoint

– Densitylessthanτ,butatleastonecorepointwithinradiusEps• Noisepoint

– Neithercorenorborder.Farfromdenseregions

Algorithm

• ConstructUDGofcorepoints

• Connectedcomponentsofthegraphgivetheclusters

• Assignborderpointstosuitableclusters(E.g.totheclustertowhichithasmostedges)

Page 45: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

DBSCAN:Discussions

• Requiresknowledgeofsuitableradiusanddensityparameters(Eps andτ)

• Doesnotallowforpossibilitythatdifferentclustersmayhavedifferentdensities

Page 46: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

DBSCAN

• Usefulincaseswhereitisclearwhichobjectscanbeconsideredsimilarbutnumberofclustersisnotknown

• Knowntoperformverywellinrealproblems

• Worstcasecomplexity:O(n2)

• Currentresearch:Makingfasterinspecialcases,approximations,distributedalgorithms.

Page 47: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

Otherdensitybasedclustering

• Singlelinkage(sameasKruskal’s MSTalgorithm)– Startwithnclusters– Mergetwoclusterswiththeshortestbridginglink– Repeatuntilkclusters

• Other,morerobustmethodsexist

Page 48: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

Communitydetectioninnetworks

• Asimplestrategy:– Chooseasuitabledistancemeasurebasedonavailabledata• E.g.Pathlengths;distancebasedoninversetiestrengths;sizeoflargestenclosinggrouporcommonattribute;distanceinaspectral(eigenvector)embedding;etc..

– Applyastandardclusteringalgorithm

Page 49: Community detection and clustering · Community detection by clustering • First, define a metric between nodes – Either compute intrinsic metrics like all pairs shortest paths

Clusteringisnotalwayssuitableinnetworks

• Smallworldnetworkshavesmalldiameter– Andsometimeintegerdistances– Adistancebasedmethoddoesnothavealotofoptiontorepresentsimilarities/dissimilarities

• Highdegreenodesarecommon– Connectdifferentcommunities– Hardtoseparatecommunities

• Edgedensitiesvaryacrossthenetwork– Samethresholddoesnotworkwelleverywhere