public double probConstraint(OP constraint,int x,int y,int[] z){
  double p=0;
  logfact[0]=0;
  for (int i=1; i < logfact.length; i++) {
    logfact[i]=log(i) + logfact[i - 1];
  }
  logfact[0]=0;
  if (z.length > maxParents) {
    int maxConditioningNodes=z.length;
    maxParents=maxConditioningNodes;
    int[] _nodeDimension=Arrays.copyOf(nodeDimension,nodeDimension.length);
    Arrays.sort(_nodeDimension);
    int g1=_nodeDimension[_nodeDimension.length - 1];
    int g2=_nodeDimension[_nodeDimension.length - 2];
    maxCells=maxParents * g1 * g2* maxCases;
    parents=new int[maxNodes + 2][maxParents + 1];
    countsTree=new int[maxCells + 1];
    counts=new int[maxCells + 1];
  }
  int n=z[0];
  parents[x][0]=n;
  for (int i=1; i <= n; i++) {
    parents[x][i]=z[i];
  }
  double lnMarginalLikelihood_X=scoreNode(x,1);
  parents[y][0]=n;
  for (int i=1; i <= n; i++) {
    parents[y][i]=z[i];
  }
  double lnMarginalLikelihood_Y=scoreNode(y,2);
  double lnMarginalLikelihood_X_Y=lnMarginalLikelihood_X + lnMarginalLikelihood_Y;
  p=priorIndependent(x,y,z);
  double lnPrior_X_Y=Math.log(p);
  double score_X_Y=lnMarginalLikelihood_X_Y + lnPrior_X_Y;
  numberOfNodes++;
  int xy=numberOfNodes;
  for (int casei=1; casei <= numberOfCases; casei++) {
    int xValue=cases[casei][x];
    int yValue=cases[casei][y];
    cases[casei][xy]=(xValue - 1) * nodeDimension[y] + yValue;
  }
  nodeDimension[xy]=nodeDimension[x] * nodeDimension[y];
  parents[xy][0]=n;
  for (int i=1; i <= n; i++) {
    parents[xy][i]=z[i];
  }
  double lnMarginalLikelihood_XY=scoreNode(xy,3);
  numberOfNodes--;
  double lnTermPrior_X_Y=Math.log(p) / numberOfScores;
  double lnTermPrior_XY=Math.log(1 - Math.exp(lnTermPrior_X_Y));
  double scoreAll=0;
  for (int i=1; i <= numberOfScores; i++) {
    scoreAll+=lnXpluslnY(lnTermPrior_X_Y + (scores[i][1] + scores[i][2]),lnTermPrior_XY + scores[i][3]);
  }
  double probInd=Math.exp(score_X_Y - scoreAll);
  if (constraint == OP.independent) {
    p=probInd;
  }
 else {
    p=1.0 - probInd;
  }
  return p;
}

public double probConstraint ( OP constraint , int x , int y , int [ ] z ) { double p = 0 ; logfact [ 0 ] = 0 ; for ( int i = 1 ; i < logfact . length ; i ++ ) { logfact [ i ] = log ( i ) + logfact [ i - 1 ] ; } logfact [ 0 ] = 0 ; if ( z . length > maxParents ) { int maxConditioningNodes = z . length ; maxParents = maxConditioningNodes ; int [ ] _nodeDimension = Arrays . copyOf ( nodeDimension , nodeDimension . length ) ; Arrays . sort ( _nodeDimension ) ; int g1 = _nodeDimension [ _nodeDimension . length - 1 ] ; int g2 = _nodeDimension [ _nodeDimension . length - 2 ] ; maxCells = maxParents * g1 * g2 * maxCases ; parents = new int [ maxNodes + 2 ] [ maxParents + 1 ] ; countsTree = new int [ maxCells + 1 ] ; counts = new int [ maxCells + 1 ] ; } int n = z [ 0 ] ; parents [ x ] [ 0 ] = n ; for ( int i = 1 ; i <= n ; i ++ ) { parents [ x ] [ i ] = z [ i ] ; } double lnMarginalLikelihood_X = scoreNode ( x , 1 ) ; parents [ y ] [ 0 ] = n ; for ( int i = 1 ; i <= n ; i ++ ) { parents [ y ] [ i ] = z [ i ] ; } double lnMarginalLikelihood_Y = scoreNode ( y , 2 ) ; double lnMarginalLikelihood_X_Y = lnMarginalLikelihood_X + lnMarginalLikelihood_Y ; p = priorIndependent ( x , y , z ) ; double lnPrior_X_Y = Math . log ( p ) ; double score_X_Y = lnMarginalLikelihood_X_Y + lnPrior_X_Y ; numberOfNodes ++ ; int xy = numberOfNodes ; for ( int casei = 1 ; casei <= numberOfCases ; casei ++ ) { int xValue = cases [ casei ] [ x ] ; int yValue = cases [ casei ] [ y ] ; cases [ casei ] [ xy ] = ( xValue - 1 ) * nodeDimension [ y ] + yValue ; } nodeDimension [ xy ] = nodeDimension [ x ] * nodeDimension [ y ] ; parents [ xy ] [ 0 ] = n ; for ( int i = 1 ; i <= n ; i ++ ) { parents [ xy ] [ i ] = z [ i ] ; } double lnMarginalLikelihood_XY = scoreNode ( xy , 3 ) ; numberOfNodes -- ; double lnTermPrior_X_Y = Math . log ( p ) / numberOfScores ; double lnTermPrior_XY = Math . log ( 1 - Math . exp ( lnTermPrior_X_Y ) ) ; double scoreAll = 0 ; for ( int i = 1 ; i <= numberOfScores ; i ++ ) { scoreAll += lnXpluslnY ( lnTermPrior_X_Y + ( scores [ i ] [ 1 ] + scores [ i ] [ 2 ] ) , lnTermPrior_XY + scores [ i ] [ 3 ] ) ; } double probInd = Math . exp ( score_X_Y - scoreAll ) ; if ( constraint == OP . independent ) { p = probInd ; } else { p = 1.0 - probInd ; } return p ; }
this function takes a constraint , which has a value of either op . dependent or op . independent , of the form " x independent y given z " or " x dependent y given z " and returns a probability for that constraint given the data in cases and assumed prior probability for that constraint given the data in cases and assumed prior probabilities . currently , it assumes uniform parameter priors and a structure prior of 0 . 5 . a structure prior of 0 . 5 means taht a priori we have that p ( x independent y given z ) = p ( x dependent y given z ) = 0 . 5 . < p / > z [ 0 ] is the length of the set represented by array z . for an example , z [ 0 ] = 1 represents the set z of size 1 . z & lsqb ; 0 & rsqb ; = 0 represents an empty set . < p / > set z with two elements : z = & lcub ; 3 , 2 & rcub ; z & lsqb ; 0 & rsqb ; = 2 / / set z has two elements ( length of 2 ) z [ 1 ] = 3 / / first element z [ 2 ] = 2 / / second element . < p / > empty set : z = & lcub ; & rcub ; z & lsqb ; 0 & rsqb ; = 0
