Program: 149517
Project: 149517
Buggy source:
private void canComputeLogLikelihoodRatio(BaseNonLinearFunction nlf){
  TestSettings.info(nlf.name);
  int n=maxx * maxx;
  double[] a=new double[]{1};
  nlf.initialise(a);
  RandomDataGenerator rdg=new RandomDataGenerator(TestSettings.getRandomGenerator());
  double[] x=new double[n];
  double[] u=new double[n];
  for (int i=0; i < n; i++) {
    u[i]=nlf.eval(i);
    if (u[i] > 0)     x[i]=rdg.nextPoisson(u[i]);
  }
  double ll=PoissonCalculator.logLikelihood(u,x);
  double mll=PoissonCalculator.maximumLogLikelihood(x);
  double llr=-2 * (ll - mll);
  double llr2=PoissonCalculator.logLikelihoodRatio(u,x);
  TestSettings.info("String_Node_Str",llr,llr2);
  Assert.assertEquals("String_Node_Str",llr,llr2,llr * 1e-10);
  double[] op=new double[x.length];
  for (int i=0; i < n; i++)   op[i]=PoissonCalculator.maximumLikelihood(x[i]);
  double max=Double.NEGATIVE_INFINITY;
  double maxa=0;
  int df=n - 1;
  ChiSquaredDistributionTable table=ChiSquaredDistributionTable.createUpperTailed(0.05,df);
  ChiSquaredDistributionTable table2=ChiSquaredDistributionTable.createUpperTailed(0.001,df);
  if (TestSettings.allow(LogLevel.INFO))   TestSettings.info("String_Node_Str",table.getCrititalValue(df),table.getSignificanceValue(),table2.getCrititalValue(df),table2.getSignificanceValue(),ChiSquaredDistributionTable.computeQValue(24,2),ChiSquaredDistributionTable.createUpperTailed(0.05,2).reject(24,2),ChiSquaredDistributionTable.getChiSquared(1e-6,2));
  for (int i=5; i <= 15; i++) {
    a[0]=(double)i / 10;
    nlf.initialise(a);
    for (int j=0; j < n; j++)     u[j]=nlf.eval(j);
    ll=PoissonCalculator.logLikelihood(u,x);
    llr=PoissonCalculator.logLikelihoodRatio(u,x);
    BigDecimal product=new BigDecimal(1);
    double ll2=0;
    for (int j=0; j < n; j++) {
      double p1=PoissonCalculator.likelihood(u[j],x[j]);
      ll2+=Math.log(p1);
      double ratio=p1 / op[j];
      product=product.multiply(new BigDecimal(ratio));
    }
    llr2=-2 * Math.log(product.doubleValue());
    double p=ChiSquaredDistributionTable.computePValue(llr,df);
    double q=ChiSquaredDistributionTable.computeQValue(llr,df);
    TestSettings.info("String_Node_Str",a[0],ll,ll2,llr,llr2,product.round(new MathContext(4)).toString(),p,q,table.reject(llr,df),table.getSignificanceValue(),table2.reject(llr,df),table2.getSignificanceValue());
    if (max < ll) {
      max=ll;
      maxa=a[0];
    }
    if (product.doubleValue() > 0) {
      Assert.assertEquals("String_Node_Str",ll,ll2,Math.abs(ll2) * 1e-10);
      Assert.assertEquals("String_Node_Str",llr,llr2,Math.abs(llr) * 1e-10);
    }
  }
  Assert.assertEquals("String_Node_Str",1,maxa,0);
}

Fixed version (ground truth):
private void canComputeLogLikelihoodRatio(BaseNonLinearFunction nlf){
  TestSettings.info(nlf.name);
  int n=maxx * maxx;
  double[] a=new double[]{1};
  nlf.initialise(a);
  RandomDataGenerator rdg=new RandomDataGenerator(TestSettings.getRandomGenerator());
  double[] x=new double[n];
  double[] u=new double[n];
  for (int i=0; i < n; i++) {
    u[i]=nlf.eval(i);
    if (u[i] > 0)     x[i]=rdg.nextPoisson(u[i]);
  }
  double ll=PoissonCalculator.logLikelihood(u,x);
  double mll=PoissonCalculator.maximumLogLikelihood(x);
  double llr=-2 * (ll - mll);
  double llr2=PoissonCalculator.logLikelihoodRatio(u,x);
  TestSettings.info("String_Node_Str",llr,llr2);
  TestAssert.assertEqualsRelative("String_Node_Str",llr,llr2,llr * 1e-10);
  double[] op=new double[x.length];
  for (int i=0; i < n; i++)   op[i]=PoissonCalculator.maximumLikelihood(x[i]);
  double max=Double.NEGATIVE_INFINITY;
  double maxa=0;
  int df=n - 1;
  ChiSquaredDistributionTable table=ChiSquaredDistributionTable.createUpperTailed(0.05,df);
  ChiSquaredDistributionTable table2=ChiSquaredDistributionTable.createUpperTailed(0.001,df);
  if (TestSettings.allow(LogLevel.INFO))   TestSettings.info("String_Node_Str",table.getCrititalValue(df),table.getSignificanceValue(),table2.getCrititalValue(df),table2.getSignificanceValue(),ChiSquaredDistributionTable.computeQValue(24,2),ChiSquaredDistributionTable.createUpperTailed(0.05,2).reject(24,2),ChiSquaredDistributionTable.getChiSquared(1e-6,2));
  for (int i=5; i <= 15; i++) {
    a[0]=(double)i / 10;
    nlf.initialise(a);
    for (int j=0; j < n; j++)     u[j]=nlf.eval(j);
    ll=PoissonCalculator.logLikelihood(u,x);
    llr=PoissonCalculator.logLikelihoodRatio(u,x);
    BigDecimal product=new BigDecimal(1);
    double ll2=0;
    for (int j=0; j < n; j++) {
      double p1=PoissonCalculator.likelihood(u[j],x[j]);
      ll2+=Math.log(p1);
      double ratio=p1 / op[j];
      product=product.multiply(new BigDecimal(ratio));
    }
    llr2=-2 * Math.log(product.doubleValue());
    double p=ChiSquaredDistributionTable.computePValue(llr,df);
    double q=ChiSquaredDistributionTable.computeQValue(llr,df);
    TestSettings.info("String_Node_Str",a[0],ll,ll2,llr,llr2,product.round(new MathContext(4)).toString(),p,q,table.reject(llr,df),table.getSignificanceValue(),table2.reject(llr,df),table2.getSignificanceValue());
    if (max < ll) {
      max=ll;
      maxa=a[0];
    }
    if (product.doubleValue() > 0) {
      TestAssert.assertEqualsRelative("String_Node_Str",ll,ll2,Math.abs(ll2) * 1e-10);
      TestAssert.assertEqualsRelative("String_Node_Str",llr,llr2,Math.abs(llr) * 1e-10);
    }
  }
  Assert.assertEquals("String_Node_Str",1,maxa,0);
}