« View all new features in
Mathematica
9
◄
previous
|
next
►
New in
Mathematica
9
›
Social Network Analysis
Cliques and Cohesive Groups
Compute components, cliques, and cohesive groups in a network.
In[1]:=
X
g = \!\(\* GraphicsBox[ NamespaceBox["NetworkGraphics", DynamicModuleBox[{Typeset`graph = HoldComplete[ Graph[{1, 2, 5, 3, 4, 6, 7}, { Null, {{1, 2}, {1, 3}, {2, 4}, {4, 5}, {5, 3}, {4, 6}, {5, 6}, {4, 7}, {5, 7}}}, { ImageSize -> 180, VertexCoordinates -> {{1.9595652573438145`, 0.5880825319731845}, {1.4502332118640586`, 1.1759717047601015`}, {1.4506626970033527`, 0.}, { 0.6271580681226379, 0.9434230409725781}, { 0.6269943909097138, 0.23230866903609504`}, {0., 0.5879767003984426}, {1.2, 0.5879767003984426}}, VertexSize -> {0.2}}]], Typeset`boxes, Typeset`boxes$s2d = GraphicsGroupBox[{{ Directive[ Opacity[0.7], Hue[0.6, 0.7, 0.5]], LineBox[{{ DynamicLocation["VertexID$1", Automatic, Center], DynamicLocation["VertexID$2", Automatic, Center]}, { DynamicLocation["VertexID$1", Automatic, Center], DynamicLocation["VertexID$3", Automatic, Center]}, { DynamicLocation["VertexID$2", Automatic, Center], DynamicLocation["VertexID$4", Automatic, Center]}, { DynamicLocation["VertexID$3", Automatic, Center], DynamicLocation["VertexID$5", Automatic, Center]}, { DynamicLocation["VertexID$4", Automatic, Center], DynamicLocation["VertexID$5", Automatic, Center]}, { DynamicLocation["VertexID$4", Automatic, Center], DynamicLocation["VertexID$6", Automatic, Center]}, { DynamicLocation["VertexID$4", Automatic, Center], DynamicLocation["VertexID$7", Automatic, Center]}, { DynamicLocation["VertexID$5", Automatic, Center], DynamicLocation["VertexID$6", Automatic, Center]}, { DynamicLocation["VertexID$5", Automatic, Center], DynamicLocation["VertexID$7", Automatic, Center]}}]}, { Directive[ Hue[0.6, 0.2, 0.8], EdgeForm[ Directive[ GrayLevel[0], Opacity[0.7]]]], TagBox[ DiskBox[{1.9595652573438145`, 0.5880825319731845}, 0.06390264356613662], "DynamicName", BoxID -> "VertexID$1"], TagBox[ DiskBox[{1.4502332118640586`, 1.1759717047601015`}, 0.06390264356613662], "DynamicName", BoxID -> "VertexID$2"], TagBox[ DiskBox[{1.4506626970033527`, 0.}, 0.06390264356613662], "DynamicName", BoxID -> "VertexID$3"], TagBox[ DiskBox[{0.6271580681226379, 0.9434230409725781}, 0.06390264356613662], "DynamicName", BoxID -> "VertexID$4"], TagBox[ DiskBox[{0.6269943909097138, 0.23230866903609504`}, 0.06390264356613662], "DynamicName", BoxID -> "VertexID$5"], TagBox[ DiskBox[{0., 0.5879767003984426}, 0.06390264356613662], "DynamicName", BoxID -> "VertexID$6"], TagBox[ DiskBox[{1.2, 0.5879767003984426}, 0.06390264356613662], "DynamicName", BoxID -> "VertexID$7"]}}], $CellContext`flag}, TagBox[ DynamicBox[GraphComputation`NetworkGraphicsBox[ 3, Typeset`graph, Typeset`boxes, $CellContext`flag], { CachedValue :> Typeset`boxes, SingleEvaluation -> True, SynchronousUpdating -> False, TrackedSymbols :> {$CellContext`flag}}, ImageSizeCache->{{2.5799999999999974`, 176.42000000000002`}, {-56.56320000000002, 52.76850441619797}}], MouseAppearanceTag["NetworkGraphics"]], AllowKernelInitialization->False, UnsavedVariables:>{$CellContext`flag}]], DefaultBaseStyle->{ "NetworkGraphics", FrontEnd`GraphicsHighlightColor -> Hue[0.8, 1., 0.6]}, FrameTicks->None, ImageSize->180]\);
In[1]:=
X
names = {"", "Clique", "KClique", "KClan", "KClub", "KPlex"};
In[1]:=
X
groups = Prepend[ First /@ {FindClique[g], FindKClique[g, 2], FindKClan[g, 2], FindKClub[g, 2], FindKPlex[g, 2]}, {}];
In[1]:=
X
grid1 = Grid[ Partition[ HighlightGraph[g, Subgraph[g, #1], {PlotLabel -> #2}] & @@@ Transpose[{groups, names}], 3, 3, 1, {}], Frame -> All];
In[2]:=
X
SeedRandom[18];
In[3]:=
X
h = SetProperty[ RandomGraph[ WattsStrogatzGraphDistribution[40, 0.05, 5]], {VertexSize -> 0.6, ImagePadding -> 15}];
In[4]:=
X
hnames = {"LuccioSamiComponents", "LambdaComponents", "KCoreComponents"};
In[5]:=
X
hgroups = {{LuccioSamiComponents[h][[41]]}, {LambdaComponents[h][[ 41]]}, KCoreComponents[h, 3]};
In[6]:=
X
grid2 = Grid[ Partition[ HighlightGraph[h, Table[Subgraph[h, i], {i, #1}], PlotLabel -> Style[#2, Bold]] & @@@ Transpose[{hgroups, hnames}], 3, 3, 1, {}], Frame -> All];
In[7]:=
X
Column[{grid1, grid2}]
Out[7]=