private double empiricalHSIC(TetradMatrix Ky,TetradMatrix Kx,TetradMatrix Kz,int m){
  TetradMatrix Kyx=Ky.times(Kx);
  TetradMatrix Kyz=Ky.times(Kz);
  TetradMatrix Kzx=Kz.times(Kx);
  TetradMatrix Kzreg=Kz.copy();
  for (int i=0; i < m; i++) {
    double ent=(Kzreg.get(i,i) + this.regularizer);
    Kzreg.set(i,i,ent);
  }
  TetradMatrix A=Kzreg.inverse();
  Kzreg=A.times(A);
  TetradMatrix Kyzzregzx=new TetradMatrix(m,m);
  A=Kyz.times(Kzreg);
  Kyzzregzx=A.times(Kzx);
  TetradMatrix Kyzzregzxzzregz=Kyzzregzx.copy();
  Kyzzregzxzzregz=Kyzzregzx.times(Kz);
  A=Kyzzregzxzzregz.times(Kzreg);
  Kyzzregzxzzregz=A.times(Kz);
  double empHSIC=0.0;
  for (int i=0; i < m; i++) {
    empHSIC+=Kyx.get(i,i);
    empHSIC+=(-2 * Kyzzregzx.get(i,i));
    empHSIC+=Kyzzregzxzzregz.get(i,i);
  }
  empHSIC/=Math.pow(m - 1,2);
  double Bz=0.0;
  for (int i=0; i < (m - 1); i++) {
    for (int j=(i + 1); j < m; j++) {
      Bz+=Math.pow(Kz.get(i,j),2);
      Bz+=Math.pow(Kz.get(j,i),2);
    }
  }
  Bz=(m * (m - 1)) / Bz;
  empHSIC*=Bz;
  return empHSIC;
}

private double empiricalHSIC ( TetradMatrix Ky , TetradMatrix Kx , TetradMatrix Kz , int m ) { TetradMatrix Kyx = Ky . times ( Kx ) ; TetradMatrix Kyz = Ky . times ( Kz ) ; TetradMatrix Kzx = Kz . times ( Kx ) ; TetradMatrix Kzreg = Kz . copy ( ) ; for ( int i = 0 ; i < m ; i ++ ) { double ent = ( Kzreg . get ( i , i ) + this . regularizer ) ; Kzreg . set ( i , i , ent ) ; } TetradMatrix A = Kzreg . inverse ( ) ; Kzreg = A . times ( A ) ; TetradMatrix Kyzzregzx = new TetradMatrix ( m , m ) ; A = Kyz . times ( Kzreg ) ; Kyzzregzx = A . times ( Kzx ) ; TetradMatrix Kyzzregzxzzregz = Kyzzregzx . copy ( ) ; Kyzzregzxzzregz = Kyzzregzx . times ( Kz ) ; A = Kyzzregzxzzregz . times ( Kzreg ) ; Kyzzregzxzzregz = A . times ( Kz ) ; double empHSIC = 0.0 ; for ( int i = 0 ; i < m ; i ++ ) { empHSIC += Kyx . get ( i , i ) ; empHSIC += ( - 2 * Kyzzregzx . get ( i , i ) ) ; empHSIC += Kyzzregzxzzregz . get ( i , i ) ; } empHSIC /= Math . pow ( m - 1 , 2 ) ; double Bz = 0.0 ; for ( int i = 0 ; i < ( m - 1 ) ; i ++ ) { for ( int j = ( i + 1 ) ; j < m ; j ++ ) { Bz += Math . pow ( Kz . get ( i , j ) , 2 ) ; Bz += Math . pow ( Kz . get ( j , i ) , 2 ) ; } } Bz = ( m * ( m - 1 ) ) / Bz ; empHSIC *= Bz ; return empHSIC ; }
empirical conditional hilbert - schmidt dependence measure y and x given z
