Sampling Module
This module provides MCMC sampling algorithms for generating networks from ERGM models.
Sampler
Base class for samplers.
Sampler
Bases: ABC
Abstract base class for ERGM network samplers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thetas
|
ndarray
|
ERGM model parameters (coefficients). |
required |
metrics_collection
|
MetricsCollection
|
Collection of metrics defining the ERGM model. |
required |
Source code in pyERGM/sampling.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | |
__init__
__init__(thetas, metrics_collection: MetricsCollection)
Source code in pyERGM/sampling.py
24 25 26 | |
sample
abstractmethod
sample(initial_state, n_iterations)
Generate network samples. Must be implemented by subclasses.
Source code in pyERGM/sampling.py
28 29 30 31 | |
NaiveMetropolisHastings
Implementation of the Metropolis-Hastings algorithm for ERGM sampling.
NaiveMetropolisHastings
Bases: Sampler
Source code in pyERGM/sampling.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | |
__init__
__init__(thetas, metrics_collection: MetricsCollection)
An implementation for the symmetric proposal Metropolis-Hastings algorithm for ERGMS, using the logit of the acceptance rate. See docs for more details. Throughout this implementation, networks are represented as adjacency matrices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thetas
|
ndarray
|
Coefficients of the ERGM |
required |
metrics_collection
|
MetricsCollection
|
A MetricsCollection object that can calculate statistics of a network. |
required |
Source code in pyERGM/sampling.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
sample
sample(initial_state, num_of_nets, replace=True, edge_proposal_method: EdgeProposalMethod = EdgeProposalMethod.UNIFORM, burn_in: int | None = None, steps_per_sample: int | None = None)
Sample networks using the Metropolis-Hastings algorithm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
initial_state
|
ndarray
|
The initial network to start the Markov Chain from |
required |
num_of_nets
|
int
|
The number of networks to sample |
required |
burn_in
|
int
|
Optional. The number of burn-in steps for the sampler (number of steps in the chain that are discarded before the sampler starts to take samples). Defaults to 100 * net_size2. |
None
|
steps_per_sample
|
int
|
Optional. The number of steps to advance the chain between samples. Defaults to net_size2. |
None
|
replace
|
bool
|
A boolean flag indicating whether we sample with our without replacement. replace=True means networks can be duplicated. |
True
|
edge_proposal_method
|
str
|
Optional. The method for the MCMC proposal distribution. This is defined as a distribution over the edges of the network, which implies how to choose a proposed graph out of all graphs that are 1-edge-away from the current graph. Defaults to "uniform". |
UNIFORM
|
Source code in pyERGM/sampling.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | |
set_thetas
set_thetas(thetas)
Update the model parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thetas
|
ndarray
|
New ERGM coefficients. |
required |
Source code in pyERGM/sampling.py
52 53 54 55 56 57 58 59 60 61 | |