Using IsingGlauberBlockState inference
Bug reports:
Please follow the general troubleshooting steps first:
-
Are you running the latest graph-tool
version? -
Do you observe the problem with the current git version? (haven't tried)
OS is arch linux, but everything is installed in miniconda using the standard conda-forge repo; python 3.10, last version of grap-tool.
I was trying to use the IsingGlauberBlockState
class on some time series of a neural network. I used as a base the code shown for the shown for the Epidemic version on the cookbook (which works no problem).
However switching the EpidemicsBlockState
class for either the continuous or discrete Ising, as in this minimal example:
# We will first simulate the dynamics with a given network
g = gt.collection.data["dolphins"]
ss = []
for i in range(100):
si_state = gt.IsingGlauberState(g, beta=.7)
s = [si_state.get_state().copy()]
for j in range(10):
si_state.iterate_sync()
s.append(si_state.get_state().copy())
# Each time series should be represented as a single vector-valued
# vertex property map with the states for each note at each time.
s = gt.group_vector_property(s)
ss.append(s)
# Prepare the initial state of the reconstruction as an empty graph
u = g.copy()
u.clear_edges()
ss = [u.own_property(s) for s in ss] # time series properties need to be 'owned' by graph u
# Create reconstruction state
rstate = gt.IsingGlauberBlockState(u, s=ss, beta=.7,
nested=False, aE=g.num_edges())
# Now we collect the marginals for exactly 10000 sweeps, at
# intervals of 10 sweeps:
gm = None
bs = []
betas = []
def collect_marginals(s):
global gm, bs
gm = s.collect_marginal(gm)
bs.append(s.bstate.b.a.copy())
betas.append(s.params["beta"])
gt.mcmc_equilibrate(rstate, force_niter=1000, mcmc_args=dict(niter=10, xstep=0),
callback=collect_marginals)
results in an error:
AttributeError: module 'graph_tool.inference.libgraph_tool_inference' has no attribute 'mcmc_ising_glauber_sweep_h'
The stack trace:
File "/lib/python3.10/site-packages/graph_tool/inference/mcmc.py", line 123, in mcmc_equilibrate
delta, nattempts, nmoves = state.multiflip_mcmc_sweep(**mcmc_args)
File "/lib/python3.10/site-packages/graph_tool/inference/uncertain_blockmodel.py", line 216, in multiflip_mcmc_sweep
return self.mcmc_sweep(multiflip=True, **kwargs)
File "/lib/python3.10/site-packages/graph_tool/inference/uncertain_blockmodel.py", line 1320, in mcmc_sweep
return super().mcmc_sweep(r=r, p=p, pstep=p, h=h, hstep=hstep,
File "/python3.10/site-packages/graph_tool/inference/base_states.py", line 78, in wrapper
ret = func(self, *args, **kwargs)
File "/lib/python3.10/site-packages/graph_tool/inference/uncertain_blockmodel.py", line 208, in mcmc_sweep
return self._algo_sweep(lambda s, **kw: s.multiflip_mcmc_sweep(**kw),
File "/lib/python3.10/site-packages/graph_tool/inference/uncertain_blockmodel.py", line 1333, in _algo_sweep
return self._mcmc_sweep_h(mcmc_state)
File "/lib/python3.10/site-packages/graph_tool/inference/uncertain_blockmodel.py", line 1367, in _mcmc_sweep_h
return libinference.mcmc_ising_glauber_sweep_h(mcmc_state, self._state,
This doesn't happen with the equilibrium Ising model classes (substituting in PseudoIsingBlockState
works fine), . Indeed it seems, by looking at the source code for the C++ side of the library, that the dynamic models do not have those functions implemented (my c++ is rusty tho), however the equilibrium ones have (for example graph_blockmodel_dynamics_pseudo_cising_mcmc_h.cc
). Also those functions are explicitly called from the python code, so it seems they should be existing.
Am i misusing the IsingGlauberBlockState
model or is this an issue with graph-tool?