Package edu.gmu.seor.prognos.unbbayesplugin.jt.prs.hybridbn

Examples of edu.gmu.seor.prognos.unbbayesplugin.jt.prs.hybridbn.ContinuousNode


      AddNewStatesToBNNode( uNode, stateIndexMap, c, stateFirst.getNext() );
      
    }else
    if( type.equalsIgnoreCase("Continuous") ){
      //create new Continuous uNode
      uNode = new ContinuousNode();
      uNode.setName(sNode.getName());
      uNode.setDescription(sNode.getName());
    }
     
    //initialize Potential Table
View Full Code Here


//      }
      pnode.setGHK(ghkPot);
      System.out.println("After reducing states variable "+node.getDescription()+" has GHK as");
      printGHK(ghkPot);
    } else if(node.getType() == Node.CONTINUOUS_NODE_TYPE){
      ContinuousNode cnode = (ContinuousNode) node;
      GHKPotentialTable ghkPot = new GHKPotentialTable();
      GHKPotentialTable prevGhkPot = getCopyof(cnode.getGHK());
      ghkPot.setVariableList(prevGhkPot.getVariableList());
      ghkPot.setContinuousNodeList(removeDuplicates((ArrayList<Node>) prevGhkPot.getContinuousNodeList()));
      for(int i=0;i<prevGhkPot.tableSize();i++){
        int coord[] = prevGhkPot.getMultidimensionalCoord(i);
        if(coord[returnIndexOf(prevGhkPot.getVariableList(),findingNode)] == stateIndex){
          ghkPot.setGValue(coord,prevGhkPot.getGValue(i));
          ghkPot.setHValue(coord, prevGhkPot.getHValue(i));
          ghkPot.setKValue(coord, prevGhkPot.getKValue(i));
        }
      }
      if(ghkPot.tableSize() == 1){
        ghkPot.hasNoDescreteStates = true;
        GHKPotential ghk = new GHKPotential();
        ghk.setG(ghkPot.getGValue(0));
        ghk.setH(ghkPot.getHValue(0));
        ghk.setK(ghkPot.getKValue(0));
        ghkPot.setGhkPot(ghk);
      }
      cnode.setGHK(ghkPot);
      System.out.println("After reducing states variable "+node.getDescription()+" has GHK as");
      printGHK(ghkPot);
    }
  }
View Full Code Here

   
    for(Clique cl:cliqueList){
      ArrayList<Node> temp = removeDuplicates(cl.getNodes());
      for(Node n: temp){
        ProbabilisticNode pn;
        ContinuousNode cn;
        if(n.getType() == Node.PROBABILISTIC_NODE_TYPE){
          pn =(ProbabilisticNode) n;
          nodeValueFromClique(cl, n);
        }
        else if(n.getType() == Node.CONTINUOUS_NODE_TYPE){
View Full Code Here

//    GHKPotentialTable ghk = new GHKPotentialTable();
//    ghk.setVariableList(getDescreteNodes(test.getNodes()));
    System.out.println("====================  Initial potential for node & clique ////////////////////// ");
   
    ProbabilisticNode pn = null;
    ContinuousNode cn = null;
    for (Node n : nodeList) {
      if (n.getType() == Node.PROBABILISTIC_NODE_TYPE) {
        pn = (ProbabilisticNode) n;
        System.out.println("------------- p Node "+pn.getDescription());
        System.out.println("G.....");
        System.out.println("table size "+pn.getGHK().tableSize());
        for (int i = 0; i < pn.getGHK().tableSize(); i++) {
          System.out.println(pn.getGHK().getGValue(i));
        }
       
      } else {
        cn = (ContinuousNode) n;
        System.out.println("------------ c Node "+cn.getDescription());
        if (cn.getGHK().hasNoDescreteStates) {
          System.out.println("G.....");
          System.out.println(cn.getGHK().getGhkPot().getG());
          System.out.println("H...");
          printMatrix(cn.getGHK().getGhkPot().getH().gethMatrix());
          System.out.println("K.....");
          printMatrix(cn.getGHK().getGhkPot().getK().getkMatrix());

        } else {
          System.out.println("G.....");
          for (int i = 0; i < cn.getGHK().tableSize(); i++) {
            System.out.println(cn.getGHK().getGValue(i));
          }
          System.out.println("H...");
          for (int i = 0; i < cn.getGHK().tableSize(); i++) {
            printMatrix(cn.getGHK().getHValue(i).gethMatrix());
          }
          System.out.println("K.....");
          for (int i = 0; i < cn.getGHK().tableSize(); i++) {
            printMatrix(cn.getGHK().getKValue(i).getkMatrix());
          }
        }
      }
    }
View Full Code Here

    }
  }

  public void printNode(Node n){
    ProbabilisticNode pn;
    ContinuousNode cn;
    if (n.getType() == Node.PROBABILISTIC_NODE_TYPE) {
      pn = (ProbabilisticNode) n;
      System.out.println("p Node "+pn.getDescription());
      System.out.println("G.....");
      System.out.println("table size "+pn.getGHK().tableSize());
      for (int i = 0; i < pn.getGHK().tableSize(); i++) {
        System.out.println(pn.getGHK().getGValue(i));
      }
     
    } else {
      cn = (ContinuousNode) n;
      System.out.println("c Node "+cn.getDescription());
      if (cn.getGHK().hasNoDescreteStates) {
        System.out.println("G.....");
        System.out.println(cn.getGHK().getGhkPot().getG());
        System.out.println("H...");
        printMatrix(cn.getGHK().getGhkPot().getH().gethMatrix());
        System.out.println("K.....");
        printMatrix(cn.getGHK().getGhkPot().getK().getkMatrix());

      } else {
        System.out.println("G.....");
        for (int i = 0; i < cn.getGHK().tableSize(); i++) {
          System.out.println(cn.getGHK().getGValue(i));
        }
        System.out.println("H...");
        for (int i = 0; i < cn.getGHK().tableSize(); i++) {
          printMatrix(cn.getGHK().getHValue(i).gethMatrix());
        }
        System.out.println("K.....");
        for (int i = 0; i < cn.getGHK().tableSize(); i++) {
          printMatrix(cn.getGHK().getKValue(i).getkMatrix());
        }
      }
    }
  }
View Full Code Here

    if(nodeVal.getType() ==  Node.PROBABILISTIC_NODE_TYPE){
      pmc = convertToMomentCharec(result);
      ProbabilisticNode pn = (ProbabilisticNode) nodeVal;
    }else if(nodeVal.getType() ==  Node.CONTINUOUS_NODE_TYPE){
      pmc = convertToMomentCharec(result);
      ContinuousNode cn = (ContinuousNode) nodeVal;
    }
    System.out.println("\n >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>************************************************* \n");
    System.out.println("\n >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>************************************************* \n");
    System.out.println("\n >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>************************************************* \n" +
        "Printing values for the Node " +nodeVal.getDescription());
View Full Code Here

      System.out.println("associated nodes are "+cl.getAssociatedNodes().toString());
     
      ArrayList<Node> AsscNodeList = cl.getAssociatedNodes();
     
      ProbabilisticNode pn;
      ContinuousNode cn;
     
      // init the clique
      setVariableListAndInit(cl);
      // remove duplicates from node list in cliques
      cl.setNodes(removeDuplicates(cl.getNodes()));
     
      //after init
      System.out.println("after init");
      printClique(cl);
     
     if( countInference == 2){
        //System.out.println(c1.getNodes().get(0).getName());
        if( cl.getNodes().get(1).getName().equalsIgnoreCase("W") && cl.getNodes().get(0).getName().equalsIgnoreCase("Z")){
          System.out.println("second runInference with clique[W Z]!");       
        }
      }
     
      if (AsscNodeList.size() > 0) {
        for(Node node:cl.getNodes()) // this is done to maintain order of multiplication
          if(AsscNodeList.contains(node)){
          if(node.getType()==Node.PROBABILISTIC_NODE_TYPE){
            pn = (ProbabilisticNode) node;
            cl.getGHK().GHKTableOp(pn.getGHK(),GHKPotentialTable.PLUS_OPERATOR);
          }
          else if(node.getType()==Node.CONTINUOUS_NODE_TYPE){
            cn = (ContinuousNode) node;
            cl.getGHK().GHKTableOp(cn.getGHK(),GHKPotentialTable.PLUS_OPERATOR);
            GHKPotentialTable ghk1 = cl.getGHK();
            GHKPotentialTable ghk2 = cn.getGHK();
            System.out.println( "clique GHK.......");
            printGHK(ghk1);
            System.out.println( "node GHK.......");
            printGHK(ghk2);
          //  cl.getGHK().getVariableList().addAll(cn.getGHK().getVariableList());
View Full Code Here

 

  private ContinuousNode cliqueContainsNode(Clique cl,
      ContinuousNode continuousNode) {
    for (Node node : cl.getGHK().getContinuousNodeList()) {
      ContinuousNode cn = (ContinuousNode) node;
      if (cn.getDescription().equals(continuousNode.getDescription()))
        return cn;
    }
    return null;
  }
View Full Code Here

 
  private void initContinuousNodePotentials_CDomain2() {
    for (Node no : nodeList) {
      int[] coord;
      if (no.getType() == Node.CONTINUOUS_NODE_TYPE) {
        ContinuousNode cn = (ContinuousNode) no;
        GHKPotentialTable ghk = cn.getGHK();
        ghk.getCDomain2List().addAll(ghk.getContinuousNodeList());
        System.out.println(ghk.getCDomain2List() );
      }
    }
  }
View Full Code Here

      int[] coord;
      if (no.getType() == Node.CONTINUOUS_NODE_TYPE) {
        System.out.println("Now working on node "+no.getDescription());
        double mean,Sigma, SD;
        double g;
        ContinuousNode cn = (ContinuousNode) no;
        CNNormalDistribution CNNormalDist = cn.getCnNormalDistribution();
        NormalDistributionFunction[] ndf = cn.getCnNormalDistribution()
            .getNDF();
        /* Has no parents */
        if (hasNoParents(cn)) {
          //initialize ghk potential table
          GHKPotentialTable ghk = new GHKPotentialTable();
          ghk.getContinuousNodeList().add(cn);
         
          mean = ndf[0].getMean();
          SD = Math.sqrt(ndf[0].getVariance());
          Sigma = ndf[0].getVariance();
          System.out.println("Mean and Variance is: "+mean+" and "+ Sigma);
          /* since it contains a single ghk value and no descrete state table, we store it in a GHKPotential class instead of the Table*/
         
          // setup G
          g= calculateG2(mean, SD);
         
          //Setup H
          HComponent hc = new HComponent();
          hc.setComponent1((1 / (SD * SD)) * mean);
          hc.buildMatrix();

          //Setup K
          KComponent kc = new KComponent();
          kc.setComponent1(1 / (SD * SD));
          kc.buildMatrix();
         
          ghk.setGhkPot(new GHKPotential(g, hc, kc));
          ghk.hasNoDescreteStates = true;
          cn.setGHK(ghk);

        }
        /* Has continuous parents only */
        else if (hasContinuousParentsOnly(cn)) {
          mean = ndf[0].getMean();
          SD = Math.sqrt(ndf[0].getVariance());
         
          /* since it contains a single ghk value and no descrete state table, we store it in a GHKPotential class instead of the Table*/
         
          // setup G
          g= calculateG(mean, SD);
         
          //Setup H
          HComponent hc = new HComponent();
          hc.setComponent1(mean * (1 / (SD * SD)));
          double[] weights = ndf[0].getConstantList();
          System.out.println("The weights I get is");
          for(int i=0;i< weights.length;i++) System.out.println(weights[i]);
          if (weights.length > 1)
            hc.setComponent2(multiplyNx1(weights, -mean
                * (1 / (SD * SD))), false);
          else
            hc.setComponent2(multiplyNx1(weights, -mean
                * (1 / (SD * SD))), true);
          hc.buildMatrix();
         
          //Setup K
          KComponent kc = new KComponent();
          kc.setComponent1(1 / (SD * SD));
          kc.setComponent2(multiplyNx1(weights, -1 / (SD * SD)),
              false);
          kc.setComponent3(multiply1xN(weights, -1 / (SD * SD)),
              false);
          kc.setComponent4(multiplyNxN(multiplyNx1(weights,
              1 / (SD * SD)), multiply1xN(weights, 1)), false);
          kc.buildMatrix();
         
          //initialize ghk potential table
          GHKPotentialTable ghk = new GHKPotentialTable();
          ghk.setGhkPot(new GHKPotential(g, hc, kc));
          ghk.hasNoDescreteStates = true;
          ghk.getContinuousNodeList().add(cn);
          for(Node n:removeDuplicates(getContinuousNodes(cn.getParents())))
            ghk.getContinuousNodeList().add(n);
          cn.setGHK(ghk);
        }
        /* Has descrete parents only */
        else if (hasDescreteParentsOnly(cn)) {
         
          /* Since we need to represent a ghk potential at every combination descrete state we will use the GHKPotential Table*/
          //initialize ghk potential table
          GHKPotentialTable ghk = new GHKPotentialTable();
          ghk.getContinuousNodeList().add(cn);
         
          //Now insert the rest of the descrete variables
          for(int i=0;i<CNNormalDist.getDiscreteParentList().size();i++)
            ghk.setVariableAtVariableList(CNNormalDist.getDiscreteParentList().get(i));
         
          for (int i = 0; i < ndf.length; i++) {
            mean = ndf[i].getMean();
            SD = Math.sqrt(ndf[i].getVariance());
           
            // setup G
            g= calculateG2(mean, SD);
           
            //Setup H
            HComponent hc = new HComponent();
            hc.setComponent1((1 / (SD * SD)) * mean);
            hc.buildMatrix();
           
            //Setup K
            KComponent kc = new KComponent();
            kc.setComponent1(1 / (SD * SD));
            kc.buildMatrix();
           
            // get the corresponding reformed co-ord and set the value
            ghk.setGHK(CNNormalDist.getMultidimensionalCoord(i),g, hc, kc);
          }
          cn.setGHK(ghk);

        }
        /* Has both continuous and descrete parents */
        else if (hasContinuousAndDescreteParents(cn)) {
         
          /* Since we need to represent a ghk potential at every combination descrete state we will use the GHKPotential Table*/
          //initialize ghk potential table
          GHKPotentialTable ghk = new GHKPotentialTable();
         
          //Now insert the rest of the descrete variables
          for(int i=0;i<CNNormalDist.getDiscreteParentList().size();i++)
            ghk.setVariableAtVariableList(CNNormalDist.getDiscreteParentList().get(i));
         
          for (int i = 0; i < ndf.length; i++) {
            mean = ndf[i].getMean();
            SD = Math.sqrt(ndf[i].getVariance());
           
            // setup G
            System.out.println("calculating g sending "+mean+" and "+SD);
            g= calculateG(mean, SD);
           
            //Setup H
            HComponent hc = new HComponent();
            hc.setComponent1(mean * (1 / (SD * SD)));
            double[] weights = ndf[i].getConstantList();
            System.out.println("The weights I get is");
            for(int k=0;k< weights.length;k++) System.out.println(weights[k]);
            if (weights.length > 1)
              hc.setComponent2(multiplyNx1(weights, -mean
                  * (1 / (SD * SD))), false);
            else
              hc.setComponent2(multiplyNx1(weights, -mean
                  * (1 / (SD * SD))), true);
            hc.buildMatrix();
           
            //Setup K
            KComponent kc = new KComponent();
            kc.setComponent1(1 / (SD * SD));
            kc.setComponent2(multiplyNx1(weights, -1 / (SD * SD)),
                false);
            kc.setComponent3(multiply1xN(weights, -1 / (SD * SD)),
                false);
            kc.setComponent4(multiplyNxN(multiplyNx1(weights,
                1 / (SD * SD)), multiply1xN(weights, 1)), false);
            kc.buildMatrix();
           
          // get the corresponding reformed co-ord and set the value
          ghk.setGHK(CNNormalDist.getMultidimensionalCoord(i),g, hc, kc);
          ghk.getContinuousNodeList().add(cn);
          for(Node n:removeDuplicates(getContinuousNodes(cn.getParents())))
            ghk.getContinuousNodeList().add(n);
        }
        cn.setGHK(ghk);
         }
      } 
    }
   
    // remove duplicate continuous nodes
    for(Node n: getContinuousNodes(nodeList)){
      ContinuousNode cn = (ContinuousNode) n;
      cn.getGHK().setContinuousNodeList(removeDuplicates((ArrayList<Node>) cn.getGHK().getContinuousNodeList()));
    }
   
    for(Node n: getContinuousNodes(nodeList)){
      ContinuousNode cn = (ContinuousNode) n;
      System.out.println("Continuous node list "+cn.getGHK().getContinuousNodeList());
    }
  }
View Full Code Here

TOP

Related Classes of edu.gmu.seor.prognos.unbbayesplugin.jt.prs.hybridbn.ContinuousNode

Copyright © 2018 www.massapicom. 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.