Error in mcmc_sweep() in network reconstruction
Cross-posted from the discourse per request:
Hi,
I’m on a fresh install of graph-tool (v2.72) on Pop!_OS 22.04 and I’m encountering an issue trying to run some of the example code from the documentation, specifically the Reconstruction with synthetic data examples.
The code I am executing is essentially verbatim from the docs:
import graph_tool.all as gt
import numpy as np
g = gt.collection.data["dolphins"]
E = g.num_edges()
N = g.num_vertices()
w = g.new_ep("double", vals=np.random.normal(N/(2*E), .05, E)) # True edge weights
istate = gt.IsingGlauberState(g, w=w)
M = 1000
X = []
for m in range(M):
istate.iterate_sync()
X.append(istate.get_state().a.copy())
X = np.array(X).T
state = gt.IsingGlauberBlockState(X)
for i in range(10):
delta, *_ = state.mcmc_sweep(niter=10)
print(delta)
While from the docs I expect this to return the list of deltas, I instead encounter the following:
---------------------------------------------------------------------------
AxisError Traceback (most recent call last)
Cell In[2], line 21
18 state = gt.IsingGlauberBlockState(X)
20 for i in range(10):
---> 21 delta, *_ = state.mcmc_sweep(niter=10)
22 print(delta)
File ~/anaconda3/envs/gt/lib/python3.12/site-packages/graph_tool/inference/reconstruction.py:442, in DynamicsBlockStateBase.mcmc_sweep(self, beta, niter, edge, edge_swap, edge_multiflip, theta, theta_multiflip, sbm, xvals, tvals, k, keep_elist, verbose, elist_args, edge_mcmc_args, edge_swap_mcmc_args, edge_multiflip_mcmc_args, xvals_mcmc_args, theta_mcmc_args, theta_multiflip_mcmc_args, tvals_mcmc_args, sbm_mcmc_args, **kwargs)
440 if verbose:
441 print("tvals_sweep:")
--> 442 eret = self.tvals_sweep(**dict(dict(beta=beta,
443 niter=10 * niter,
444 **kwargs),
445 **tvals_mcmc_args))
446 ret = (sum(x) for x in zip(ret, eret))
447 if edge:
File ~/anaconda3/envs/gt/lib/python3.12/site-packages/graph_tool/inference/base_states.py:79, in mcmc_sweep_wrap.<locals>.wrapper(self, *args, **kwargs)
76 assert self._check_clabel(), "invalid clabel before sweep"
77 Si = self.entropy(**entropy_args)
---> 79 ret = func(self, *args, **kwargs)
81 if _bm_test() and test:
82 if hasattr(self, "_check_clabel"):
File ~/anaconda3/envs/gt/lib/python3.12/site-packages/graph_tool/inference/reconstruction.py:935, in DynamicsBlockStateBase.tvals_sweep(self, beta, niter, maxiter, min_size, tol, entropy_args)
905 r"""Perform sweeps of a greedy update on the node category
906 values, based on bisection search.
907
(...)
931 Number of variables moved.
932 """
934 tvals = self.get_tvals()
--> 935 r = min(niter/len(tvals), 1) if len(tvals) > 0 else 1
936 niter = max(1, int(round(niter/len(tvals)))) if len(tvals) > 0 else 1
937 ea = self._get_entropy_args(entropy_args)
File ~/anaconda3/envs/gt/lib/python3.12/site-packages/numpy/_core/fromnumeric.py:3042, in min(a, axis, out, keepdims, initial, where)
2925 @array_function_dispatch(_min_dispatcher)
2926 def min(a, axis=None, out=None, keepdims=np._NoValue, initial=np._NoValue,
2927 where=np._NoValue):
2928 """
2929 Return the minimum of an array or minimum along an axis.
2930
(...)
3040 6
3041 """
-> 3042 return _wrapreduction(a, np.minimum, 'min', axis, None, out,
3043 keepdims=keepdims, initial=initial, where=where)
File ~/anaconda3/envs/gt/lib/python3.12/site-packages/numpy/_core/fromnumeric.py:86, in _wrapreduction(obj, ufunc, method, axis, dtype, out, **kwargs)
83 else:
84 return reduction(axis=axis, out=out, **passkwargs)
---> 86 return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
AxisError: axis 1 is out of bounds for array of dimension 0
The same error also gets thrown for mcmc_sweep() call in the subsequent example for empirical data.