Program: 72756
Project: 72756
Buggy source:
/** 
 * Generate a sample from a multivariate Gaussian distribution.
 * @param type The type of the argument to the corresponding function.
 * @return The type of the value returned from the corresponding function.
 */
public static ArrayToken multivariateGaussian(ArrayToken mean,DoubleMatrixToken covariance) throws IllegalActionException {
  int N=mean.length();
  double[][] S=covariance.doubleMatrix();
  if ((covariance.getColumnCount() != N) || (covariance.getRowCount() != covariance.getColumnCount())) {
    throw new IllegalActionException("String_Node_Str" + "String_Node_Str");
  }
  for (int i=0; i < N; i++) {
    for (int j=0; j < i; j++) {
      if (S[i][j] != S[j][i]) {
        throw new IllegalActionException("String_Node_Str");
      }
    }
  }
  double[][] L=new double[N][N];
  for (int i=0; i < N; i++) {
    for (int j=0; j <= i; j++) {
      double lowerSum=0;
      for (int k=0; k < j; k++) {
        lowerSum+=L[i][k] * L[j][k];
      }
      if (i != j) {
        L[i][j]=1.0 / L[j][j] * (S[i][j] - lowerSum);
      }
 else {
        L[i][j]=Math.pow(S[i][i] - lowerSum,0.5);
      }
    }
  }
  ArrayToken uncorrelated=gaussian(0,1,N);
  Token[] uncorrelatedTokens=uncorrelated.arrayValue();
  Token[] correlatedTokens=new Token[N];
  double[] correlatedSamples=new double[N];
  for (int i=0; i < N; i++) {
    for (int j=0; j < N; j++) {
      double uncorr=((DoubleToken)uncorrelatedTokens[j]).doubleValue();
      correlatedSamples[i]+=L[i][j] * uncorr;
    }
    correlatedTokens[i]=new DoubleToken(correlatedSamples[i]);
  }
  return new ArrayToken(correlatedTokens);
}

Fixed version (ground truth):
/** 
 * Generate a sample from a multivariate Gaussian distribution.
 * @param type The type of the argument to the corresponding function.
 * @return The type of the value returned from the corresponding function.
 */
public static ArrayToken multivariateGaussian(ArrayToken mean,DoubleMatrixToken covariance) throws IllegalActionException {
  int N=mean.length();
  double[][] S=covariance.doubleMatrix();
  if ((covariance.getColumnCount() != N) || (covariance.getRowCount() != covariance.getColumnCount())) {
    throw new IllegalActionException("String_Node_Str" + "String_Node_Str");
  }
 else   if (!BaseType.DOUBLE.isCompatible(mean.getElementType())) {
    throw new IllegalActionException("String_Node_Str");
  }
  for (int i=0; i < N; i++) {
    for (int j=0; j < i; j++) {
      if (S[i][j] != S[j][i]) {
        throw new IllegalActionException("String_Node_Str");
      }
    }
  }
  double[][] L=new double[N][N];
  for (int i=0; i < N; i++) {
    for (int j=0; j <= i; j++) {
      double lowerSum=0;
      for (int k=0; k < j; k++) {
        lowerSum+=L[i][k] * L[j][k];
      }
      if (i != j) {
        L[i][j]=1.0 / L[j][j] * (S[i][j] - lowerSum);
      }
 else {
        L[i][j]=Math.pow(S[i][i] - lowerSum,0.5);
      }
    }
  }
  ArrayToken uncorrelated=gaussian(0,1,N);
  Token[] uncorrelatedTokens=uncorrelated.arrayValue();
  Token[] correlatedTokens=new Token[N];
  double[] correlatedSamples=new double[N];
  Token[] meanArray=mean.arrayValue();
  for (int i=0; i < N; i++) {
    for (int j=0; j < N; j++) {
      double uncorr=((DoubleToken)uncorrelatedTokens[j]).doubleValue();
      correlatedSamples[i]+=L[i][j] * uncorr;
    }
    correlatedTokens[i]=new DoubleToken(correlatedSamples[i]).add(meanArray[i]);
  }
  return new ArrayToken(BaseType.DOUBLE,correlatedTokens);
}