Program: 149537
Project: 149537
Buggy source:
@Test public void gradientProcedureComputesSameWithPrecomputed(){
  int iter=10;
  rdg=new RandomDataGenerator(new Well19937c(30051977));
  ErfGaussian2DFunction f1=(ErfGaussian2DFunction)GaussianFunctionFactory.create2D(1,10,10,GaussianFunctionFactory.FIT_ERF_FREE_CIRCLE,null);
  ErfGaussian2DFunction f2=(ErfGaussian2DFunction)GaussianFunctionFactory.create2D(2,10,10,GaussianFunctionFactory.FIT_ERF_FREE_CIRCLE,null);
  double[] a1=new double[7];
  double[] a2=new double[13];
  final double[] x=new double[f1.size()];
  final double[] b=new double[f1.size()];
  for (int i=0; i < iter; i++) {
    a2[Gaussian2DFunction.BACKGROUND]=rdg.nextUniform(0.1,0.3);
    a2[Gaussian2DFunction.SIGNAL]=rdg.nextUniform(100,300);
    a2[Gaussian2DFunction.X_POSITION]=rdg.nextUniform(3,5);
    a2[Gaussian2DFunction.Y_POSITION]=rdg.nextUniform(3,5);
    a2[Gaussian2DFunction.X_SD]=rdg.nextUniform(1,1.3);
    a2[Gaussian2DFunction.Y_SD]=rdg.nextUniform(1,1.3);
    a2[6 + Gaussian2DFunction.SIGNAL]=rdg.nextUniform(100,300);
    a2[6 + Gaussian2DFunction.X_POSITION]=rdg.nextUniform(5,7);
    a2[6 + Gaussian2DFunction.Y_POSITION]=rdg.nextUniform(5,7);
    a2[6 + Gaussian2DFunction.X_SD]=rdg.nextUniform(1,1.3);
    a2[6 + Gaussian2DFunction.Y_SD]=rdg.nextUniform(1,1.3);
    f2.initialise0(a2);
    f1.forEach(new ValueProcedure(){
      int k=0;
      public void execute(      double value){
        x[k++]=(value > 0) ? rdg.nextPoisson(value) : 0;
      }
    }
);
    a1[Gaussian2DFunction.BACKGROUND]=0;
    for (int j=1; j < 7; j++)     a1[j]=a2[6 + j];
    f1.initialise0(a1);
    f1.forEach(new ValueProcedure(){
      int k=0;
      public void execute(      double value){
        b[k++]=value;
      }
    }
);
    for (int j=0; j < 7; j++)     a1[j]=a2[j];
    NewtonRaphsonGradient2Procedure p12=NewtonRaphsonGradient2ProcedureFactory.create(x,f2);
    double[] up1=Arrays.copyOf(p12.computeUpdate(a2),f1.getNumberOfGradients());
    NewtonRaphsonGradient2Procedure p1b2=NewtonRaphsonGradient2ProcedureFactory.create(x,b,f1);
    double[] up2=p1b2.computeUpdate(a1);
    Assert.assertArrayEquals("String_Node_Str" + i,p12.u,p1b2.u,1e-10);
    Assert.assertArrayEquals("String_Node_Str" + i,up1,up2,1e-10);
    double[] v1=p12.computeValue(a2);
    double[] v2=p1b2.computeValue(a1);
    Assert.assertArrayEquals("String_Node_Str" + i,v1,v2,1e-10);
    double[] d1=Arrays.copyOf(p12.computeFirstDerivative(a2),f1.getNumberOfGradients());
    double[] d2=p1b2.computeFirstDerivative(a1);
    Assert.assertArrayEquals("String_Node_Str" + i,d1,d2,1e-10);
  }
}

Fixed version (ground truth):
@Test public void gradientProcedureComputesSameWithPrecomputed(){
  int iter=10;
  rdg=new RandomDataGenerator(new Well19937c(30051977));
  ErfGaussian2DFunction f1=(ErfGaussian2DFunction)GaussianFunctionFactory.create2D(1,10,10,GaussianFunctionFactory.FIT_ERF_FREE_CIRCLE,null);
  ErfGaussian2DFunction f2=(ErfGaussian2DFunction)GaussianFunctionFactory.create2D(2,10,10,GaussianFunctionFactory.FIT_ERF_FREE_CIRCLE,null);
  double[] a1=new double[7];
  double[] a2=new double[13];
  final double[] x=new double[f1.size()];
  final double[] b=new double[f1.size()];
  for (int i=0; i < iter; i++) {
    a2[Gaussian2DFunction.BACKGROUND]=rdg.nextUniform(0.1,0.3);
    a2[Gaussian2DFunction.SIGNAL]=rdg.nextUniform(100,300);
    a2[Gaussian2DFunction.X_POSITION]=rdg.nextUniform(3,5);
    a2[Gaussian2DFunction.Y_POSITION]=rdg.nextUniform(3,5);
    a2[Gaussian2DFunction.X_SD]=rdg.nextUniform(1,1.3);
    a2[Gaussian2DFunction.Y_SD]=rdg.nextUniform(1,1.3);
    a2[6 + Gaussian2DFunction.SIGNAL]=rdg.nextUniform(100,300);
    a2[6 + Gaussian2DFunction.X_POSITION]=rdg.nextUniform(5,7);
    a2[6 + Gaussian2DFunction.Y_POSITION]=rdg.nextUniform(5,7);
    a2[6 + Gaussian2DFunction.X_SD]=rdg.nextUniform(1,1.3);
    a2[6 + Gaussian2DFunction.Y_SD]=rdg.nextUniform(1,1.3);
    f2.initialise0(a2);
    f1.forEach(new ValueProcedure(){
      int k=0;
      public void execute(      double value){
        x[k++]=(value > 0) ? rdg.nextPoisson(value) : 0;
      }
    }
);
    a1[Gaussian2DFunction.BACKGROUND]=0;
    for (int j=1; j < 7; j++)     a1[j]=a2[6 + j];
    f1.initialise0(a1);
    f1.forEach(new ValueProcedure(){
      int k=0;
      public void execute(      double value){
        b[k++]=value;
      }
    }
);
    for (int j=0; j < 7; j++)     a1[j]=a2[j];
    NewtonRaphsonGradient2Procedure p12=NewtonRaphsonGradient2ProcedureFactory.create(x,f2);
    p12.computeUpdate(a2);
    double[] up1=Arrays.copyOf(p12.getUpdate(),f1.getNumberOfGradients());
    NewtonRaphsonGradient2Procedure p1b2=NewtonRaphsonGradient2ProcedureFactory.create(x,b,f1);
    p1b2.computeUpdate(a1);
    double[] up2=p1b2.getUpdate();
    Assert.assertArrayEquals("String_Node_Str" + i,p12.u,p1b2.u,1e-10);
    Assert.assertArrayEquals("String_Node_Str" + i,up1,up2,1e-10);
    double[] v1=p12.computeValue(a2);
    double[] v2=p1b2.computeValue(a1);
    Assert.assertArrayEquals("String_Node_Str" + i,v1,v2,1e-10);
    double[] d1=Arrays.copyOf(p12.computeFirstDerivative(a2),f1.getNumberOfGradients());
    double[] d2=p1b2.computeFirstDerivative(a1);
    Assert.assertArrayEquals("String_Node_Str" + i,d1,d2,1e-10);
  }
}