Package groundTruthModule.GTmodule

Source Code of groundTruthModule.GTmodule.GenerateDataForChildrenOfAggressiveBehavior

package groundTruthModule.GTmodule;
import java.util.ArrayList;
import java.util.Map;

import edu.gmu.seor.prognos.unbbayesplugin.cps.CPSCompilerMain;
import edu.gmu.seor.prognos.unbbayesplugin.cps.datastructure.EDB;
import edu.gmu.seor.prognos.unbbayesplugin.cps.lw.LikelihoodWeighting;
import groundTruthModule.datastructure.PersonEntity;
import groundTruthModule.datastructure.ShipEntity;
 
import unbbayes.util.Debug;
/**
* The Class GenerateDataForChildrenOfAggressiveBehavior.
*/
public class GenerateDataForChildrenOfAggressiveBehavior {
 
  /**
   * Instantiates a new generate data for children of aggressive behavior.
   */
  public GenerateDataForChildrenOfAggressiveBehavior() {
  } 
 
  /* 
  %
  %                              hasAgressiveBehavior
  %                                      /   \      
  %                                     /     \      
  %                               *       *   
  %                        (SpeedChange)     (TurnRate)
  %                                 / \          /  \
  %                                /   \        /    \
  %                               /     \      /      \
  %                              *       *    *        *
  %                 (propellerTurnCount)(cavitation)  (shipRCSchange)
  %
   */

  /** The Aggressive behavior_net. */
  String AggressiveBehavior_net = new String(
    "defineNode(hasAggressiveBehavior, DescriptionA);"+
    "{ defineState(Discrete, True, False);" +
    "p( hasAggressiveBehavior ) = { True:0.5; False:0.5; } }" +
   
    "defineNode(speedChange, DescriptionZ);"+
    "{ defineState(Continuous);" +
    "p( speedChange | hasAggressiveBehavior ) = if( hasAggressiveBehavior == True ) { NormalDist(5,2); } " +
    " else if( hasAggressiveBehavior == False ){ NormalDist(0,3); } " +
    "}" +
   
    
    "defineNode(turnRate, DescriptionZ);"+
    "{ defineState(Continuous);" +
    " p( turnRate | hasAggressiveBehavior ) = if( hasAggressiveBehavior == True ) { NormalDist(5, 1); } " +
    " else if( hasAggressiveBehavior == False ){ NormalDist(0, 4); } " +
    "}" +
    "defineNode(propellerTurnCount, DescriptionE);"+
    "{ defineState(Continuous);" +
      "p( propellerTurnCount | speedChange ) = 2* 3.1415*Root(Exp( speedChange, e),2) + NormalDist( 0, 5 );  " +
    "}" +

      "defineNode(shipRCSchange, DescriptionE);"+
      "{ defineState(Continuous);" +
      "p( shipRCSchange | turnRate ) = 3.1415*Root(Exp(turnRate, e), 2) + NormalDist( 0, 1 ); " +
    "}"+
     
    "defineNode(cavitation, DescriptionE);"+
      "{ defineState(Continuous);" +
      "p( cavitation | speedChange,turnRate ) =   3.1415*speedChange + 3.1415*Root(Exp(turnRate,e),2) +  NormalDist(0,0.01);" +
    "}"
      );

   /**
    * See.
    *
    * @param se the ShipEntity list
    */
   public void see(ArrayList<ShipEntity> se){
     for (ShipEntity ship : se){
      if (!ship.isShipOfInterest()){
        System.out.println(ship.toString());
        for (PersonEntity pe : ship.getCrew()  ){
          System.out.println(pe.toString());
        }
      }
     }
  }
 
  /**
   * Fill information.
   *
   * @param se the ShipEntity list
   */
  public void fillInformation(ArrayList<ShipEntity> se){
    int sizeOfTrue = 0;
    int sizeOfFalse = 0;
   
    for (ShipEntity ship : se){
      if (ship.hasAggressiveBehaviorState())
        sizeOfTrue++;
      else
        sizeOfFalse++;
    }
    
    //for hasAgressiveBehavior == true
    CPSCompilerMain cpsCompiler = new CPSCompilerMain();
        cpsCompiler.InitCompiler();
        cpsCompiler.compile( AggressiveBehavior_net +
                   "defineEvidence( hasAggressiveBehavior, True );"+
                   "run(LW, " + sizeOfTrue + ");" );
       
      int i = 0;
     for (ShipEntity ship : se){
      if (ship.hasAggressiveBehaviorState()){
        Map<String, String> mapSample = LikelihoodWeighting.This().sampleList.get(i++);
       
        for (String key : mapSample.keySet()){
          String value = mapSample.get(key);
          if (key.equalsIgnoreCase("speedChange"))
            ship.setSpeedChange(Float.valueOf(value));
          else
          if (key.equalsIgnoreCase("turnRate"))
            ship.setTurnRate(Float.valueOf(value));
          else
          if (key.equalsIgnoreCase("propellerTurnCount"))
            ship.setPropellerTurnCount(Float.valueOf(value))
          else
          if (key.equalsIgnoreCase("shipRCSchange"))
            ship.setShipRCSChange(Float.valueOf(value));
          else
          if (key.equalsIgnoreCase("cavitation"))
            ship.setCavitation(Float.valueOf(value));  
        }
       
        //System.out.println(ship.toString());
      }
    }   

        //for hasAgressiveBehavior == false
      LikelihoodWeighting.This().sampleList.clear();
        cpsCompiler.InitCompiler();
        cpsCompiler.compile( AggressiveBehavior_net +
                   "defineEvidence( hasAggressiveBehavior, False );"+
                   "run(LW, " + sizeOfFalse + ");" );
       
        i = 0;
     for (ShipEntity ship : se){
      if (!ship.hasAggressiveBehaviorState()){
        Map<String, String> mapSample = LikelihoodWeighting.This().sampleList.get(i++);
        for (String key : mapSample.keySet()){
          String value = mapSample.get(key);
          if (key.equalsIgnoreCase("speedChange"))
            ship.setSpeedChange(Float.valueOf(value));
          else
          if (key.equalsIgnoreCase("turnRate"))
            ship.setTurnRate(Float.valueOf(value));
          else
          if (key.equalsIgnoreCase("propellerTurnCount"))
            ship.setPropellerTurnCount(Float.valueOf(value))
          else
          if (key.equalsIgnoreCase("shipRCSchange"))
            ship.setShipRCSChange(Float.valueOf(value));
          else
          if (key.equalsIgnoreCase("cavitation"))
            ship.setCavitation(Float.valueOf(value));  
        }
        //System.out.println(ship.toString());
      }
     
      }
    }
 
  /**
   * It just delegates to UnBBayes' main.
   *
   * @param args the arguments
   */
  public static void main(String[] args) {
    Debug.setDebug(true);
    EDB.This().printSet(true);
    GenerateDataForChildrenOfAggressiveBehavior u = new GenerateDataForChildrenOfAggressiveBehavior();
    EDB.This().get("ROOT.ENGINES.DMP.NODES").print("");
  }
}
TOP

Related Classes of groundTruthModule.GTmodule.GenerateDataForChildrenOfAggressiveBehavior

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.