Simulation#

ergmx.simulate() draws networks from a model with given coefficients, like R’s simulate(net ~ formula, coef = ...). The MCMC starts from the network passed, which also provides the vertex attributes:

import ergmx
from ergmx import datasets

flomarriage = datasets.load("flomarriage")
networks = ergmx.simulate(flomarriage, "edges + triangle", [-1.7, 0.2], nsim=3, seed=1)
[g.ecount() for g in networks]
[20, 22, 23]

The networks are of the same kind as the one passed, here igraph graphs, with its vertex attributes. output="stats" returns only their statistics, one row per network, which is much faster for many networks:

stats = ergmx.simulate(flomarriage, "edges + triangle", [-1.7, 0.2], nsim=1000, seed=1,
                       output="stats")
stats.mean(axis=0)
array([19.681,  2.996])

Coefficients can be given by name:

ergmx.simulate(flomarriage, "edges + triangle", {"edges": -1.7, "triangle": 0.2})

From a fit#

ErgmFit.simulate() uses the estimates. At the MLE, the simulated networks have, on average, the observed statistics:

fit = ergmx.ergm(flomarriage, "edges + triangle", seed=1)
stats = fit.simulate(1000, seed=1, output="stats")
dict(zip(fit.names, stats.mean(axis=0).round(2))), fit.observed
({'edges': np.float64(19.91), 'triangle': np.float64(3.03)},
 {'edges': 20.0, 'triangle': 3.0})

MCMC settings#

burnin (16,384 proposals by default) is the number of proposals before the first network and interval (1,024) the number between networks. Networks closer together are more alike; raise interval when consecutive networks must be nearly independent.

Over time#

A temporal model simulates a process, each network drawn given the one before: fit.simulate(time_slices=...) for a fit of ergmx.tergm(), and ergmx.simulate_dynamic() for any coefficients and starting network, with the ties that form and dissolve, their durations, and monitor= statistics of each network, tie ages included: see Simulating the process.