@Override public UtilityTable queryUtil(Query.UtilQuery query){
  BNetwork network=query.getNetwork();
  Collection<String> queryVars=query.getQueryVars();
  Assignment evidence=query.getEvidence();
  Map<Assignment,Double> fullJoint=getFullJoint(network,true);
  SortedMap<String,Set<Value>> actionValues=new TreeMap<String,Set<Value>>();
  for (  BNode n : network.getNodes()) {
    if (queryVars.contains(n.getId())) {
      actionValues.put(n.getId(),n.getValues());
    }
  }
  Set<Assignment> actionAssigns=InferenceUtils.getAllCombinations(actionValues);
  UtilityTable table=new UtilityTable();
  for (  Assignment actionAssign : actionAssigns) {
    double totalUtility=0.0f;
    double totalProb=0.0f;
    for (    Assignment jointAssign : fullJoint.keySet()) {
      if (jointAssign.contains(evidence)) {
        double totalUtilityForAssign=0.0f;
        Assignment stateAndActionAssign=new Assignment(jointAssign,actionAssign);
        for (        UtilityNode valueNode : network.getUtilityNodes()) {
          double singleUtility=valueNode.getUtility(stateAndActionAssign);
          totalUtilityForAssign+=singleUtility;
        }
        totalUtility+=(totalUtilityForAssign * fullJoint.get(jointAssign));
        totalProb+=fullJoint.get(jointAssign);
      }
    }
    table.setUtil(actionAssign,totalUtility / totalProb);
  }
  return table;
}

@ Override public UtilityTable queryUtil ( Query . UtilQuery query ) { BNetwork network = query . getNetwork ( ) ; Collection < String > queryVars = query . getQueryVars ( ) ; Assignment evidence = query . getEvidence ( ) ; Map < Assignment , Double > fullJoint = getFullJoint ( network , true ) ; SortedMap < String , Set < Value > > actionValues = new TreeMap < String , Set < Value > > ( ) ; for ( BNode n : network . getNodes ( ) ) { if ( queryVars . contains ( n . getId ( ) ) ) { actionValues . put ( n . getId ( ) , n . getValues ( ) ) ; } } Set < Assignment > actionAssigns = InferenceUtils . getAllCombinations ( actionValues ) ; UtilityTable table = new UtilityTable ( ) ; for ( Assignment actionAssign : actionAssigns ) { double totalUtility = 0.0f ; double totalProb = 0.0f ; for ( Assignment jointAssign : fullJoint . keySet ( ) ) { if ( jointAssign . contains ( evidence ) ) { double totalUtilityForAssign = 0.0f ; Assignment stateAndActionAssign = new Assignment ( jointAssign , actionAssign ) ; for ( UtilityNode valueNode : network . getUtilityNodes ( ) ) { double singleUtility = valueNode . getUtility ( stateAndActionAssign ) ; totalUtilityForAssign += singleUtility ; } totalUtility += ( totalUtilityForAssign * fullJoint . get ( jointAssign ) ) ; totalProb += fullJoint . get ( jointAssign ) ; } } table . setUtil ( actionAssign , totalUtility / totalProb ) ; } return table ; }
computes the utility distribution for the bayesian network , depending on the value of the action variables given as parameters .
