问题
I am using Weka Java API. I trained a Bayesnet on an Instances object (data set) data
.
/**
* Initialization
*/
Instances data = ...;
BayesNet bn = new EditableBayesNet(data);
SearchAlgorithm learner = new TAN();
SimpleEstimator estimator = new SimpleEstimator();
/**
* Training
*/
bn.initStructure();
learner.buildStructure(bn, data);
estimator.estimateCPTs(bn);
getMargin
returns marginal distibution for a node. Ideally, assuming node A
has 3 possible values, and its node index is 0. Then, bn.getMargin(0)
should return something like [0.3, 0.4, 0.3]
.
However, in my case, when I print marginal distributions of all nodes using the following code.
for (int i = 0; i <bn.getNrOfNodes(); i++)
System.out.println(Arrays.toString(bn.getMargin(i)));
It returns
[0.0, 0.0, 0.0, ...]
[0.0, 0.0, 0.0, ...]
[0.0, 0.0, 0.0, ...]
...
Someone has seen this before or can possibly give me some hints why this happens?
My data are nominal and most of the columns have many classes/values.
回答1:
I think I saw something like this in the GUI. When I had MaxnrofParents = 2, I could see the margins in the Bayes Editor, but if I used MaxnrofParents of anything bigger, the margins didn't show anything.
来源:https://stackoverflow.com/questions/53494595/weka-why-getmargin-returns-all-zeros