Added Daniel's Bayes Net code. Converted example code to unit tests. Minor code clean-up.
This commit is contained in:
45
src/dkohl/bayes/bayesnet/BayesNet.java
Normal file
45
src/dkohl/bayes/bayesnet/BayesNet.java
Normal file
@@ -0,0 +1,45 @@
|
||||
package dkohl.bayes.bayesnet;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import dkohl.bayes.probability.Variable;
|
||||
import dkohl.bayes.probability.distribution.ProbabilityDistribution;
|
||||
|
||||
/**
|
||||
* Represents a Bayes net as a graph with a probability table associated with
|
||||
* each node.
|
||||
*
|
||||
* @author Daniel Kohlsdorf
|
||||
*/
|
||||
public class BayesNet extends NamedGraph {
|
||||
|
||||
/**
|
||||
* The probability tables for each node
|
||||
*/
|
||||
private HashMap<String, ProbabilityDistribution> nodes;
|
||||
private LinkedList<Variable> variables;
|
||||
|
||||
public BayesNet(String names[]) {
|
||||
super(names);
|
||||
this.nodes = new HashMap<String, ProbabilityDistribution>();
|
||||
this.variables = new LinkedList<Variable>();
|
||||
}
|
||||
|
||||
public void setDistribution(Variable node, ProbabilityDistribution dist) {
|
||||
nodes.put(node.getName(), dist);
|
||||
variables.add(node);
|
||||
}
|
||||
|
||||
public void updateDistribution(Variable node, ProbabilityDistribution dist) {
|
||||
nodes.put(node.getName(), dist);
|
||||
}
|
||||
|
||||
public HashMap<String, ProbabilityDistribution> getNodes() {
|
||||
return nodes;
|
||||
}
|
||||
|
||||
public LinkedList<Variable> getVariables() {
|
||||
return variables;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user