1
$\begingroup$

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.

$\endgroup$

1 Answer 1

1
$\begingroup$

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}

$\endgroup$
2
  • $\begingroup$ Woah thank you so much, can you check my slightly edited question? $\endgroup$
    – user9858
    Oct 6, 2013 at 8:34
  • $\begingroup$ @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}] $\endgroup$
    – halmir
    Oct 6, 2013 at 22:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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