public double localScore(int i,int... parents){
  for (  int p : parents)   if (forbidden.contains(p))   return Double.NaN;
  double residualVariance=covariances.get(i,i);
  int n=getSampleSize();
  int p=parents.length;
  Matrix covxx=getSelection1(covariances,parents);
  try {
    Matrix covxxInv=covxx.inverse();
    Matrix covxy=getSelection2(covariances,parents,i);
    Matrix b=covxxInv.times(covxy);
    double dot=0.0;
    for (int j=0; j < covxy.getRowDimension(); j++) {
      for (int k=0; k < covxy.getColumnDimension(); k++) {
        dot+=covxy.get(j,k) * b.get(j,k);
      }
    }
    residualVariance-=dot;
    if (residualVariance <= 0) {
      if (isVerbose()) {
        out.println("Nonpositive residual varianceY: resVar / varianceY = " + (residualVariance / covariances.get(i,i)));
      }
      return Double.NaN;
    }
    double c=getPenaltyDiscount();
    return score(residualVariance,n,logn,p,c);
  }
 catch (  Exception e) {
    boolean removedOne=true;
    while (removedOne) {
      List<Integer> _parents=new ArrayList<>();
      for (int y=0; y < parents.length; y++)       _parents.add(parents[y]);
      _parents.removeAll(forbidden);
      parents=new int[_parents.size()];
      for (int y=0; y < _parents.size(); y++)       parents[y]=_parents.get(y);
      removedOne=printMinimalLinearlyDependentSet(parents,covariances);
    }
    return Double.NaN;
  }
}

public double localScore ( int i , int ... parents ) { for ( int p : parents ) if ( forbidden . contains ( p ) ) return Double . NaN ; double residualVariance = covariances . get ( i , i ) ; int n = getSampleSize ( ) ; int p = parents . length ; Matrix covxx = getSelection1 ( covariances , parents ) ; try { Matrix covxxInv = covxx . inverse ( ) ; Matrix covxy = getSelection2 ( covariances , parents , i ) ; Matrix b = covxxInv . times ( covxy ) ; double dot = 0.0 ; for ( int j = 0 ; j < covxy . getRowDimension ( ) ; j ++ ) { for ( int k = 0 ; k < covxy . getColumnDimension ( ) ; k ++ ) { dot += covxy . get ( j , k ) * b . get ( j , k ) ; } } residualVariance -= dot ; if ( residualVariance <= 0 ) { if ( isVerbose ( ) ) { out . println ( "Nonpositive residual varianceY: resVar / varianceY = " + ( residualVariance / covariances . get ( i , i ) ) ) ; } return Double . NaN ; } double c = getPenaltyDiscount ( ) ; return score ( residualVariance , n , logn , p , c ) ; } catch ( Exception e ) { boolean removedOne = true ; while ( removedOne ) { List < Integer > _parents = new ArrayList < > ( ) ; for ( int y = 0 ; y < parents . length ; y ++ ) _parents . add ( parents [ y ] ) ; _parents . removeAll ( forbidden ) ; parents = new int [ _parents . size ( ) ] ; for ( int y = 0 ; y < _parents . size ( ) ; y ++ ) parents [ y ] = _parents . get ( y ) ; removedOne = printMinimalLinearlyDependentSet ( parents , covariances ) ; } return Double . NaN ; } }
calculates the sample likelihood and bic score for i given its parents in a simple sem model
