I am trying to model networks with ERGMs.
I have an n
by n
matrix for each network statistic (e.g., density
, triangles
). Each cell in each matrix indicates how the presence of that potential edge would change that statistic, holding the rest of the network constant. am
is the adjacency matrix of graph G
(given by nx.to_numpy_array(G)
).
My model looks like this:
with pm.Model() as model:
intercept = pm.Normal('intercept', 0, sigma=100, initval=1)
β_density = pm.Normal('β_density', sigma=100, initval=1)
β_triangles = pm.Normal('β_triangles', sigma=100, initval=1)
μ = intercept + β_density * density + β_triangles * triangles
likelihood = pm.invlogit(μ)
# likelihood = pm.math.sigmoid(μ)
pm.Bernoulli(name='logit', p=likelihood, observed=am)
pm.model_to_graphviz(model)
with model:
trace = pm.sample(
tune=1000,
draws=1000,
chains=4,
# init = 'adapt_diag',
cores=4,
step=pm.Metropolis(),
# step=pm.NUTS(),
# random_seed=12345,
)
For almost all networks I get the following error:
SamplingError: Initial evaluation of model at starting point failed!
Starting values:
{'intercept': array(10.), 'β_density': array(10.), 'β_triangles': array(10.)}
Initial evaluation results:
{'intercept': -7.83, 'β_density': -7.83, 'β_triangles': -7.83, 'logit': -inf}
I’ve tried a variety of initvals
, samplers, priors, but the error persists.
Does anyone know what I may be doing wrong?