00001 package edu.tum.cs.srl.bayesnets.inference; 00002 00003 import edu.ksu.cis.bnj.ver3.core.BeliefNode; 00004 import edu.tum.cs.bayesnets.inference.SampledDistribution; 00005 import edu.tum.cs.inference.BasicSampledDistribution; 00006 00007 public class InferenceResult implements Comparable<InferenceResult> { 00008 public String varName; 00009 public String[] domainElements; 00010 public double[] probabilities; 00011 public Object[] additionalInfo = null; 00012 00013 public InferenceResult(SampledDistribution dist, int nodeIdx) { 00014 BeliefNode node = dist.bn.bn.getNodes()[nodeIdx]; 00015 varName = node.getName(); 00016 domainElements = dist.getDomain(nodeIdx); 00017 probabilities = dist.getDistribution(nodeIdx); 00018 if(dist.usesConfidenceComputation()) { 00019 additionalInfo = new BasicSampledDistribution.ConfidenceInterval[domainElements.length]; 00020 for(int i = 0; i < additionalInfo.length; i++) 00021 additionalInfo[i] = dist.getConfidenceInterval(nodeIdx, i); 00022 } 00023 } 00024 00025 public void print() { 00026 System.out.println(varName + ":"); 00027 if(additionalInfo == null) 00028 for(int i = 0; i < domainElements.length; i++) 00029 System.out.println(String.format(" %.4f %s", probabilities[i], domainElements[i])); 00030 else 00031 for(int i = 0; i < domainElements.length; i++) 00032 System.out.println(String.format(" %.4f %s %s", probabilities[i], additionalInfo[i], domainElements[i])); 00033 } 00034 00038 public int compareTo(InferenceResult o) { 00039 return varName.compareTo(o.varName); 00040 } 00041 00042 public int getDomainSize() { 00043 return domainElements.length; 00044 } 00045 00046 @Override 00047 public String toString() { 00048 StringBuffer sb = new StringBuffer(varName + " ~ "); 00049 for(int i = 0; i < this.domainElements.length; i++) { 00050 if(i > 0) 00051 sb.append(", "); 00052 sb.append(domainElements[i]); 00053 sb.append(": "); 00054 sb.append(probabilities[i]); 00055 } 00056 return sb.toString(); 00057 } 00058 }