Package edu.gmu.seor.prognos.unbbayesplugin.cps.Jama

Examples of edu.gmu.seor.prognos.unbbayesplugin.cps.Jama.Matrix


   * @return the double
   */
  public double int_prod_gaussian_gmm( EDBUnit lam, EDBUnit pi ){
    double intp = 0;
   
    Matrix lamMu = lam.get("MU").getMatrix();
    Matrix lamSigma = lam.get("SIGMA").getMatrix();
    Matrix lamPrior = lam.get("GMMPRIOR").getMatrix();
    Matrix piMu = pi.get("MU").getMatrix();
    Matrix piSigma = pi.get("SIGMA").getMatrix();
    Matrix piPrior = pi.get("GMMPRIOR").getMatrix();
       
    for( int i = 0; i < lamPrior.getColumnDimension(); i++ ){
      for( int j = 0; j < piPrior.getColumnDimension(); j++ ){
        Double pmp = lamPrior.get(0, i) * piPrior.get(0, j)
        Double mu1 = lamMu.get(0, i);
            Double mu2 = piMu.get(0, j);
            Double S1 = lamSigma.get(0, i);
            Double S2 = piSigma.get(0, j);
           
View Full Code Here


        ret.copy2( pi );
        return ret;
      }else
      if( lambda.get("PRECISION").getData().equalsIgnoreCase("INFINITY") ){
        ret.get("MU").setMatrix(lambda.get("MU").getMatrix())
        Matrix zero = new Matrix(ret.get("MU").getMatrix(), 0);       
        ret.get("SIGMA").setMatrix(zero);
        Matrix one = new Matrix(ret.get("MU").getMatrix(), 1);       
        ret.get("GMMPRIOR").setMatrix(one);
        return ret;
      }else
      {
        lambda.create("SIGMA", lambda.get("PRECISION").getMatrix().divideByMatrix(1));
        lambda.create("MU", lambda.get("SIGMA").getMatrix().arrayTimes(lambda.get("INFO_STATE").getMatrix()));   
        
        lambda.get("GMMPRIOR").setMatrix(lambda.get("RATIO").getMatrix().arrayTimes(lambda.get("WEIGHT").getMatrix()));
        lambda.get("GMMPRIOR").setMatrix(lambda.get("GMMPRIOR").getMatrix().normalize());
        //lambda.print("lambda :  ");
        //pi.print("pi :  ");
       
        Matrix lamMu = lambda.get("MU").getMatrix();
        Matrix lamSigma = lambda.get("SIGMA").getMatrix();
        Matrix lamPrior = lambda.get("GMMPRIOR").getMatrix();
        Matrix piMu = pi.get("MU").getMatrix();
        Matrix piSigma = pi.get("SIGMA").getMatrix();
        Matrix piPrior = pi.get("GMMPRIOR").getMatrix();
           
        Matrix pi_gc = new Matrix(2);
        Matrix lam_gc = new Matrix(2);
        int n1 = piPrior.getColumnDimension();
        int n2 = lamPrior.getColumnDimension();
       
        ret.get("MU").setMatrix(new Matrix(1, n1*n2,1));
        ret.get("SIGMA").setMatrix(new Matrix(1, n1*n2,1));
        ret.get("GMMPRIOR").setMatrix(new Matrix(1, n1*n2,1));
        //ret.print("ret ");
       
        for( int i = 0; i < n1; i++ ){
          pi_gc.set(0, 0, piMu.get(0, i));
          pi_gc.set(1, 0, piSigma.get(0, i));
          for( int j = 0; j < n2; j++ ){
            lam_gc.set(0, 0, lamMu.get(0, j));
            lam_gc.set(1, 0, lamSigma.get(0, j));
           
            Matrix tp_bel = prod_2gaussian(pi_gc, lam_gc)
            double nconst = int_prod_gaussian(pi_gc,lam_gc);
            double tp_mixing = nconst * pi.get("GMMPRIOR").getMatrix().get(0,i) * lambda.get("GMMPRIOR").getMatrix().get(0,j);
          
            ret.get("GMMPRIOR").getMatrix().set(0, i*n2+j,tp_mixing);
            ret.get("MU").getMatrix().set(0, i*n2+j,tp_bel.get(0));
            ret.get("SIGMA").getMatrix().set(0, i*n2+j,tp_bel.get(1));
            
            //ret.print("ret ");
          }
        }
       
View Full Code Here

    if( !lambda.get("PRECISION").getData().equalsIgnoreCase("INFINITY") &&
      lambda.get("PRECISION").getMatrixData() == 0){
      ret.get("GMMPRIOR").setMatrix(lambda.get("GMMPRIOR").getMatrix());
      ret.get("RATIO").setMatrix(lambda.get("RATIO").getMatrix());
      ret.get("WEIGHT").setMatrix(lambda.get("WEIGHT").getMatrix());
      ret.get("PRECISION").setMatrix(new Matrix(1,1,0));
      ret.get("INFO_STATE").setMatrix(new Matrix(1,1,0));
     
      return;
    }
   
    //% the continuous parent to whom lambda message is sending does not have
View Full Code Here

   
    EDBUnit temp_lambda = new EDBUnit(lambda);
    EDBUnit temp_pi = new EDBUnit(pi);
   
    if( lambda.get("PRECISION").getData().equalsIgnoreCase("INFINITY")){
      Matrix m = new Matrix(1,1,0);
      temp_lambda.create("SIGMA", m);
     
      //Y_12_20_2011:
      //this is a new function which is different with Dr.Sun's code.
      //If this node is an evidence node, pi should be filled by parent's combination.
View Full Code Here

      return;
           
    //pi.print("pi");
   
    String str = parentNext.getName()+"["+stateNextOfParent.getName()+"]";
    Matrix m = pi.get("MU").getMatrix(str);
    Matrix s = pi.get("SIGMA").getMatrix(str);
    Matrix p = pi.get("GMMPRIOR").getMatrix(str);
    //Matrix mixing_prior = new Matrix(1,1,1);
   
    EDBUnit tempPi = new EDBUnit("TempPi");
    tempPi.create("MU", m);
    tempPi.create("SIGMA", s);
View Full Code Here

      
      //temp_lambda.print("temp_lambda ");
      //temp_pi.print("temp_pi:");
       
      if( lambda.get("PRECISION").getData().equalsIgnoreCase("INFINITY")){
        Matrix m = new Matrix(1,1,0);
        temp_lambda.create("SIGMA", m);
        
      }else{
        temp_lambda.create("SIGMA", lambda.get("PRECISION").getMatrix().divideByMatrix(1));
        temp_lambda.create("MU", temp_lambda.get("SIGMA").getMatrix().arrayTimes(temp_lambda.get("INFO_STATE").getMatrix()));      
      }
     
       //get combination 
      get_full_combination2( listDiscreteNodeCombination, listContinuousNodeCombination, node, parentNext, pi_from_parents, combined, 1 );
       
      int i = 0;
      for( DiscreteNodesCombination dc: listDiscreteNodeCombination ){
        Double mean = 0.0;
        Double cov = 0.0;
       
        if( dc.toString().equalsIgnoreCase("This[null]")){
          mean = node.get("CPD.MEAN").getMatrix().get(0, 0);
          cov = node.get("CPD.COV").getMatrix().get(0, 0);
        }else{
          mean = node.get("CPD.MEAN").getMatrix(dc.getMap()).get();
          cov = node.get("CPD.COV").getMatrix(dc.getMap()).get();
        }
         
        //cpt.print("CPT ");
        // we don't use CPD_to_pi_pcp_gmm function as matlab code,
        // but the following functions are enough to do same things.
        // EX) CPD_to_pi_pcp_gmm2( tempPi, node, msg, cpt, parentNext, pi_from_parents );
       
        for( EDBUnit parents : listContinuousNodeCombination ){
          //parents.print("parents ");
          Matrix m = CPD_to_pi_ukf( mean, cov, dc, parents )
         
          temp_pi.get("MU").createNext(dc.toString());
          temp_pi.get("SIGMA").createNext(dc.toString());
          temp_pi.get("GMMPRIOR").createNext(dc.toString());
          temp_pi.get("MU").setMatrixData(i, m.get(0,0));
          temp_pi.get("SIGMA").setMatrixData(i, m.get(1,0));
          temp_pi.get("GMMPRIOR").setMatrixData(i, parents.getDataByDouble() * dc.getPrior());
          //temp_pi.get("GMMPRIOR").setMatrixData(i, dc.getPrior());
          i++;
        }
       
View Full Code Here

  public void CPD_to_lambda_ukf(EDBUnit ret, EDBUnit node, DiscreteNodesCombination dc, EDBUnit lambda, int indexLambda, EDBUnit parentNext, EDBUnit pi_from_parents){
  
    //lambda.print("");
    if( lambda.get("PRECISION").getMatrix() != null )
    if( lambda.get("PRECISION").getMatrixData() == 0){
      ret.get("PRECISION").setMatrix(new Matrix(1,1,0));
      ret.get("INFO_STATE").setMatrix(new Matrix(1,1,0));   
      ret.get("WEIGHT").setMatrix(new Matrix(1,1,1));
      ret.get("RATIO").setMatrix(new Matrix(1,1,1));
      return;
    }
   
    //pi_from_parents.print("");
    EDBUnit cpd = node.get("CPD");
   
    double Q = 0.0;
    double Mean = 0.0;
    EDBUnit f;
   
    if( dc != null ){
     
      Mean = cpd.get("MEAN").getMatrix(dc.getMap()).get();
      Q = cpd.get("COV").getMatrix(dc.getMap()).get();
      f = dc.getEquation();
    }
    else{
      Mean = cpd.get("MEAN").getMatrixData();
      Q = cpd.get("COV").getMatrixData();
      f = node.get("EQUATION");
    }
     
 
    // %% find the coefficient of the independent variable in the original linear
    // %% equation - the final ratio will be the reciprocal of this number.
    // %% -wsun, 12/14/10. 
    double r = 0;
    int j = 0;
    Map<String, Integer> mapName1 = new HashMap<String, Integer>();
    Matrix mValue = new Matrix(pi_from_parents.getSize());
    
    for( String str: pi_from_parents.getRel("ISA").getMap().keySet() ){
      if( !str.equalsIgnoreCase(parentNext.getName())) {
        mapName1.put(str,j);
      }else{
        mapName1.put(str,j);
        mValue.set(j, 0, 1);
      }
      j++;
    }
         
    //f.print(" f ");
    r = substitution(0, f, mValue, mapName1);
    r = Math.abs(r);
    // invert function
    //f.print(" f ");
    //System.out.println("");
    EDBUnit invF = convert( f, parentNext.getName(), node.getName() );
    //invF.print(" invF ");
    //lambda.print("lambda ");
    // % transform the lambda message of the current node.
    double Sigma_lambda = 0;
    double mu_lambda = 0;
    if( lambda.get("PRECISION").getData().equalsIgnoreCase("INFINITY")){
      Sigma_lambda = 0;
      mu_lambda = lambda.get("MU").getMatrix().get(0, indexLambda);
    }else{
     
      Sigma_lambda = 1/lambda.get("PRECISION").getMatrix().get(0, indexLambda);
      mu_lambda = Sigma_lambda * lambda.get("INFO_STATE").getMatrix().get(0, indexLambda);
    }
       
    Matrix augSigma = new Matrix(pi_from_parents.getSize()+1, pi_from_parents.getSize()+1);
    Matrix augMu = new Matrix(pi_from_parents.getSize()+1);
    int i = 0;
    Map<String, Integer> mapName = new HashMap<String, Integer>();
   
    //pi_from_parents.print("pi_from_parents:  ");
    //parentNext.print("parentNext:  ");
   
    for( String str: pi_from_parents.getRel("ISA").getMap().keySet() ){
      if( !str.equalsIgnoreCase(parentNext.getName())) {
        mapName.put(str,i);
        EDBUnit parent = pi_from_parents.get(str);
        augMu.set(i,0, parent.get("MU").getMatrixData());
        augSigma.set(i,i, parent.get("SIGMA").getMatrixData());
        i++;
      }
    }   
    
    augMu.set(i, 0, Mean );
    augSigma.set(i, i, Q);
    mapName.put("NormalDist",i);
    i++;
   
    augMu.set(i, 0, mu_lambda);
    augSigma.set(i, i, Sigma_lambda);
    mapName.put(node.getName(),i);
   
    //invF.print(" invF ");
   
    Matrix rM = mysut_wgn( invF, augMu, augSigma, 0, mapName );
   
    ret.get("WEIGHT").setMatrixData(1);
   
    EDBUnit nonlinear = node.get("INFO.NONLINEAR");
    if (nonlinear != null &&
      nonlinear.getData().equalsIgnoreCase("TRUE")){
      double d = Math.sqrt(rM.get(1))/Math.sqrt(Q+Sigma_lambda);
      ret.get("RATIO").setMatrixData(d);
    }else{
      ret.get("RATIO").setMatrixData(1/r);
    }
       
    ret.get("PRECISION").setMatrixData( 1/rM.get(1));
    ret.get("INFO_STATE").setMatrixData( rM.get(0)*ret.get("PRECISION").getMatrixData() );
   
    //ret.print("Ret");
  }
View Full Code Here

      }
      
      int j = 0;     
      for( EDBUnit parents : listContinuousNodeCombination ){
        //parents.print("parents ");
        Matrix m = CPD_to_pi_ukf( mean, cov, dc, parents )
        //
        ret.get("MU").createNext(dc.toString());
        ret.get("SIGMA").createNext(dc.toString());
        ret.get("GMMPRIOR").createNext(dc.toString());
        ret.get("MU").setMatrixData(j, m.get(0,0));
        ret.get("SIGMA").setMatrixData(j, m.get(1,0));
        ret.get("GMMPRIOR").setMatrixData(j, parents.getDataByDouble());
        j++;
      }
     
      //ret.print("PI ");
View Full Code Here

      }
     
      int j = 0;
      for( EDBUnit parents : listContinuousNodeCombination ){
        //parents.print("parents ");
        Matrix m = CPD_to_pi_ukf( mean, cov, dc, parents )
       
        ret.get("MU").createNext(dc.toString());
        ret.get("SIGMA").createNext(dc.toString());
        ret.get("GMMPRIOR").createNext(dc.toString());
        ret.get("MU").setMatrixData(j, m.get(0,0));
        ret.get("SIGMA").setMatrixData(j, m.get(1,0));
        ret.get("GMMPRIOR").setMatrixData(j, parents.getDataByDouble());
        j++;
      }
     
      //ret.print("PI ");
View Full Code Here

        cov = node.get("CPD.COV").getMatrix(dc.getMap()).get();
      }
       
      for( EDBUnit parents : listContinuousNodeCombination ){
        gmmprior = parents.getDataByDouble();
        Matrix m = CPD_to_pi_ukf( mean, cov, dc, parents )
       
        ret.get("MU").createNext(dc.toString());
        ret.get("SIGMA").createNext(dc.toString());
        ret.get("GMMPRIOR").createNext(dc.toString());
        ret.get("MU").setMatrixData(i, m.get(0,0));
        ret.get("SIGMA").setMatrixData(i, m.get(1,0));
        ret.get("GMMPRIOR").setMatrixData(i, dc.getPrior()*gmmprior);
        i++;
      }
      //ret.print("ret: ");
      
View Full Code Here

TOP

Related Classes of edu.gmu.seor.prognos.unbbayesplugin.cps.Jama.Matrix

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.