Worked example
Vertices need a String property :name.
using SamplingPerceivedNetworks, Graphs, MetaGraphs, Random
g = MetaGraph(watts_strogatz(100, 6, 0.2; rng = MersenneTwister(1)))
for i in vertices(g)
set_prop!(g, i, :name, "p$i")
endOne perceiver
The orbit of vertex 1, out to $d_{max} = 3$, and the number of candidate pairs in each bin:
orbit = vertexorbit(g, 1, 3)
bins = samplingbins(orbit, 3)
Dict(k => length(v) for (k, v) in bins)Dict{Tuple{Int64, Bool}, Int64} with 6 entries:
(1, 1) => 5
(2, 1) => 29
(2, 0) => 127
(3, 0) => 552
(1, 0) => 10
(3, 1) => 57With moreinfo = true, samplebins also returns the degree bin and reality of each sampled pair:
lst, degrees, real = samplebins(
MersenneTwister(2), bins;
desired = ((3, 3), (3, 3), (3, 3)), dvals = (1, 2, 3), moreinfo = true,
)
first(collect(zip(lst, degrees, real)), 5)5-element Vector{Tuple{Tuple{String, String}, Union{UnitRange{Int64}, Int64}, Bool}}:
(("p3", "p100"), 1, 1)
(("p98", "p99"), 1, 1)
(("p3", "p4"), 1, 1)
(("p82", "p79"), 2, 1)
(("p3", "p2"), 2, 1)The whole network
lists = samplenetwork(
MersenneTwister(3), g;
desired = ((5, 5), (5, 5), (5, 5)), dvals = (1, 2, 3), moreinfo = true,
)
length(lists)100psn_edgelists flattens the lists into a table for export (for example, with CSV.jl):
el = psn_edgelists(lists)
first(el, 5)5×5 DataFrame
| Row | perceiver | from | to | bin | real |
|---|---|---|---|---|---|
| String | String | String | String | Bool | |
| 1 | p19 | p36 | p48 | 2 | false |
| 2 | p19 | p36 | p84 | 2 | true |
| 3 | p19 | p22 | p44 | 3 | false |
| 4 | p19 | p62 | p65 | 3 | true |
| 5 | p19 | p17 | p64 | 2 | true |
edgelist returns the true network in the same format, for merging with survey responses:
first(edgelist(g), 3)3×2 DataFrame
| Row | from | to |
|---|---|---|
| String | String | |
| 1 | p1 | p3 |
| 2 | p1 | p4 |
| 3 | p1 | p82 |