amidst / toolbox

A Java Toolbox for Scalable Probabilistic Machine Learning
http://www.amidsttoolbox.com
Apache License 2.0
119 stars 35 forks source link

NullPointerException in MessagePassingAlgorithm::SetEFModel #72

Open santoshthammana opened 7 years ago

santoshthammana commented 7 years ago

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!

rcabanasdepaz commented 7 years ago

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

santoshthammana commented 7 years ago

I emailed a code example.

rcabanasdepaz commented 7 years ago

Received. We will answer you as soon as possible.

rcabanasdepaz commented 7 years ago

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.