Simulation¶
simulate_graph(κ, μ, η, S, nv, ns, key=KEY)
¶
Simulate a random graph. Return the vertex type indices and vertex types sampled from the type distribution, vertex thresholds from the threshold distribution, and adjacency matrix sampled from the kernel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
κ
|
Kernel
|
kernel function |
required |
μ
|
TypeMeasure
|
type measure |
required |
η
|
ThresholdMeasure
|
threshold distribution |
required |
nv
|
VertexNum
|
number of vertices |
required |
ns
|
TypeNum
|
number of types |
required |
S
|
TypeDomain
|
type domain |
required |
key
|
Key
|
random key |
KEY
|
Returns:
| Name | Type | Description |
|---|---|---|
vsid |
VertexTypeIndex
|
vertex type indices |
vs |
VertexType
|
vertex types |
vk |
VertexThreshold
|
vertex thresholds |
A |
AdjacencyMatrix
|
adjacency matrix |
Source code in src/bprg/simulation.py
simulate_percolation_final(vk, A)
¶
Simulate bootstrap percolation and return the final threshold vector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vk
|
VertexThreshold
|
vertex thresholds |
required |
A
|
AdjacencyMatrix
|
adjacency matrix |
required |
Returns: vk_final: threshold vector after the process stabilizes
Source code in src/bprg/simulation.py
simulate_percolation_history(vk, A)
¶
Simulate bootstrap percolation on a graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vk
|
VertexThreshold
|
vertex thresholds |
required |
A
|
AdjacencyMatrix
|
adjacency matrix |
required |
Returns:
| Name | Type | Description |
|---|---|---|
vk_hist |
Array[VertexThreshold]
|
vertex thresholds at each step, shape (n_steps+1, nv) |
ea_hist |
Array[bool]
|
boolean adjacency masks of the edges leaving that step's newly-infected vertices, shape (n_steps+1, nv, nv). ea_hist[t, i, j] is True iff vertex i became infected at step t and (i, j) is an edge of A — i.e. the edges that "caused" new infections downstream. |
Source code in src/bprg/simulation.py
estimate_infection(κ, μ, η, S, nv, ns, nm, key=KEY)
¶
Monte Carlo estimate of final proportion of infected vertices by type after the bootstrap percolation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
κ
|
Kernel
|
kernel function |
required |
μ
|
TypeMeasure
|
type measure |
required |
η
|
ThresholdMeasure
|
threshold distribution |
required |
S
|
TypeDomain
|
type domain |
required |
nv
|
VertexNum
|
number of vertices |
required |
ns
|
TypeNum
|
number of types |
required |
nm
|
SimulationNum
|
number of simulations |
required |
key
|
Key
|
random key |
KEY
|
Returns:
| Name | Type | Description |
|---|---|---|
pi_s |
Array[float]
|
final proportion of infected vertices by type, shape (ns,) |
Source code in src/bprg/simulation.py
estimate_infection_apportioned_type(κ, μ, η, S, nv, ns, nm, key=KEY)
¶
Monte Carlo estimate of final proportion of infected vertices by type after the bootstrap percolation, using apportioned types to reduce variance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
κ
|
Kernel
|
kernel function |
required |
μ
|
TypeMeasure
|
type measure |
required |
η
|
ThresholdMeasure
|
threshold distribution |
required |
S
|
TypeDomain
|
type domain |
required |
nv
|
VertexNum
|
number of vertices |
required |
ns
|
TypeNum
|
number of types |
required |
nm
|
SimulationNum
|
number of simulations |
required |
key
|
Key
|
random key |
KEY
|
Returns:
| Name | Type | Description |
|---|---|---|
pi_s |
Array
|
final proportion of infected vertices by type, shape (ns,) |
Source code in src/bprg/simulation.py
count_infected_by_type(vs, vk, S, ns)
¶
Count infected vertices (vk == 0) by vertex type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vs
|
VertexType
|
vertex type vector |
required |
vk
|
VertexThreshold
|
vertex threshold vector |
required |
S
|
TypeDomain
|
type domain |
required |
ns
|
TypeNum
|
number of types |
required |
Returns:
| Name | Type | Description |
|---|---|---|
n_si |
Array
|
infected count per type, shape (ns,) |
Source code in src/bprg/simulation.py
count_infected_by_typeindex(vsid, vk, ns)
¶
Count infected vertices (vk == 0) by vertex type index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vsid
|
VertexTypeIndex
|
vertex type indices |
required |
vk
|
VertexThreshold
|
vertex threshold vector |
required |
ns
|
TypeNum
|
number of types |
required |
Returns:
| Name | Type | Description |
|---|---|---|
n_si |
Array
|
infected count per type, shape (ns,) |