You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've found a segfault after applying belief propogation to a dummy graph when I call infr.marginals([]) twice.
The first time it returns an empty array, and the second time it segfaults.
I don't think it makes sense to call infr.marginals like this, but its probably not good that the library segfaults in this case either.
Code to reproduce the issue.
importnumpyasnpimportitertoolsasitimportopengmn_states=2# each node has 2 statesn_nodes=4# Unaries are the measured probabilites that each node is in a state# The probability an node `a` is in state `s` is unaries[a, s]unaries=np.empty((n_nodes, n_states))
rng=np.random.RandomState(0)
unaries[:, 0] =rng.rand(n_nodes)
unaries[:, 1] =1-unaries[:, 0]
assertnp.all(unaries.sum(axis=1) ==1), 'must sum to 1'# Costs for having the same labelpotts_func=opengm.PottsFunction(
(n_states, n_states), valueEqual=.7, valueNotEqual=.3)
operator='multiplier'accumulator='integrator'# Define graphical modelnode_state_card=np.ones(n_nodes, dtype=opengm.index_type) *n_statesgm=opengm.graphicalModel(node_state_card, operator=operator)
unary_factor_idxs= []
pairwise_factor_idxs= []
# Add unary terms to the graphnode_idxs=list(range(n_nodes))
forcount, idxinenumerate(node_idxs, start=gm.numberOfFactors):
fid=gm.addFunction(unaries[idx])
gm.addFactor(fid, idx)
unary_factor_idxs.append(count)
# Add pairwise edge terms to the graphedge_idxs=list(it.combinations(node_idxs, 2))
potts_func_id=gm.addFunction(potts_func)
# Add Potts function for each edgeforcount, (idx1, idx2) inenumerate(edge_idxs, start=gm.numberOfFactors):
var_idxs=np.array([idx1, idx2])
gm.addFactor(potts_func_id, var_idxs)
pairwise_factor_idxs.append(count)
# Apply Inferenceinfr=opengm.inference.BeliefPropagation(gm, accumulator=accumulator)
infr.infer()
# The first call does not segfaultempty_marginals=infr.marginals([])
print('empty_marginals(1) = %r'% (empty_marginals,))
# But the second one doesempty_marginals=infr.marginals([])
print('empty_marginals(2) = %r'% (empty_marginals,))
The text was updated successfully, but these errors were encountered:
Hi,
So calling marginals with an empty list is not allowed and we could/should check / assert this on the python side.
The idea is to pass a list of variable indexes, a numpy array of indexes or a single index to this function.
But it is still not so nice that is segfaults if this is done twice, but i am not sure if it is allowed/intended to call this twice.
Might be some implementation details in BP that disallow calling this twice.
ATM there is no state machine inside the solvers and calling functions like 'infer','arg' and 'marginals' twice might lead to undefined behavior ( @joergkappes should know this part of the code the best)
I've found a segfault after applying belief propogation to a dummy graph when I call infr.marginals([]) twice.
The first time it returns an empty array, and the second time it segfaults.
I don't think it makes sense to call infr.marginals like this, but its probably not good that the library segfaults in this case either.
Code to reproduce the issue.
The text was updated successfully, but these errors were encountered: