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.

I have a simple problem, I would like to measure the global clustering coefficient for a random graph. Here is my code:

GlobalClusteringCoefficient[RandomGraph[DegreeGraphDistribution[
  {2, 1, 1, 1, 1, 2, 1, 3, 3, 1, 1, 2, 2, 2, 2,1, 1, 1, 7, 3, 3, 3, 1, 2, 1}], 10000]]

This is just supposed to create 10000 random graphs, with each vertex in each graph having a fixed number of edges. The error I get is as follows:

GlobalClusteringCoefficient::graph: A graph object is expected at position 1 in GlobalClusteringCoefficient

I tried wrapping everything before the clustering function as follows:

Graph[[RandomGraph[DegreeGraphDistribution[
  {2, 1, 1, 1, 1, 2, 1, 3, 3, 1, 1, 2, 2, 2, 2,1, 1, 1, 7, 3, 3, 3, 1, 2, 1}], 10000]]]

And it gives the same error. Anyone know how to convert the random graph generated into a graph object?

EDIT:

So I had in mind to create a For-loop which would go from i = 1 until 10,000 -- but this saved me a lot of computational power. Now I have this:

Mean[GlobalClusteringCoefficient /@ 
  RandomGraph[DegreeGraphDistribution[
    {2, 1, 1, 1, 1, 2, 1, 3, 3, 1, 1, 2, 2, 2, 2, 1, 1, 1, 7, 3, 3, 3, 1, 2, 1}], 10000]]

I get a value of 4587/86000, which is almost too good to be true -- is this really calculating the mean of all 10000 cluster coefficients?

I am a little surprised because I have been using Mathematica for a total of one day, but this solved the issue far faster than R.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

RandomGraph[DegreeGraphDistribution[...], 10000] gives a list of graphs. You need to map GlobalClusteringCoefficient into that. For example,

GlobalClusteringCoefficient /@ 
  RandomGraph[DegreeGraphDistribution[
    {2, 1, 1, 1, 1, 2, 1, 3, 3, 1, 1, 2, 2, 2, 2, 1, 1, 1, 7, 3, 3, 3, 1, 2, 1}], 10]

{3/43, 0, 0, 0, 3/43, 3/43, 3/43, 3/43, 0, 3/43}

share|improve this answer
    
Woah thank you so much, can you check my slightly edited question? –  user9858 Oct 6 '13 at 8:34
    
@user9858 yes, it's computing all 10000 cluster coefficient. you could also do something like this: dist = DegreeGraphDistribution[{2, 1, 1, 1, 1, 2, 1, 3, 3, 1, 1, 2, 2, 2, 2, 1, 1, 1, 7, 3, 3, 3, 1, 2, 1}]; data1 = RandomVariate[ GraphPropertyDistribution[GlobalClusteringCoefficient[g], g [Distributed] dist], 1000]; data2 = RandomVariate[ GraphPropertyDistribution[MeanClusteringCoefficient[g], g [Distributed] dist], 1000]; Histogram[{data1, data2}] –  halmir Oct 6 '13 at 22:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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