amidst/toolbox

NullPointerException in MessagePassingAlgorithm::SetEFModel

santoshthammana opened this issue · 4 comments

I'm using version 0.6.

I get a NullPointerException for the following line of MessagePassingAlgorithm::SetEFModel:
node.setParents(node.getPDist().getConditioningVariables().stream().map(this::getNodeOfVar).collect(Collectors.toList()));
It looks like the issue is with the call to map(). The getNodeOfVar() function is iterating over this.variablesToNode. But should this map() call be iterating over variablesToNode instead?

Thanks!

Can you give us a short code-example in order to reproduce the bug?

I emailed a code example.

Received. We will answer you as soon as possible.

In the code you send, you create an unconnected DAG. You have to specify the links by adding nodes to the parent sets of each node. For that, use the methods DAG::getParentSet(Variable var) and ParentSet::addParent(Variable var). In the link below you have an example of DAG definition.

http://www.amidsttoolbox.com/documentation/0-6-0/examples-060/bnetworks-060/#sec:bns:models

When defining the the DAG, make sure that it has no cycles and all the nodes are connected.

Another problem that I see in your code, is that you try to build a BN over 9 nodes but you only specify 3 probability distributions. When you call the constructor new BayesianNetwork(modelDAG, modelConditionalDistributions), the list modelConditionalDistributions should contain a distribution for each node in the DAG. As you are working with discrete domains, for nodes without parents you define an object of class Multinomial. For nodes with parents, use Multinomial_MultinomialParents instead.

Let me know if fixing these problems your code works.