public int tetradScore(int v1,int v2,int v3,int v4){
  int count=0;
  double p_12=CorrelationMatrix.getValue(v1,v2);
  double p_13=CorrelationMatrix.getValue(v1,v3);
  double p_14=CorrelationMatrix.getValue(v1,v4);
  double p_23=CorrelationMatrix.getValue(v2,v3);
  double p_24=CorrelationMatrix.getValue(v2,v4);
  double p_34=CorrelationMatrix.getValue(v3,v4);
  for (int i=0; i < 3; i++) {
    bvalues[i]=false;
  }
  if (Math.abs(p_12 * p_34 - p_13 * p_24) < epsilon) {
    count++;
    bvalues[0]=true;
  }
  if (Math.abs(p_12 * p_34 - p_14 * p_23) < epsilon) {
    count++;
    bvalues[1]=true;
  }
  if (Math.abs(p_13 * p_24 - p_14 * p_23) < epsilon) {
    count++;
    bvalues[2]=true;
  }
  return count;
}

public int tetradScore ( int v1 , int v2 , int v3 , int v4 ) { int count = 0 ; double p_12 = CorrelationMatrix . getValue ( v1 , v2 ) ; double p_13 = CorrelationMatrix . getValue ( v1 , v3 ) ; double p_14 = CorrelationMatrix . getValue ( v1 , v4 ) ; double p_23 = CorrelationMatrix . getValue ( v2 , v3 ) ; double p_24 = CorrelationMatrix . getValue ( v2 , v4 ) ; double p_34 = CorrelationMatrix . getValue ( v3 , v4 ) ; for ( int i = 0 ; i < 3 ; i ++ ) { bvalues [ i ] = false ; } if ( Math . abs ( p_12 * p_34 - p_13 * p_24 ) < epsilon ) { count ++ ; bvalues [ 0 ] = true ; } if ( Math . abs ( p_12 * p_34 - p_14 * p_23 ) < epsilon ) { count ++ ; bvalues [ 1 ] = true ; } if ( Math . abs ( p_13 * p_24 - p_14 * p_23 ) < epsilon ) { count ++ ; bvalues [ 2 ] = true ; } return count ; }
population scores : assumes correlationmatrix is the population covariance correlationmatrix . due to numerical rounding problems , we need a parameter epsilon to control it . nothing here is implemented for discrete data ( yet ) .
