Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

For a uni assignment, I need to plot the "number of triples at each v in V(G)". I tried to find relevant information in the Mathematica documentation through Google, but I'm lost. How do I get the set of number of triples at each v in V(G)?

I have graph WS:

WS = RandomGraph[WattsStrogatzGraphDistribution[500, 0.01, 10]]

I want this:

ListPlot[NumberOfTriples[WS]]

NumberOfTriples is an imaginary function, but the previous line illustrates what I want.

share|improve this question

closed as off-topic by Szabolcs, Kuba, Simon Woods, rasher, Oleksandr R. May 11 at 23:01

  • The question does not concern the technical computing software Mathematica by Wolfram Research. Please see the help center to find out about the topics that can be asked here.
If this question can be reworded to fit the rules in the help center, please edit the question.

3  
Can you provide a minimum example ? Any relevant code ? –  Sektor May 11 at 15:59
    
@Sektor updated question. –  bhkj May 11 at 16:04
    
Apparently "number of triples" means "number of triangles". Can't you elaborate a solution? –  Öskå May 11 at 16:18
    
I thought "triples" were well defined in graph theory, maybe it's not. Our professor defines it like this: "A triple is a (sub)graph with exactly 3 vertices and 2 edges." –  bhkj May 11 at 16:24
6  
This question appears to be off-topic because it is not about Mathematica. The missing piece to the solution requires calculating the number of "triples" on paper, and requires an understanding of math/combinatorics and not programming/Mathematica. –  Szabolcs May 11 at 17:26

2 Answers 2

up vote 2 down vote accepted

Let's try with a smaller and less regular Graph.

  • Considering your teacher's definition:

    A triple is a (sub)graph with exactly 3 vertices and 2 edges

    SeedRandom@5;
    g1 = First @ RandomGraph[BernoulliGraphDistribution[7, 0.6], 1];
    Length@Select[(Subgraph[g1, #] & /@ Subsets[VertexList@g1, {3}]), Length@EdgeList@# >= 2 &]
    (* 17 *)
    HighlightGraph[g1, #] & /@ Select[(Subgraph[g1, #] & /@
      Subsets[VertexList@g1, {3}]),Length@EdgeList@# >= 2 &][[1;;3]]
    

    enter image description here


  • Assuming that the "number of triples" is defined by (see here):

    Let X be a random variable whose value is the number of triples of vertices such that the three possible edges connecting them are present in the random graph. In other words, X is defined for each graph, G, and its value, X(G), is the number of triangles in the graph G.

    Length@Select[(Subgraph[g1, #] & /@ Subsets[VertexList@g1, {3}]), Length@EdgeList@# == 3 &]
    (* 3 *)
    HighlightGraph[g1, #] & /@ Select[(Subgraph[g1, #] & /@
      Subsets[VertexList@g1, {3}]),Length@EdgeList@# == 3 &]
    

    enter image description here

share|improve this answer
SeedRandom[5];
wS = RandomGraph[WattsStrogatzGraphDistribution[50, 0.01, 10]]; 
triplets[g_, k_, v_] := With[{vl =Select[Subsets[ VertexList[g], {3}], MemberQ[#, v] &]}, 
                        Pick[vl,Length@EdgeList[Subgraph[g, #]] >= k & /@ vl]];
counts2 = Length[triplets[wS, 2, #]] & /@ VertexList[wS];
counts3 = Length[triplets[wS, 3, #]] & /@ VertexList[wS];
ListPlot[{counts2, counts3}, Joined -> True, ImageSize -> 400, PlotStyle -> Thick]

enter image description here

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.