I am optimising the random geometric graph generation ideas in this post. I need to generate a large number of random geometric graphs with probabilistic connectivity (soft random geometric graphs), then sample the path lengths between two specified vertices in order to find their distribution.
I am trying to compile the edge selection functions, as you can see below:
beta = 1.5;density = 10;r = 2;Ngraphs = 80;edgescompiled = Compile[{{vert, _Real}, {b, _Real}}, Select[Subsets[vert, {2}], RandomReal[{0, 1}] < Exp[-b (Norm[#])^2] &], CompilationTarget -> "C", RuntimeAttributes -> {Listable}, Parallelization -> True];gr[vert_] := Graph[#[[1]] <-> #[[2]] & /@ edgescompiled[vert, beta]] ;n = RandomVariate[PoissonDistribution[4 density r^2], Ngraphs]; // AbsoluteTimingv = Table[ Join[Table[{RandomReal[{-r, r}], RandomReal[{-r, r}]}, {k, 1, n[[k]]}], {{-r/2, 0}, {r/2, 0}}], {k, 1, Ngraphs}]; // AbsoluteTiminggraphs = gr[#] & /@ v; // AbsoluteTiming
But I get an error related to Instruction 3
in CompiledFunction
. Does this not work because Select is not compilable? If it isn't, is there some other way I can performance tune the code?