Combine two BNs - changePotential() issue
I build complex BNs and I am exploring ways to create smaller BNs that I can merge together. I am aware of o3prm project but have some additional requirements. I want to build a custom function that will combine two BNs together, assuming names for all nodes are different.
I've started by creating a function that will "copy" a BN but faced an error from changePotential() that I cannot understand. The following code:
def copy(src):
bn = gum.BayesNet("copy")
id_name_map = dict(zip(src.ids(src.names()), src.names()))
for node_name in src.names():
bn.add(src.variable(node_name))
for arc in src.arcs():
parent_name = id_name_map[arc[0]]
child_name = id_name_map[arc[1]]
bn.addArc(parent_name, child_name)
for node in src.names():
bn.changePotential(node, src.cpt(node))
return bn
throws: OperationNotAllowed: [pyAgrum] Operation not allowed: cannot exchange potentials because, for variable with id 0, dimension 0 differs.
I've compared the potentials and it looks like the dimensions are the same... Is there a simpler way to "combine" two BNs into one?