({{, (RefLink[SpatialGraphDistribution, paclet:ref/SpatialGraphDistribution])[n,r] 
represents a spatial distribution for graphs with n vertices uniformly distributed over the unit square and edges between vertices that are at distance at most r.}, {, (RefLink[SpatialGraphDistribution, paclet:ref/SpatialGraphDistribution])[n,r,d]
represents a spatial distribution for graphs with vertices uniformly distributed over the d-dimensional unit square.}, {, (RefLink[SpatialGraphDistribution, paclet:ref/SpatialGraphDistribution])[n,r,dist]
represents a spatial distribution for graphs with vertices distributed according to the probability distribution dist.}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[SpatialGraphDistribution, paclet:ref/SpatialGraphDistribution])[n,r] is equivalent to (RefLink[SpatialGraphDistribution, paclet:ref/SpatialGraphDistribution])[n,r,2].

The probability distribution dist can be any symbolic probability distribution specification.

(RefLink[SpatialGraphDistribution, paclet:ref/SpatialGraphDistribution]) by default effectively uses the Euclidean distance function (RefLink[EuclideanDistance, paclet:ref/EuclideanDistance]).

The following option can be given:

(RefLink[SpatialGraphDistribution, paclet:ref/SpatialGraphDistribution]) can be used with such functions as (RefLink[RandomGraph, paclet:ref/RandomGraph]).

OpenersPrimaryExamplesSection(Spacer1)Examples  (20)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Generate a pseudorandom graph:

RandomGraph[SpatialGraphDistribution[15,0.5]]

Probability density functions of the (RefLink[EdgeCount, paclet:ref/EdgeCount]):

𝒟[n_,r_]:=EmpiricalDistribution[Flatten[Table[EdgeCount[g],{g,RandomGraph[SpatialGraphDistribution[n,r],3000]}]]]

DiscretePlot[Evaluate@Table[PDF[𝒟[8,r],d],{r,0.1,1,0.2}],{d,0,28},PlotRange->All,ExtentSize->1/2]

OpenersExampleSection1(Spacer1)Scope  (6)

Generate simple undirected graphs:

RandomGraph[SpatialGraphDistribution[15,0.3]]

Generate graphs with vertices uniformly distributed in unit cubes of different dimensions:

Table[RandomGraph[SpatialGraphDistribution[15,0.3,d]],{d,1,4}]

Generate graphs with vertices distributed according to different distributions:

RandomGraph[SpatialGraphDistribution[20,0.1,UniformDistribution[{{-0.3,0.3},{1,1.5}}]]]

Univariate distributions:

RandomGraph[SpatialGraphDistribution[20,0.1,ExponentialDistribution[2.5]]]

Bivariate distributions:

RandomGraph[SpatialGraphDistribution[20,5,BinormalDistribution[{3,2},0.01]]]

Multivariate distributions:

RandomGraph[SpatialGraphDistribution[20,5,MultinormalDistribution[{1,1},{{2,1/4},{1/4,3}}]]]

Generate graphs with distance measured using different norms:

Table[SeedRandom[4];RandomGraph[SpatialGraphDistribution[100,0.15,DistanceFunction->(Norm[#2-#1,p]&)]],{p,{1,1.5,2,∞}}]

Generate a set of pseudorandom graphs:

RandomGraph[SpatialGraphDistribution[10,0.5],4]

Compute probabilities and statistical properties:

𝒟=GraphPropertyDistribution[EdgeCount[g],g\[Distributed]SpatialGraphDistribution[10,0.3]];

NExpectation[x,x\[Distributed]𝒟]

OpenersExampleSection2(Spacer1)Options  (2)

OpenersExampleSubsection0(Spacer1)DistanceFunction  (2)

By default, distance is measured using (RefLink[EuclideanDistance, paclet:ref/EuclideanDistance]):

Table[SeedRandom[1];
RandomGraph[SpatialGraphDistribution[30,0.3,DistanceFunction->df]],
{df,{Automatic,EuclideanDistance}}]

This is the same as 2-norm:

SeedRandom[1];
RandomGraph[SpatialGraphDistribution[30,0.3,DistanceFunction->(Norm[#1-#2]&)]]

Use any p-norm:

Table[SeedRandom[1];
RandomGraph[SpatialGraphDistribution[30,0.3,DistanceFunction->(Norm[#1-#2,p]&)]],{p,{1,1.5,2.5,∞}}]

OpenersExampleSection3(Spacer1)Applications  (3)

A wireless ad hoc network can be modeled with a (RefLink[SpatialGraphDistribution, paclet:ref/SpatialGraphDistribution]):

𝒟=BinormalDistribution[{2,1.5},0.3];

𝒢=SpatialGraphDistribution[50,1,𝒟];

Nodes are connected if they are sufficiently near each other:

g=RandomGraph[𝒢,EdgeStyle->White];

Show[DensityPlot[PDF[𝒟,{x,y}],{x,-5,5},{y,-4,4},AspectRatio->Automatic,ColorFunction->ColorData["SolarColors"]],g]

In a piece of brain cortex with 100 neurons, the neurons are connected by synapses if they are at a distance less than 0.2:

𝒢=SpatialGraphDistribution[100,0.2];

RandomGraph[𝒢]

Find the probability that the network is connected:

NProbability[x==1,x\[Distributed]GraphPropertyDistribution[Boole[ConnectedGraphQ[g]],g\[Distributed]𝒢]]

A frog in a lily pond is able to jump 1.5 feet to get from one of the 25 lily pads to another. Model the frog jumping network from the lily pad density and (RefLink[SpatialGraphDistribution, paclet:ref/SpatialGraphDistribution]):

lilyDensity=MixtureDistribution[{1,1,1},{BinormalDistribution[{0,0},{1,1},0],BinormalDistribution[{-1,4},{1,1},-1/2],BinormalDistribution[{4,4},{1,1},1/3]}];

lilyPond=SpatialGraphDistribution[25,1.5,lilyDensity];

Sample a random pond:

g=RandomGraph[lilyPond,VertexShape->,VertexSize->{"Scaled",0.1},EdgeStyle->Opacity[0],Background->Hue[0.6,0.8,0.4],ImageSize->150]

Find the largest collection of lily pads the frog can jump between:

Length[First@ConnectedComponents[g]]

Use simulation to find the sizes of the largest collections of lily pads for similar ponds:

largestIsland=GraphPropertyDistribution[Length[First[ConnectedComponents[g]]],g\[Distributed]lilyPond];

RandomVariate[largestIsland,10]

Find the number of times the frog would have to swim to visit all lily pads:

Length[ConnectedComponents[g]]-1

Simulate to get results for similar lily ponds:

frogSwims=GraphPropertyDistribution[Length[ConnectedComponents[g]]-1,g\[Distributed]lilyPond];

RandomVariate[frogSwims,10]

OpenersExampleSection4(Spacer1)Properties & Relations  (6)

Distribution of the number of vertices:

𝒟[n_,r_]=GraphPropertyDistribution[VertexCount[g],g\[Distributed]SpatialGraphDistribution[n,r]]

Distribution of the number of edges:

𝒟[n_,r_]:=EmpiricalDistribution[Flatten[Table[EdgeCount[g],{g,RandomGraph[SpatialGraphDistribution[n,r],3000]}]]];

DiscretePlot[Evaluate @ Table[PDF[𝒟[15,r],d],{r,0.1,1,0.2}],{d,0,105},PlotRange->All,ExtentSize->1/2]

Degree distribution:

𝒟[n_,r_]:=EmpiricalDistribution[Flatten[Table[VertexDegree[g],{g,RandomGraph[SpatialGraphDistribution[n,r],1000]}]]]

DiscretePlot[Evaluate @ Table[PDF[𝒟[31,r],d],{r,0.1,1,0.2}],{d,0,30},PlotRange->All,ExtentSize->1/2]

Use (RefLink[UniformDistribution, paclet:ref/UniformDistribution]) and (RefLink[EuclideanDistance, paclet:ref/EuclideanDistance]) to simulate (RefLink[SpatialGraphDistribution, paclet:ref/SpatialGraphDistribution]):

edges[n_,c_,r_]:=Cases[EdgeList[CompleteGraph[n]],i_\[UndirectedEdge]j_/;EuclideanDistance[c[[i]],c[[j]]]<r]

spatial[n_,r_]:=Module[{c=RandomVariate[UniformDistribution[{{0,1},{0,1}}],n]},
Graph[Range[n],edges[n,c,r],VertexCoordinates->c]]

Table[spatial[30,0.3],{4}]

A negative distance bound yields an empty graph:

Table[RandomGraph[SpatialGraphDistribution[10,-1,DistanceFunction->(Norm[#2-#1,p]&)]],{p,{1,1.5,2,∞}}]

EmptyGraphQ/@%

A large distance bound yields a complete graph:

Table[RandomGraph[SpatialGraphDistribution[10,2,DistanceFunction->(Norm[#2-#1,p]&)]],{p,{1,1.5,2,∞}}]

CompleteGraphQ/@%

OpenersExampleSection5(Spacer1)Neat Examples  (1)

Generate random star constellations:

RandomGraph[SpatialGraphDistribution[100,0.08],VertexStyle->White,EdgeStyle->Gray,Background->Black,VertexSize->Table[i->RandomReal[{1,3}],{i,100}]]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[BernoulliGraphDistribution, paclet:ref/BernoulliGraphDistribution])  ▪  (RefLink[UniformGraphDistribution, paclet:ref/UniformGraphDistribution])  ▪  (RefLink[DegreeGraphDistribution, paclet:ref/DegreeGraphDistribution])  ▪  (RefLink[BarabasiAlbertGraphDistribution, paclet:ref/BarabasiAlbertGraphDistribution])  ▪  (RefLink[PriceGraphDistribution, paclet:ref/PriceGraphDistribution])  ▪  (RefLink[WattsStrogatzGraphDistribution, paclet:ref/WattsStrogatzGraphDistribution])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Random Graphs, paclet:guide/RandomGraphs])}})}})