* @throws SSBNNodeGeneralException
*/
protected void setUpFindings(SSBN ssbn, IInferenceAlgorithm algorithm) throws SSBNNodeGeneralException {
// initial assertion
if (ssbn == null || algorithm == null) {
throw new SSBNNodeGeneralException(new NullPointerException(this.getClass() + ": SSBN == null; algorithm == null."));
}
if (algorithm instanceof DMPInference) {
DMPInference dmp = (DMPInference) algorithm;
// dmp needs a reset, because it uses static db and previous findings may still be in the system.
// TODO fix dmp so that it stops using static db
dmp.reset();
// findings of discrete nodes may be directly inserted to the network treated by the algorithm
Graph g = dmp.getNetwork(); // net to add findings
if (g == null) {
throw new SSBNNodeGeneralException(new IllegalStateException(ssbn + " and " + algorithm + " should be compiled before this method."));
}
if (g instanceof ProbabilisticNetwork) {
ProbabilisticNetwork net = (ProbabilisticNetwork) g;
for(SimpleSSBNNode ssbnFindingNode: ssbn.getFindingList()){
//Not all findings nodes are at the network.
if(ssbnFindingNode.getProbNode()!= null){
// extract node and finding state from the network managed by the algorithm
TreeVariable node = (TreeVariable)net.getNode(ssbnFindingNode.getProbNode().getName());
String stateName = ssbnFindingNode.getState().getName();
// TODO avoid usage of instanceof
// TODO stop using static instance of DMP DB
if ((node instanceof ContinuousNode)
|| (node instanceof GmmNodePluginStub)) {
// findings to continuous nodes should be added directly to the DMP database.
EDBUnit edbNode = EDB.This().get("ROOT.NODES." + node.getName());
EDBUnit Evidence = edbNode.create("EVIDENCE");
Evidence.setData(stateName);
} else {
// add discrete findings directly to the network managed by the inference algorithm
// unfortunately, the network managed by the algorithm and the one linked to the SSBN may not be the same (because algorithm may instantiate another network)
boolean isStateInNode = false; // indicates if node contains the specified state (true if evidence is to a valid state)
for(int i = 0; i < node.getStatesSize(); i++){
// check if the name of the state in the SSBN node is the same in the node in actual network managed by the algorithm
if(node.getStateAt(i).equals(stateName)){
node.addFinding(i);
// ssbnFindingNode.getProbNode().addFinding(i); // add to original node as well, just to make sure
isStateInNode = true;
break;
}
}
if(!isStateInNode){
throw new SSBNNodeGeneralException(node + " has no state for finding: " + stateName);
}
}
}