public Matrix compute(Matrix loghyper,Matrix X){
  if (loghyper.getColumnDimension() != 1 || loghyper.getRowDimension() != numParameters())   throw new IllegalArgumentException("Wrong number of hyperparameters, " + loghyper.getRowDimension() + " instead of "+ numParameters());
  final double ell=Math.exp(loghyper.get(0,0));
  final double em2=1 / (ell * ell);
  final double oneplusem2=1 + em2;
  final double sf2=Math.exp(2 * loghyper.get(1,0));
  final double s2=Math.exp(2 * loghyper.get(2,0));
  final int m=X.getRowDimension();
  final int n=X.getColumnDimension();
  double[][] x=X.getArray();
  q=new double[m][m];
  for (int i=0; i < m; i++) {
    for (int j=0; j < m; j++) {
      double t=0;
      for (int k=0; k < n; k++) {
        t+=x[i][k] * x[j][k] * em2;
      }
      q[i][j]=t;
    }
  }
  double[] dq=new double[m];
  for (int i=0; i < m; i++) {
    dq[i]=Math.sqrt(oneplusem2 + q[i][i]);
  }
  Matrix A=new Matrix(m,m);
  k=new double[m][m];
  double[][] a=A.getArray();
  for (int i=0; i < m; i++) {
    final double dqi=dq[i];
    for (int j=0; j < m; j++) {
      final double t=(em2 + q[i][j]) / (dqi * dq[j]);
      k[i][j]=t;
      a[i][j]=sf2 * Math.asin(t);
    }
    a[i][i]+=s2;
  }
  return A;
}

public Matrix compute ( Matrix loghyper , Matrix X ) { if ( loghyper . getColumnDimension ( ) != 1 || loghyper . getRowDimension ( ) != numParameters ( ) ) throw new IllegalArgumentException ( "Wrong number of hyperparameters, " + loghyper . getRowDimension ( ) + " instead of " + numParameters ( ) ) ; final double ell = Math . exp ( loghyper . get ( 0 , 0 ) ) ; final double em2 = 1 / ( ell * ell ) ; final double oneplusem2 = 1 + em2 ; final double sf2 = Math . exp ( 2 * loghyper . get ( 1 , 0 ) ) ; final double s2 = Math . exp ( 2 * loghyper . get ( 2 , 0 ) ) ; final int m = X . getRowDimension ( ) ; final int n = X . getColumnDimension ( ) ; double [ ] [ ] x = X . getArray ( ) ; q = new double [ m ] [ m ] ; for ( int i = 0 ; i < m ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { double t = 0 ; for ( int k = 0 ; k < n ; k ++ ) { t += x [ i ] [ k ] * x [ j ] [ k ] * em2 ; } q [ i ] [ j ] = t ; } } double [ ] dq = new double [ m ] ; for ( int i = 0 ; i < m ; i ++ ) { dq [ i ] = Math . sqrt ( oneplusem2 + q [ i ] [ i ] ) ; } Matrix A = new Matrix ( m , m ) ; k = new double [ m ] [ m ] ; double [ ] [ ] a = A . getArray ( ) ; for ( int i = 0 ; i < m ; i ++ ) { final double dqi = dq [ i ] ; for ( int j = 0 ; j < m ; j ++ ) { final double t = ( em2 + q [ i ] [ j ] ) / ( dqi * dq [ j ] ) ; k [ i ] [ j ] = t ; a [ i ] [ j ] = sf2 * Math . asin ( t ) ; } a [ i ] [ i ] += s2 ; } return A ; }
compute covariance matrix of a dataset x
