Esempio n. 1
0
 public String renderInferenceResult(BeliefNetwork bn, Inference Inf) {
   String result = "";
   BeliefNode[] nodes = bn.getNodes();
   if (_RENDERHTML) {
     result += "<table>";
   }
   for (int i = 0; i < nodes.length; i++) {
     BeliefNode X = nodes[i];
     if (_RENDERHTML) {
       result += "<tr>";
     } else {
       result += X.getName() + ":\n";
     }
     result += renderCPF(Inf.queryMarginal(X));
     if (_RENDERHTML) {
       result += "</tr>";
     } else {
       result += "\n";
     }
   }
   if (_RENDERHTML) {
     result += "</table>";
   }
   return result;
 }
Esempio n. 2
0
  public static BeliefNetwork load(FileInputStream FIS, String file) {
    IOPlugInLoader pil = IOPlugInLoader.getInstance();
    Importer IMP = pil.GetImporterByExt(pil.GetExt(file));
    OmniFormatV1_Reader ofv1r = new OmniFormatV1_Reader();
    IMP.load(FIS, ofv1r);
    BeliefNetwork bn = ofv1r.GetBeliefNetwork(0);
    if (_RATIONAL) {
      BeliefNode[] n = bn.getNodes();
      for (int i = 0; i < n.length; i++) n[i].getCPF().convertDouble2Rational();
    }
    if (_FLOAT) {
      BeliefNode[] n = bn.getNodes();
      for (int i = 0; i < n.length; i++) n[i].getCPF().convertDouble2Float();
    }

    return bn;
  }
Esempio n. 3
0
 public void WriteSample(BeliefNetwork bn, EvidenceStream out, int time) {
   out.BeginSample(time);
   BeliefNode[] nodes = bn.getNodes();
   for (int i = 0; i < nodes.length; i++) {
     if (nodes[i].hasEvidence()) {
       out.Witness(nodes[i].getName(), nodes[i].getEvidence().getName(nodes[i].getDomain()));
     }
   }
   out.EndSample();
 }
Esempio n. 4
0
 public static BeliefNetwork load(String file) {
   try {
     IOPlugInLoader pil = IOPlugInLoader.getInstance();
     Importer IMP = pil.GetImporterByExt(pil.GetExt(file));
     FileInputStream FIS = new FileInputStream(file);
     OmniFormatV1_Reader ofv1r = new OmniFormatV1_Reader();
     IMP.load(FIS, ofv1r);
     BeliefNetwork bn = ofv1r.GetBeliefNetwork(0);
     if (_RATIONAL) {
       BeliefNode[] n = bn.getNodes();
       for (int i = 0; i < n.length; i++) n[i].getCPF().convertDouble2Rational();
     }
     if (_FLOAT) {
       BeliefNode[] n = bn.getNodes();
       for (int i = 0; i < n.length; i++) n[i].getCPF().convertDouble2Float();
     }
     return bn;
   } catch (Exception e) {
     outputln("file: `" + file + "` was not found");
     return null;
   }
 }