public static TetradMatrix constructGramMatrix(List<Kernel> kernels,DataSet dataset,List<Node> nodes){
  int m=dataset.getNumRows();
  TetradMatrix gram=new TetradMatrix(m,m);
  for (int k=0; k < nodes.size(); k++) {
    Node node=nodes.get(k);
    int col=dataset.getColumn(node);
    Kernel kernel=kernels.get(k);
    for (int i=0; i < m; i++) {
      for (int j=i; j < m; j++) {
        double keval=kernel.eval(dataset.getDouble(i,col),dataset.getDouble(j,col));
        if (k == 0) {
          gram.set(i,j,keval);
        }
 else {
          keval*=gram.get(i,j);
          gram.set(i,j,keval);
        }
      }
    }
  }
  return gram;
}

public static TetradMatrix constructGramMatrix ( List < Kernel > kernels , DataSet dataset , List < Node > nodes ) { int m = dataset . getNumRows ( ) ; TetradMatrix gram = new TetradMatrix ( m , m ) ; for ( int k = 0 ; k < nodes . size ( ) ; k ++ ) { Node node = nodes . get ( k ) ; int col = dataset . getColumn ( node ) ; Kernel kernel = kernels . get ( k ) ; for ( int i = 0 ; i < m ; i ++ ) { for ( int j = i ; j < m ; j ++ ) { double keval = kernel . eval ( dataset . getDouble ( i , col ) , dataset . getDouble ( j , col ) ) ; if ( k == 0 ) { gram . set ( i , j , keval ) ; } else { keval *= gram . get ( i , j ) ; gram . set ( i , j , keval ) ; } } } } return gram ; }
constructs gram matrix for a given vector valued sample . the set of kernels corresponds to the variables in the set . the output matrix is the tensor product of gram matrices for each variable .
