コード例 #1
0
  public double logPdf(double[] x) {
    Matrix W = new Matrix(x, dim, dim);
    double logDensity = 0;

    //	    System.err.println("here");
    //	    double det = 0;
    //	    try {
    //	        det = W.determinant();
    //	    }   catch (IllegalDimension illegalDimension) {
    //            illegalDimension.printStackTrace();
    //        }
    //	    if( det < 0 ) {
    //		    System.err.println("not positive definite");
    //		    return Double.NEGATIVE_INFINITY;
    //	    }

    try {
      logDensity = Math.log(W.determinant());

      logDensity *= -0.5;
      logDensity *= df + dim + 1;

      Matrix product = S.product(W.inverse());

      for (int i = 0; i < dim; i++) logDensity -= 0.5 * product.component(i, i);

    } catch (IllegalDimension illegalDimension) {
      illegalDimension.printStackTrace();
    }

    logDensity += logNormalizationConstant;
    return logDensity;
  }
コード例 #2
0
 private void computeNormalizationConstant() {
   logNormalizationConstant = 0;
   try {
     logNormalizationConstant = df / 2.0 * Math.log(new Matrix(scaleMatrix).determinant());
   } catch (IllegalDimension illegalDimension) {
     illegalDimension.printStackTrace();
   }
   logNormalizationConstant -= df * dim / 2.0 * Math.log(2);
   logNormalizationConstant -= dim * (dim - 1) / 4.0 * Math.log(Math.PI);
   for (int i = 1; i <= dim; i++) {
     logNormalizationConstant -= GammaFunction.lnGamma((df + 1 - i) / 2.0);
   }
 }