nus-yam/ex-repair huggingface dataset:
Program: 57078
Project: 57078
Buggy source:
/** 
 * Compute the <i>distance</i> between two rotations. <p>The <i>distance</i> is intended here as a way to check if two rotations are almost similar (i.e. they transform vectors the same way) or very different. It is mathematically defined as the angle of the rotation r that prepended to one of the rotations gives the other one:</p> <pre> r<sub>1</sub>(r) = r<sub>2</sub> </pre> <p>This distance is an angle between 0 and &pi;. Its value is the smallest possible upper bound of the angle in radians between r<sub>1</sub>(v) and r<sub>2</sub>(v) for all possible vectors v. This upper bound is reached for some v. The distance is equal to 0 if and only if the two rotations are identical.</p> <p>Comparing two rotations should always be done using this value rather than for example comparing the components of the quaternions. It is much more stable, and has a geometric meaning. Also comparing quaternions components is error prone since for example quaternions (0.36, 0.48, -0.48, -0.64) and (-0.36, -0.48, 0.48, 0.64) represent exactly the same rotation despite their components are different (they are exact opposites).</p>
 * @param r1 first rotation
 * @param r2 second rotation
 * @return <i>distance</i> between r1 and r2
 */
public static double distance(Rotation r1,Rotation r2){
  return r1.composeInverseInternal(r2).getAngle();
}

Fixed version (ground truth):
/** 
 * Compute the <i>distance</i> between two rotations. <p>The <i>distance</i> is intended here as a way to check if two rotations are almost similar (i.e. they transform vectors the same way) or very different. It is mathematically defined as the angle of the rotation r that prepended to one of the rotations gives the other one:</p> <div style="white-space: pre"><code> r<sub>1</sub>(r) = r<sub>2</sub> </code></div> <p>This distance is an angle between 0 and &pi;. Its value is the smallest possible upper bound of the angle in radians between r<sub>1</sub>(v) and r<sub>2</sub>(v) for all possible vectors v. This upper bound is reached for some v. The distance is equal to 0 if and only if the two rotations are identical.</p> <p>Comparing two rotations should always be done using this value rather than for example comparing the components of the quaternions. It is much more stable, and has a geometric meaning. Also comparing quaternions components is error prone since for example quaternions (0.36, 0.48, -0.48, -0.64) and (-0.36, -0.48, 0.48, 0.64) represent exactly the same rotation despite their components are different (they are exact opposites).</p>
 * @param r1 first rotation
 * @param r2 second rotation
 * @return <i>distance</i> between r1 and r2
 */
public static double distance(Rotation r1,Rotation r2){
  return r1.composeInverseInternal(r2).getAngle();
}
Program: 57081
Project: 57081
Buggy source:
/** 
 * Computes cos(a)  Used when 0 < a < pi/4. Uses the classic Taylor series for cosine.  1 - x**2/2! + x**4/4!  ...
 * @param a number from which cosine is desired, in split form
 * @return cos(a)
 */
protected static Dfp cosInternal(Dfp a[]){
  final Dfp one=a[0].getOne();
  Dfp x=one;
  Dfp y=one;
  Dfp c=a[0].add(a[1]);
  c=c.multiply(c);
  Dfp fact=one;
  Dfp py=new Dfp(y);
  for (int i=2; i < 90; i+=2) {
    x=x.multiply(c);
    x=x.negate();
    fact=fact.divide((i - 1) * i);
    y=y.add(x.multiply(fact));
    if (y.equals(py)) {
      break;
    }
    py=new Dfp(y);
  }
  return y;
}

Fixed version (ground truth):
/** 
 * Computes cos(a)  Used when   {@code 0 < a < pi/4}. Uses the classic Taylor series for cosine.  1 - x**2/2! + x**4/4!  ...
 * @param a number from which cosine is desired, in split form
 * @return cos(a)
 */
protected static Dfp cosInternal(Dfp a[]){
  final Dfp one=a[0].getOne();
  Dfp x=one;
  Dfp y=one;
  Dfp c=a[0].add(a[1]);
  c=c.multiply(c);
  Dfp fact=one;
  Dfp py=new Dfp(y);
  for (int i=2; i < 90; i+=2) {
    x=x.multiply(c);
    x=x.negate();
    fact=fact.divide((i - 1) * i);
    y=y.add(x.multiply(fact));
    if (y.equals(py)) {
      break;
    }
    py=new Dfp(y);
  }
  return y;
}
Program: 57082
Project: 57082
Buggy source:
/** 
 * Computes e to the given power. Where -1 < a < 1.  Use the classic Taylor series.  1 + x**2/2! + x**3/3! + x**4/4!  ...
 * @param a power at which e should be raised
 * @return e<sup>a</sup>
 */
protected static Dfp expInternal(final Dfp a){
  Dfp y=a.getOne();
  Dfp x=a.getOne();
  Dfp fact=a.getOne();
  Dfp py=new Dfp(y);
  for (int i=1; i < 90; i++) {
    x=x.multiply(a);
    fact=fact.divide(i);
    y=y.add(x.multiply(fact));
    if (y.equals(py)) {
      break;
    }
    py=new Dfp(y);
  }
  return y;
}

Fixed version (ground truth):
/** 
 * Computes e to the given power. Where   {@code -1 < a < 1}.  Use the classic Taylor series.  {@code 1 + x**2/2! + x**3/3! + x**4/4!  ... }
 * @param a power at which e should be raised
 * @return e<sup>a</sup>
 */
protected static Dfp expInternal(final Dfp a){
  Dfp y=a.getOne();
  Dfp x=a.getOne();
  Dfp fact=a.getOne();
  Dfp py=new Dfp(y);
  for (int i=1; i < 90; i++) {
    x=x.multiply(a);
    fact=fact.divide(i);
    y=y.add(x.multiply(fact));
    if (y.equals(py)) {
      break;
    }
    py=new Dfp(y);
  }
  return y;
}
Program: 57083
Project: 57083
Buggy source:
/** 
 * Computes sin(a)  Used when 0 < a < pi/4. Uses the classic Taylor series.  x - x**3/3! + x**5/5!  ...
 * @param a number from which sine is desired, in split form
 * @return sin(a)
 */
protected static Dfp sinInternal(Dfp a[]){
  Dfp c=a[0].add(a[1]);
  Dfp y=c;
  c=c.multiply(c);
  Dfp x=y;
  Dfp fact=a[0].getOne();
  Dfp py=new Dfp(y);
  for (int i=3; i < 90; i+=2) {
    x=x.multiply(c);
    x=x.negate();
    fact=fact.divide((i - 1) * i);
    y=y.add(x.multiply(fact));
    if (y.equals(py)) {
      break;
    }
    py=new Dfp(y);
  }
  return y;
}

Fixed version (ground truth):
/** 
 * Computes sin(a)  Used when   {@code} {@code 0 < a < pi/4}}. Uses the classic Taylor series.    {@code x - x**3/3! + x**5/5!  ... }
 * @param a number from which sine is desired, in split form
 * @return sin(a)
 */
protected static Dfp sinInternal(Dfp a[]){
  Dfp c=a[0].add(a[1]);
  Dfp y=c;
  c=c.multiply(c);
  Dfp x=y;
  Dfp fact=a[0].getOne();
  Dfp py=new Dfp(y);
  for (int i=3; i < 90; i+=2) {
    x=x.multiply(c);
    x=x.negate();
    fact=fact.divide((i - 1) * i);
    y=y.add(x.multiply(fact));
    if (y.equals(py)) {
      break;
    }
    py=new Dfp(y);
  }
  return y;
}
Program: 57087
Project: 57087
Buggy source:
/** 
 * Generates a representation of a permutation corresponding to a permutation which yields <code>permutedData</code> when applied to <code>originalData</code>. This method can be viewed as an inverse to   {@link #decode(List)}.
 * @param < S > type of the data
 * @param originalData the original, unpermuted data
 * @param permutedData the data, somehow permuted
 * @return representation of a permutation corresponding to the permutation<code>originalData -> permutedData</code>
 * @throws DimensionMismatchException iff the length of <code>originalData</code>and <code>permutedData</code> lists are not equal
 * @throws MathIllegalArgumentException iff the <code>permutedData</code> and<code>originalData</code> lists contain different data
 */
public static <S>List<Double> inducedPermutation(final List<S> originalData,final List<S> permutedData) throws DimensionMismatchException, MathIllegalArgumentException {
  if (originalData.size() != permutedData.size()) {
    throw new DimensionMismatchException(permutedData.size(),originalData.size());
  }
  int l=originalData.size();
  List<S> origDataCopy=new ArrayList<>(originalData);
  Double[] res=new Double[l];
  for (int i=0; i < l; i++) {
    int index=origDataCopy.indexOf(permutedData.get(i));
    if (index == -1) {
      throw new MathIllegalArgumentException(LocalizedFormats.DIFFERENT_ORIG_AND_PERMUTED_DATA);
    }
    res[index]=(double)i / l;
    origDataCopy.set(index,null);
  }
  return Arrays.asList(res);
}

Fixed version (ground truth):
/** 
 * Generates a representation of a permutation corresponding to a permutation which yields <code>permutedData</code> when applied to <code>originalData</code>. This method can be viewed as an inverse to   {@link #decode(List)}.
 * @param < S > type of the data
 * @param originalData the original, unpermuted data
 * @param permutedData the data, somehow permuted
 * @return representation of a permutation corresponding to the permutation{@code originalData -> permutedData}
 * @throws DimensionMismatchException iff the length of <code>originalData</code>and <code>permutedData</code> lists are not equal
 * @throws MathIllegalArgumentException iff the <code>permutedData</code> and<code>originalData</code> lists contain different data
 */
public static <S>List<Double> inducedPermutation(final List<S> originalData,final List<S> permutedData) throws DimensionMismatchException, MathIllegalArgumentException {
  if (originalData.size() != permutedData.size()) {
    throw new DimensionMismatchException(permutedData.size(),originalData.size());
  }
  int l=originalData.size();
  List<S> origDataCopy=new ArrayList<>(originalData);
  Double[] res=new Double[l];
  for (int i=0; i < l; i++) {
    int index=origDataCopy.indexOf(permutedData.get(i));
    if (index == -1) {
      throw new MathIllegalArgumentException(LocalizedFormats.DIFFERENT_ORIG_AND_PERMUTED_DATA);
    }
    res[index]=(double)i / l;
    origDataCopy.set(index,null);
  }
  return Arrays.asList(res);
}
Program: 57090
Project: 57090
Buggy source:
@Test public void testBinomialTestPValues(){
  Assert.assertEquals(0.04375,testStatistic.binomialTest(trials,successes,probability,AlternativeHypothesis.TWO_SIDED),1E-4);
  Assert.assertEquals(0.02654,testStatistic.binomialTest(trials,successes,probability,AlternativeHypothesis.GREATER_THAN),1E-4);
  Assert.assertEquals(0.982,testStatistic.binomialTest(trials,successes,probability,AlternativeHypothesis.LESS_THAN),1E-4);
}

Fixed version (ground truth):
@Test public void testBinomialTestPValues(){
  Assert.assertEquals(0.04375,testStatistic.binomialTest(trials,successes,probability,AlternativeHypothesis.TWO_SIDED),1E-4);
  Assert.assertEquals(0.02654,testStatistic.binomialTest(trials,successes,probability,AlternativeHypothesis.GREATER_THAN),1E-4);
  Assert.assertEquals(0.982,testStatistic.binomialTest(trials,successes,probability,AlternativeHypothesis.LESS_THAN),1E-4);
  Assert.assertEquals(1,testStatistic.binomialTest(3,3,1,AlternativeHypothesis.TWO_SIDED),1E-4);
  Assert.assertEquals(1,testStatistic.binomialTest(3,3,0.9,AlternativeHypothesis.TWO_SIDED),1E-4);
  Assert.assertEquals(1,testStatistic.binomialTest(3,3,0.8,AlternativeHypothesis.TWO_SIDED),1E-4);
  Assert.assertEquals(0.559,testStatistic.binomialTest(3,3,0.7,AlternativeHypothesis.TWO_SIDED),1E-4);
  Assert.assertEquals(0.28,testStatistic.binomialTest(3,3,0.6,AlternativeHypothesis.TWO_SIDED),1E-4);
  Assert.assertEquals(0.25,testStatistic.binomialTest(3,3,0.5,AlternativeHypothesis.TWO_SIDED),1E-4);
  Assert.assertEquals(0.064,testStatistic.binomialTest(3,3,0.4,AlternativeHypothesis.TWO_SIDED),1E-4);
  Assert.assertEquals(0.027,testStatistic.binomialTest(3,3,0.3,AlternativeHypothesis.TWO_SIDED),1E-4);
  Assert.assertEquals(0.008,testStatistic.binomialTest(3,3,0.2,AlternativeHypothesis.TWO_SIDED),1E-4);
  Assert.assertEquals(0.001,testStatistic.binomialTest(3,3,0.1,AlternativeHypothesis.TWO_SIDED),1E-4);
  Assert.assertEquals(0,testStatistic.binomialTest(3,3,0.0,AlternativeHypothesis.TWO_SIDED),1E-4);
  Assert.assertEquals(0,testStatistic.binomialTest(3,0,1,AlternativeHypothesis.TWO_SIDED),1E-4);
  Assert.assertEquals(0.001,testStatistic.binomialTest(3,0,0.9,AlternativeHypothesis.TWO_SIDED),1E-4);
  Assert.assertEquals(0.008,testStatistic.binomialTest(3,0,0.8,AlternativeHypothesis.TWO_SIDED),1E-4);
  Assert.assertEquals(0.027,testStatistic.binomialTest(3,0,0.7,AlternativeHypothesis.TWO_SIDED),1E-4);
  Assert.assertEquals(0.064,testStatistic.binomialTest(3,0,0.6,AlternativeHypothesis.TWO_SIDED),1E-4);
  Assert.assertEquals(0.25,testStatistic.binomialTest(3,0,0.5,AlternativeHypothesis.TWO_SIDED),1E-4);
  Assert.assertEquals(0.28,testStatistic.binomialTest(3,0,0.4,AlternativeHypothesis.TWO_SIDED),1E-4);
  Assert.assertEquals(0.559,testStatistic.binomialTest(3,0,0.3,AlternativeHypothesis.TWO_SIDED),1E-4);
  Assert.assertEquals(1,testStatistic.binomialTest(3,0,0.2,AlternativeHypothesis.TWO_SIDED),1E-4);
  Assert.assertEquals(1,testStatistic.binomialTest(3,0,0.1,AlternativeHypothesis.TWO_SIDED),1E-4);
  Assert.assertEquals(1,testStatistic.binomialTest(3,0,0.0,AlternativeHypothesis.TWO_SIDED),1E-4);
}
Program: 57091
Project: 57091
Buggy source:
/** 
 * {@inheritDoc} 
 */
@Override public IntegerDistribution.Sampler createSampler(final UniformRandomProvider rng){
  return new IntegerDistribution.Sampler(){
    private final DiscreteSampler sampler=new InverseTransformDiscreteSampler(rng,createICPF());
    /** 
 * {@inheritDoc} 
 */
    @Override public int sample(){
      return sampler.sample();
    }
  }
;
}

Fixed version (ground truth):
/** 
 * {@inheritDoc} 
 */
@Override public IntegerDistribution.Sampler createSampler(final UniformRandomProvider rng){
  return new IntegerDistribution.Sampler(){
    /** 
 * Inversion method distribution sampler.
 */
    private final DiscreteSampler sampler=new InverseTransformDiscreteSampler(rng,createICPF());
    /** 
 * {@inheritDoc} 
 */
    @Override public int sample(){
      return sampler.sample();
    }
  }
;
}
Program: 57092
Project: 57092
Buggy source:
/** 
 * {@inheritDoc} 
 */
@Override public RealDistribution.Sampler createSampler(final UniformRandomProvider rng){
  return new RealDistribution.Sampler(){
    private final ContinuousSampler sampler=new InverseTransformContinuousSampler(rng,createICPF());
    /** 
 * {@inheritDoc} 
 */
    @Override public double sample(){
      return sampler.sample();
    }
  }
;
}

Fixed version (ground truth):
/** 
 * {@inheritDoc} 
 */
@Override public RealDistribution.Sampler createSampler(final UniformRandomProvider rng){
  return new RealDistribution.Sampler(){
    /** 
 * Inversion method distribution sampler.
 */
    private final ContinuousSampler sampler=new InverseTransformContinuousSampler(rng,createICPF());
    /** 
 * {@inheritDoc} 
 */
    @Override public double sample(){
      return sampler.sample();
    }
  }
;
}
Program: 57093
Project: 57093
Buggy source:
/** 
 * {@inheritDoc}Sampling is performed using Cheng's algorithm: <blockquote> <pre> R. C. H. Cheng, "Generating beta variates with nonintegral shape parameters", Communications of the ACM, 21, 317-322, 1978. </pre> </blockquote>
 */
@Override public RealDistribution.Sampler createSampler(final UniformRandomProvider rng){
  return new RealDistribution.Sampler(){
    private final ContinuousSampler sampler=new ChengBetaSampler(rng,alpha,beta);
    /** 
 * {@inheritDoc} 
 */
    @Override public double sample(){
      return sampler.sample();
    }
  }
;
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}Sampling is performed using Cheng's algorithm: <blockquote> <pre> R. C. H. Cheng, "Generating beta variates with nonintegral shape parameters", Communications of the ACM, 21, 317-322, 1978. </pre> </blockquote>
 */
@Override public RealDistribution.Sampler createSampler(final UniformRandomProvider rng){
  return new RealDistribution.Sampler(){
    /** 
 * Beta distribution sampler.
 */
    private final ContinuousSampler sampler=new ChengBetaSampler(rng,alpha,beta);
    /** 
 * {@inheritDoc} 
 */
    @Override public double sample(){
      return sampler.sample();
    }
  }
;
}
Program: 57094
Project: 57094
Buggy source:
/** 
 * {@inheritDoc}<p>Sampling algorithm uses the <a href="http://www.jesus.ox.ac.uk/~clifford/a5/chap1/node5.html"> inversion method</a> to generate exponentially distributed random values from uniform deviates. </p>
 */
@Override public RealDistribution.Sampler createSampler(final UniformRandomProvider rng){
  return new RealDistribution.Sampler(){
    private final ContinuousSampler sampler=new AhrensDieterExponentialSampler(rng,mean);
    /** 
 * {@inheritDoc} 
 */
    @Override public double sample(){
      return sampler.sample();
    }
  }
;
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}<p>Sampling algorithm uses the <a href="http://www.jesus.ox.ac.uk/~clifford/a5/chap1/node5.html"> inversion method</a> to generate exponentially distributed random values from uniform deviates. </p>
 */
@Override public RealDistribution.Sampler createSampler(final UniformRandomProvider rng){
  return new RealDistribution.Sampler(){
    /** 
 * Exponential distribution sampler.
 */
    private final ContinuousSampler sampler=new AhrensDieterExponentialSampler(rng,mean);
    /** 
 * {@inheritDoc} 
 */
    @Override public double sample(){
      return sampler.sample();
    }
  }
;
}
Program: 57095
Project: 57095
Buggy source:
/** 
 * {@inheritDoc}<p> Sampling algorithms: <ul> <li> For   {@code 0 < shape < 1}: <blockquote> Ahrens, J. H. and Dieter, U., <i>Computer methods for sampling from gamma, beta, Poisson and binomial distributions,</i> Computing, 12, 223-246, 1974. </blockquote> </li> <li> For   {@code shape >= 1}: <blockquote> Marsaglia and Tsang, <i>A Simple Method for Generating Gamma Variables.</i> ACM Transactions on Mathematical Software, Volume 26 Issue 3, September, 2000. </blockquote> </li> </ul>
 */
@Override public RealDistribution.Sampler createSampler(final UniformRandomProvider rng){
  return new RealDistribution.Sampler(){
    private final ContinuousSampler sampler=new AhrensDieterMarsagliaTsangGammaSampler(rng,scale,shape);
    /** 
 * {@inheritDoc} 
 */
    @Override public double sample(){
      return sampler.sample();
    }
  }
;
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}<p> Sampling algorithms: <ul> <li> For   {@code 0 < shape < 1}: <blockquote> Ahrens, J. H. and Dieter, U., <i>Computer methods for sampling from gamma, beta, Poisson and binomial distributions,</i> Computing, 12, 223-246, 1974. </blockquote> </li> <li> For   {@code shape >= 1}: <blockquote> Marsaglia and Tsang, <i>A Simple Method for Generating Gamma Variables.</i> ACM Transactions on Mathematical Software, Volume 26 Issue 3, September, 2000. </blockquote> </li> </ul>
 */
@Override public RealDistribution.Sampler createSampler(final UniformRandomProvider rng){
  return new RealDistribution.Sampler(){
    /** 
 * Gamma distribution sampler.
 */
    private final ContinuousSampler sampler=new AhrensDieterMarsagliaTsangGammaSampler(rng,scale,shape);
    /** 
 * {@inheritDoc} 
 */
    @Override public double sample(){
      return sampler.sample();
    }
  }
;
}
Program: 57096
Project: 57096
Buggy source:
/** 
 * {@inheritDoc} 
 */
@Override public RealDistribution.Sampler createSampler(final UniformRandomProvider rng){
  return new RealDistribution.Sampler(){
    private final ContinuousSampler sampler=new MarsagliaLogNormalSampler(rng,scale,shape);
    /** 
 * {@inheritDoc} 
 */
    @Override public double sample(){
      return sampler.sample();
    }
  }
;
}

Fixed version (ground truth):
/** 
 * {@inheritDoc} 
 */
@Override public RealDistribution.Sampler createSampler(final UniformRandomProvider rng){
  return new RealDistribution.Sampler(){
    /** 
 * Log normal distribution sampler.
 */
    private final ContinuousSampler sampler=new MarsagliaLogNormalSampler(rng,scale,shape);
    /** 
 * {@inheritDoc} 
 */
    @Override public double sample(){
      return sampler.sample();
    }
  }
;
}
Program: 57097
Project: 57097
Buggy source:
/** 
 * {@inheritDoc} 
 */
@Override public RealDistribution.Sampler createSampler(final UniformRandomProvider rng){
  return new RealDistribution.Sampler(){
    private final ContinuousSampler sampler=new GaussianSampler(new MarsagliaNormalizedGaussianSampler(rng),mean,standardDeviation);
    /** 
 * {@inheritDoc} 
 */
    @Override public double sample(){
      return sampler.sample();
    }
  }
;
}

Fixed version (ground truth):
/** 
 * {@inheritDoc} 
 */
@Override public RealDistribution.Sampler createSampler(final UniformRandomProvider rng){
  return new RealDistribution.Sampler(){
    /** 
 * Gaussian distribution sampler.
 */
    private final ContinuousSampler sampler=new GaussianSampler(new MarsagliaNormalizedGaussianSampler(rng),mean,standardDeviation);
    /** 
 * {@inheritDoc} 
 */
    @Override public double sample(){
      return sampler.sample();
    }
  }
;
}
Program: 57098
Project: 57098
Buggy source:
/** 
 * {@inheritDoc} 
 */
@Override public RealDistribution.Sampler createSampler(final UniformRandomProvider rng){
  return new RealDistribution.Sampler(){
    private final ContinuousSampler sampler=new InverseTransformParetoSampler(rng,scale,shape);
    /** 
 * {@inheritDoc} 
 */
    @Override public double sample(){
      return sampler.sample();
    }
  }
;
}

Fixed version (ground truth):
/** 
 * {@inheritDoc} 
 */
@Override public RealDistribution.Sampler createSampler(final UniformRandomProvider rng){
  return new RealDistribution.Sampler(){
    /** 
 * Pareto distribution sampler.
 */
    private final ContinuousSampler sampler=new InverseTransformParetoSampler(rng,scale,shape);
    /** 
 * {@inheritDoc} 
 */
    @Override public double sample(){
      return sampler.sample();
    }
  }
;
}
Program: 57099
Project: 57099
Buggy source:
/** 
 * {@inheritDoc} 
 */
@Override public IntegerDistribution.Sampler createSampler(final UniformRandomProvider rng){
  return new IntegerDistribution.Sampler(){
    private final DiscreteSampler sampler=new PoissonSampler(rng,mean);
    /** 
 * {@inheritDoc} 
 */
    @Override public int sample(){
      return sampler.sample();
    }
  }
;
}

Fixed version (ground truth):
/** 
 * {@inheritDoc} 
 */
@Override public IntegerDistribution.Sampler createSampler(final UniformRandomProvider rng){
  return new IntegerDistribution.Sampler(){
    /** 
 * Poisson distribution sampler.
 */
    private final DiscreteSampler sampler=new PoissonSampler(rng,mean);
    /** 
 * {@inheritDoc} 
 */
    @Override public int sample(){
      return sampler.sample();
    }
  }
;
}
Program: 57100
Project: 57100
Buggy source:
/** 
 * {@inheritDoc} 
 */
@Override public IntegerDistribution.Sampler createSampler(final UniformRandomProvider rng){
  return new IntegerDistribution.Sampler(){
    private final DiscreteSampler sampler=new DiscreteUniformSampler(rng,lower,upper);
    /** 
 * {@inheritDoc} 
 */
    @Override public int sample(){
      return sampler.sample();
    }
  }
;
}

Fixed version (ground truth):
/** 
 * {@inheritDoc} 
 */
@Override public IntegerDistribution.Sampler createSampler(final UniformRandomProvider rng){
  return new IntegerDistribution.Sampler(){
    /** 
 * Discrete uniform distribution sampler.
 */
    private final DiscreteSampler sampler=new DiscreteUniformSampler(rng,lower,upper);
    /** 
 * {@inheritDoc} 
 */
    @Override public int sample(){
      return sampler.sample();
    }
  }
;
}
Program: 57101
Project: 57101
Buggy source:
/** 
 * {@inheritDoc} 
 */
@Override public RealDistribution.Sampler createSampler(final UniformRandomProvider rng){
  return new RealDistribution.Sampler(){
    private final ContinuousSampler sampler=new ContinuousUniformSampler(rng,lower,upper);
    /** 
 * {@inheritDoc} 
 */
    @Override public double sample(){
      return sampler.sample();
    }
  }
;
}

Fixed version (ground truth):
/** 
 * {@inheritDoc} 
 */
@Override public RealDistribution.Sampler createSampler(final UniformRandomProvider rng){
  return new RealDistribution.Sampler(){
    /** 
 * Uniform distribution sampler.
 */
    private final ContinuousSampler sampler=new ContinuousUniformSampler(rng,lower,upper);
    /** 
 * {@inheritDoc} 
 */
    @Override public double sample(){
      return sampler.sample();
    }
  }
;
}
Program: 57102
Project: 57102
Buggy source:
/** 
 * {@inheritDoc} 
 */
@Override public IntegerDistribution.Sampler createSampler(final UniformRandomProvider rng){
  return new IntegerDistribution.Sampler(){
    private final DiscreteSampler sampler=new RejectionInversionZipfSampler(rng,numberOfElements,exponent);
    /** 
 * {@inheritDoc} 
 */
    @Override public int sample(){
      return sampler.sample();
    }
  }
;
}

Fixed version (ground truth):
/** 
 * {@inheritDoc} 
 */
@Override public IntegerDistribution.Sampler createSampler(final UniformRandomProvider rng){
  return new IntegerDistribution.Sampler(){
    /** 
 * Zipf distribution sampler.
 */
    private final DiscreteSampler sampler=new RejectionInversionZipfSampler(rng,numberOfElements,exponent);
    /** 
 * {@inheritDoc} 
 */
    @Override public int sample(){
      return sampler.sample();
    }
  }
;
}
Program: 57104
Project: 57104
Buggy source:
/** 
 * {@inheritDoc}<p>Returns the kernel density normalized so that its integral over each bin equals the bin mass.</p> <p>Algorithm description: <ol> <li>Find the bin B that x belongs to.</li> <li>Compute K(B) = the mass of B with respect to the within-bin kernel (i.e., the integral of the kernel density over B).</li> <li>Return k(x) * P(B) / K(B), where k is the within-bin kernel density and P(B) is the mass of B.</li></ol></p>
 * @since 3.1
 */
@Override public double density(double x){
  if (x < min || x > max) {
    return 0d;
  }
  final int binIndex=findBin(x);
  final RealDistribution kernel=getKernel(binStats.get(binIndex));
  return kernel.density(x) * pB(binIndex) / kB(binIndex);
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}<p>Returns the kernel density normalized so that its integral over each bin equals the bin mass.</p> <p>Algorithm description: <ol> <li>Find the bin B that x belongs to.</li> <li>Compute K(B) = the mass of B with respect to the within-bin kernel (i.e., the integral of the kernel density over B).</li> <li>Return k(x) * P(B) / K(B), where k is the within-bin kernel density and P(B) is the mass of B.</li></ol>
 * @since 3.1
 */
@Override public double density(double x){
  if (x < min || x > max) {
    return 0d;
  }
  final int binIndex=findBin(x);
  final RealDistribution kernel=getKernel(binStats.get(binIndex));
  return kernel.density(x) * pB(binIndex) / kB(binIndex);
}
Program: 57105
Project: 57105
Buggy source:
/** 
 * {@inheritDoc}<p>Algorithm description:<ol> <li>Find the smallest i such that the sum of the masses of the bins through i is at least p.</li> <li> Let K be the within-bin kernel distribution for bin i.</br> Let K(B) be the mass of B under K. <br/> Let K(B-) be K evaluated at the lower endpoint of B (the combined mass of the bins below B under K).<br/> Let P(B) be the probability of bin i.<br/> Let P(B-) be the sum of the bin masses below bin i. <br/> Let pCrit = p - P(B-)<br/> <li>Return the inverse of K evaluated at <br/> K(B-) + pCrit * K(B) / P(B) </li> </ol></p>
 * @since 3.1
 */
@Override public double inverseCumulativeProbability(final double p) throws OutOfRangeException {
  if (p < 0.0 || p > 1.0) {
    throw new OutOfRangeException(p,0,1);
  }
  if (p == 0.0) {
    return getSupportLowerBound();
  }
  if (p == 1.0) {
    return getSupportUpperBound();
  }
  int i=0;
  while (cumBinP(i) < p) {
    i++;
  }
  final RealDistribution kernel=getKernel(binStats.get(i));
  final double kB=kB(i);
  final double[] binBounds=getUpperBounds();
  final double lower=i == 0 ? min : binBounds[i - 1];
  final double kBminus=kernel.cumulativeProbability(lower);
  final double pB=pB(i);
  final double pBminus=pBminus(i);
  final double pCrit=p - pBminus;
  if (pCrit <= 0) {
    return lower;
  }
  return kernel.inverseCumulativeProbability(kBminus + pCrit * kB / pB);
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}<p>Algorithm description:<ol> <li>Find the smallest i such that the sum of the masses of the bins through i is at least p.</li> <li> Let K be the within-bin kernel distribution for bin i.<br> Let K(B) be the mass of B under K. <br> Let K(B-) be K evaluated at the lower endpoint of B (the combined mass of the bins below B under K).<br> Let P(B) be the probability of bin i.<br> Let P(B-) be the sum of the bin masses below bin i. <br> Let pCrit = p - P(B-)<br> <li>Return the inverse of K evaluated at <br> K(B-) + pCrit * K(B) / P(B) </li> </ol>
 * @since 3.1
 */
@Override public double inverseCumulativeProbability(final double p) throws OutOfRangeException {
  if (p < 0.0 || p > 1.0) {
    throw new OutOfRangeException(p,0,1);
  }
  if (p == 0.0) {
    return getSupportLowerBound();
  }
  if (p == 1.0) {
    return getSupportUpperBound();
  }
  int i=0;
  while (cumBinP(i) < p) {
    i++;
  }
  final RealDistribution kernel=getKernel(binStats.get(i));
  final double kB=kB(i);
  final double[] binBounds=getUpperBounds();
  final double lower=i == 0 ? min : binBounds[i - 1];
  final double kBminus=kernel.cumulativeProbability(lower);
  final double pB=pB(i);
  final double pBminus=pBminus(i);
  final double pCrit=p - pBminus;
  if (pCrit <= 0) {
    return lower;
  }
  return kernel.inverseCumulativeProbability(kBminus + pCrit * kB / pB);
}
Program: 57106
Project: 57106
Buggy source:
/** 
 * <p>Returns a fresh copy of the array of upper bounds for the bins. Bins are: <br/> [min,upperBounds[0]],(upperBounds[0],upperBounds[1]],..., (upperBounds[binCount-2], upperBounds[binCount-1] = max].</p> <p>Note: In versions 1.0-2.0 of commons-math, this method incorrectly returned the array of probability generator upper bounds now returned by   {@link #getGeneratorUpperBounds()}.</p>
 * @return array of bin upper bounds
 * @since 2.1
 */
public double[] getUpperBounds(){
  double[] binUpperBounds=new double[binCount];
  for (int i=0; i < binCount - 1; i++) {
    binUpperBounds[i]=min + delta * (i + 1);
  }
  binUpperBounds[binCount - 1]=max;
  return binUpperBounds;
}

Fixed version (ground truth):
/** 
 * <p>Returns a fresh copy of the array of upper bounds for the bins. Bins are: <br> [min,upperBounds[0]],(upperBounds[0],upperBounds[1]],..., (upperBounds[binCount-2], upperBounds[binCount-1] = max].</p> <p>Note: In versions 1.0-2.0 of commons-math, this method incorrectly returned the array of probability generator upper bounds now returned by   {@link #getGeneratorUpperBounds()}.</p>
 * @return array of bin upper bounds
 * @since 2.1
 */
public double[] getUpperBounds(){
  double[] binUpperBounds=new double[binCount];
  for (int i=0; i < binCount - 1; i++) {
    binUpperBounds[i]=min + delta * (i + 1);
  }
  binUpperBounds[binCount - 1]=max;
  return binUpperBounds;
}
Program: 57107
Project: 57107
Buggy source:
/** 
 * {@inheritDoc}<p> Sampling algorithms: <ul> <li> For   {@code 0 < shape < 1}: <blockquote> Ahrens, J. H. and Dieter, U., <i>Computer methods for sampling from gamma, beta, Poisson and binomial distributions,</i> Computing, 12, 223-246, 1974. </blockquote> </li> <li> For   {@code shape >= 1}: <blockquote> Marsaglia and Tsang, <i>A Simple Method for Generating Gamma Variables.</i> ACM Transactions on Mathematical Software, Volume 26 Issue 3, September, 2000. </blockquote> </li> </ul> </p>
 */
@Override public RealDistribution.Sampler createSampler(final UniformRandomProvider rng){
  return new RealDistribution.Sampler(){
    private final ContinuousSampler sampler=new AhrensDieterMarsagliaTsangGammaSampler(rng,scale,shape);
    /** 
 * {@inheritDoc} 
 */
    @Override public double sample(){
      return sampler.sample();
    }
  }
;
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}<p> Sampling algorithms: <ul> <li> For   {@code 0 < shape < 1}: <blockquote> Ahrens, J. H. and Dieter, U., <i>Computer methods for sampling from gamma, beta, Poisson and binomial distributions,</i> Computing, 12, 223-246, 1974. </blockquote> </li> <li> For   {@code shape >= 1}: <blockquote> Marsaglia and Tsang, <i>A Simple Method for Generating Gamma Variables.</i> ACM Transactions on Mathematical Software, Volume 26 Issue 3, September, 2000. </blockquote> </li> </ul>
 */
@Override public RealDistribution.Sampler createSampler(final UniformRandomProvider rng){
  return new RealDistribution.Sampler(){
    private final ContinuousSampler sampler=new AhrensDieterMarsagliaTsangGammaSampler(rng,scale,shape);
    /** 
 * {@inheritDoc} 
 */
    @Override public double sample(){
      return sampler.sample();
    }
  }
;
}
Program: 57108
Project: 57108
Buggy source:
/** 
 * Solve the linear least squares problem Jx=r.
 * @param jacobian  the Jacobian matrix, J. the number of rows >= the number orcolumns.
 * @param residuals the computed residuals, r.
 * @return the solution x, to the linear least squares problem Jx=r.
 * @throws ConvergenceException if the matrix properties (e.g. singular) do notpermit a solution.
 */
protected abstract RealVector solve(RealMatrix jacobian,RealVector residuals);

Fixed version (ground truth):
/** 
 * Solve the linear least squares problem Jx=r.
 * @param jacobian  the Jacobian matrix, J. the number of rows &gt;= the number orcolumns.
 * @param residuals the computed residuals, r.
 * @return the solution x, to the linear least squares problem Jx=r.
 * @throws ConvergenceException if the matrix properties (e.g. singular) do notpermit a solution.
 */
protected abstract RealVector solve(RealMatrix jacobian,RealVector residuals);
Program: 57109
Project: 57109
Buggy source:
/** 
 * {@inheritDoc}
 * @param point
 */
@Override public Evaluation evaluate(final RealVector point){
  return problem.evaluate(point);
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}
 */
@Override public Evaluation evaluate(final RealVector point){
  return problem.evaluate(point);
}
Program: 57110
Project: 57110
Buggy source:
/** 
 * Configure the convergence checker. <p/> This function is an overloaded version of   {@link #checker(ConvergenceChecker)}.
 * @param newChecker the convergence checker.
 * @return this
 */
public LeastSquaresBuilder checkerPair(final ConvergenceChecker<PointVectorValuePair> newChecker){
  return this.checker(LeastSquaresFactory.evaluationChecker(newChecker));
}

Fixed version (ground truth):
/** 
 * Configure the convergence checker. <p> This function is an overloaded version of   {@link #checker(ConvergenceChecker)}.
 * @param newChecker the convergence checker.
 * @return this
 */
public LeastSquaresBuilder checkerPair(final ConvergenceChecker<PointVectorValuePair> newChecker){
  return this.checker(LeastSquaresFactory.evaluationChecker(newChecker));
}
Program: 57111
Project: 57111
Buggy source:
/** 
 * Get the covariance matrix of the optimized parameters. <br/> Note that this operation involves the inversion of the <code>J<sup>T</sup>J</code> matrix, where   {@code J} is the Jacobian matrix. The {@code threshold} parameter is away for the caller to specify that the result of this computation should be considered meaningless, and thus trigger an exception.
 * @param threshold Singularity threshold.
 * @return the covariance matrix.
 * @throws org.apache.commons.math4.linear.SingularMatrixException if the covariance matrix cannot be computed (singular problem).
 */
RealMatrix getCovariances(double threshold);

Fixed version (ground truth):
/** 
 * Get the covariance matrix of the optimized parameters. <br> Note that this operation involves the inversion of the <code>J<sup>T</sup>J</code> matrix, where   {@code J} is the Jacobian matrix. The {@code threshold} parameter is away for the caller to specify that the result of this computation should be considered meaningless, and thus trigger an exception.
 * @param threshold Singularity threshold.
 * @return the covariance matrix.
 * @throws org.apache.commons.math4.linear.SingularMatrixException if the covariance matrix cannot be computed (singular problem).
 */
RealMatrix getCovariances(double threshold);
Program: 57115
Project: 57115
Buggy source:
/** 
 * Returns the R-Squared statistic, defined by the formula <pre> R<sup>2</sup> = 1 - SSR / SSTO </pre> where SSR is the   {@link #calculateResidualSumOfSquares() sum of squared residuals}and SSTO is the   {@link #calculateTotalSumOfSquares() total sum of squares}<p>If there is no variance in y, i.e., SSTO = 0, NaN is returned.</p>
 * @return R-square statistic
 * @throws NullPointerException if the sample has not been set
 * @throws org.apache.commons.math4.linear.SingularMatrixException if the design matrix is singular
 * @since 2.2
 */
public double calculateRSquared(){
  return 1 - calculateResidualSumOfSquares() / calculateTotalSumOfSquares();
}

Fixed version (ground truth):
/** 
 * Returns the R-Squared statistic, defined by the formula <div style="white-space: pre"><code> R<sup>2</sup> = 1 - SSR / SSTO </code></div> where SSR is the   {@link #calculateResidualSumOfSquares() sum of squared residuals}and SSTO is the   {@link #calculateTotalSumOfSquares() total sum of squares}<p>If there is no variance in y, i.e., SSTO = 0, NaN is returned.</p>
 * @return R-square statistic
 * @throws NullPointerException if the sample has not been set
 * @throws org.apache.commons.math4.linear.SingularMatrixException if the design matrix is singular
 * @since 2.2
 */
public double calculateRSquared(){
  return 1 - calculateResidualSumOfSquares() / calculateTotalSumOfSquares();
}
Program: 57116
Project: 57116
Buggy source:
/** 
 * <p>Returns the adjusted R-squared statistic, defined by the formula <pre> R<sup>2</sup><sub>adj</sub> = 1 - [SSR (n - 1)] / [SSTO (n - p)] </pre> where SSR is the   {@link #calculateResidualSumOfSquares() sum of squared residuals}, SSTO is the   {@link #calculateTotalSumOfSquares() total sum of squares}, n is the number of observations and p is the number of parameters estimated (including the intercept).</p> <p>If the regression is estimated without an intercept term, what is returned is <pre> <code> 1 - (1 -   {@link #calculateRSquared()}) * (n / (n - p)) </code> </pre> <p>If there is no variance in y, i.e., SSTO = 0, NaN is returned.</p>
 * @return adjusted R-Squared statistic
 * @throws NullPointerException if the sample has not been set
 * @throws org.apache.commons.math4.linear.SingularMatrixException if the design matrix is singular
 * @see #isNoIntercept()
 * @since 2.2
 */
public double calculateAdjustedRSquared(){
  final double n=getX().getRowDimension();
  if (isNoIntercept()) {
    return 1 - (1 - calculateRSquared()) * (n / (n - getX().getColumnDimension()));
  }
 else {
    return 1 - (calculateResidualSumOfSquares() * (n - 1)) / (calculateTotalSumOfSquares() * (n - getX().getColumnDimension()));
  }
}

Fixed version (ground truth):
/** 
 * <p>Returns the adjusted R-squared statistic, defined by the formula <div style="white-space: pre"><code> R<sup>2</sup><sub>adj</sub> = 1 - [SSR (n - 1)] / [SSTO (n - p)] </code></div> where SSR is the   {@link #calculateResidualSumOfSquares() sum of squared residuals}, SSTO is the   {@link #calculateTotalSumOfSquares() total sum of squares}, n is the number of observations and p is the number of parameters estimated (including the intercept). <p>If the regression is estimated without an intercept term, what is returned is <pre> <code> 1 - (1 -   {@link #calculateRSquared()}) * (n / (n - p)) </code> </pre> <p>If there is no variance in y, i.e., SSTO = 0, NaN is returned.</p>
 * @return adjusted R-Squared statistic
 * @throws NullPointerException if the sample has not been set
 * @throws org.apache.commons.math4.linear.SingularMatrixException if the design matrix is singular
 * @see #isNoIntercept()
 * @since 2.2
 */
public double calculateAdjustedRSquared(){
  final double n=getX().getRowDimension();
  if (isNoIntercept()) {
    return 1 - (1 - calculateRSquared()) * (n / (n - getX().getColumnDimension()));
  }
 else {
    return 1 - (calculateResidualSumOfSquares() * (n - 1)) / (calculateTotalSumOfSquares() * (n - getX().getColumnDimension()));
  }
}
Program: 57117
Project: 57117
Buggy source:
/** 
 * <p>Returns the adjusted R-squared statistic, defined by the formula <pre> R<sup>2</sup><sub>adj</sub> = 1 - [SSR (n - 1)] / [SSTO (n - p)] </pre> where SSR is the sum of squared residuals}, SSTO is the total sum of squares}, n is the number of observations and p is the number of parameters estimated (including the intercept).</p> <p>If the regression is estimated without an intercept term, what is returned is <pre> <code> 1 - (1 -   {@link #getRSquared()} ) * (n / (n - p)) </code></pre>
 * @return adjusted R-Squared statistic
 */
public double getAdjustedRSquared(){
  return this.globalFitInfo[ADJRSQ_IDX];
}

Fixed version (ground truth):
/** 
 * <p>Returns the adjusted R-squared statistic, defined by the formula <div style="white-space: pre"><code> R<sup>2</sup><sub>adj</sub> = 1 - [SSR (n - 1)] / [SSTO (n - p)] </code></div> where SSR is the sum of squared residuals}, SSTO is the total sum of squares}, n is the number of observations and p is the number of parameters estimated (including the intercept). <p>If the regression is estimated without an intercept term, what is returned is <pre> <code> 1 - (1 -   {@link #getRSquared()} ) * (n / (n - p)) </code></pre>
 * @return adjusted R-Squared statistic
 */
public double getAdjustedRSquared(){
  return this.globalFitInfo[ADJRSQ_IDX];
}
Program: 57118
Project: 57118
Buggy source:
/** 
 * Returns the significance level of the slope (equiv) correlation. <p> Specifically, the returned value is the smallest <code>alpha</code> such that the slope confidence interval with significance level equal to <code>alpha</code> does not include <code>0</code>. On regression output, this is often denoted <code>Prob(|t| > 0)</code> </p><p> <strong>Usage Note</strong>:<br> The validity of this statistic depends on the assumption that the observations included in the model are drawn from a <a href="http://mathworld.wolfram.com/BivariateNormalDistribution.html"> Bivariate Normal Distribution</a>.</p> <p> If there are fewer that <strong>three</strong> observations in the model, or if there is no variation in x, this returns <code>Double.NaN</code>.</p>
 * @return significance level for slope/correlation
 * @throws org.apache.commons.math4.exception.MaxCountExceededException if the significance level can not be computed.
 */
public double getSignificance(){
  if (n < 3) {
    return Double.NaN;
  }
  TDistribution distribution=new TDistribution(n - 2);
  return 2d * (1.0 - distribution.cumulativeProbability(FastMath.abs(getSlope()) / getSlopeStdErr()));
}

Fixed version (ground truth):
/** 
 * Returns the significance level of the slope (equiv) correlation. <p> Specifically, the returned value is the smallest <code>alpha</code> such that the slope confidence interval with significance level equal to <code>alpha</code> does not include <code>0</code>. On regression output, this is often denoted   {@code Prob(|t| > 0)}</p><p> <strong>Usage Note</strong>:<br> The validity of this statistic depends on the assumption that the observations included in the model are drawn from a <a href="http://mathworld.wolfram.com/BivariateNormalDistribution.html"> Bivariate Normal Distribution</a>.</p> <p> If there are fewer that <strong>three</strong> observations in the model, or if there is no variation in x, this returns <code>Double.NaN</code>.</p>
 * @return significance level for slope/correlation
 * @throws org.apache.commons.math4.exception.MaxCountExceededException if the significance level can not be computed.
 */
public double getSignificance(){
  if (n < 3) {
    return Double.NaN;
  }
  TDistribution distribution=new TDistribution(n - 2);
  return 2d * (1.0 - distribution.cumulativeProbability(FastMath.abs(getSlope()) / getSlopeStdErr()));
}
Program: 57119
Project: 57119
Buggy source:
/** 
 * Returns the sum of squared deviations of the y values about their mean. <p> This is defined as SSTO <a href="http://www.xycoon.com/SumOfSquares.htm">here</a>.</p> <p> If <code>n < 2</code>, this returns <code>Double.NaN</code>.</p>
 * @return sum of squared deviations of y values
 */
public double getTotalSumSquares(){
  if (n < 2) {
    return Double.NaN;
  }
  return sumYY;
}

Fixed version (ground truth):
/** 
 * Returns the sum of squared deviations of the y values about their mean. <p> This is defined as SSTO <a href="http://www.xycoon.com/SumOfSquares.htm">here</a>.</p> <p> If   {@code n < 2}, this returns <code>Double.NaN</code>.</p>
 * @return sum of squared deviations of y values
 */
public double getTotalSumSquares(){
  if (n < 2) {
    return Double.NaN;
  }
  return sumYY;
}
Program: 57120
Project: 57120
Buggy source:
/** 
 * Returns the half-width of a (100-100*alpha)% confidence interval for the slope estimate. <p> The (100-100*alpha)% confidence interval is </p> <p> <code>(getSlope() - getSlopeConfidenceInterval(), getSlope() + getSlopeConfidenceInterval())</code></p> <p> To request, for example, a 99% confidence interval, use <code>alpha = .01</code></p> <p> <strong>Usage Note</strong>:<br> The validity of this statistic depends on the assumption that the observations included in the model are drawn from a <a href="http://mathworld.wolfram.com/BivariateNormalDistribution.html"> Bivariate Normal Distribution</a>.</p> <p> <strong> Preconditions:</strong><ul> <li>If there are fewer that <strong>three</strong> observations in the model, or if there is no variation in x, this returns <code>Double.NaN</code>. </li> <li><code>(0 < alpha < 1)</code>; otherwise an <code>OutOfRangeException</code> is thrown. </li></ul>
 * @param alpha the desired significance level
 * @return half-width of 95% confidence interval for the slope estimate
 * @throws OutOfRangeException if the confidence interval can not be computed.
 */
public double getSlopeConfidenceInterval(final double alpha) throws OutOfRangeException {
  if (n < 3) {
    return Double.NaN;
  }
  if (alpha >= 1 || alpha <= 0) {
    throw new OutOfRangeException(LocalizedFormats.SIGNIFICANCE_LEVEL,alpha,0,1);
  }
  TDistribution distribution=new TDistribution(n - 2);
  return getSlopeStdErr() * distribution.inverseCumulativeProbability(1d - alpha / 2d);
}

Fixed version (ground truth):
/** 
 * Returns the half-width of a (100-100*alpha)% confidence interval for the slope estimate. <p> The (100-100*alpha)% confidence interval is </p> <p> <code>(getSlope() - getSlopeConfidenceInterval(), getSlope() + getSlopeConfidenceInterval())</code></p> <p> To request, for example, a 99% confidence interval, use <code>alpha = .01</code></p> <p> <strong>Usage Note</strong>:<br> The validity of this statistic depends on the assumption that the observations included in the model are drawn from a <a href="http://mathworld.wolfram.com/BivariateNormalDistribution.html"> Bivariate Normal Distribution</a>.</p> <p> <strong> Preconditions:</strong><ul> <li>If there are fewer that <strong>three</strong> observations in the model, or if there is no variation in x, this returns <code>Double.NaN</code>. </li> <li>  {@code (0 < alpha < 1)}; otherwise an <code>OutOfRangeException</code> is thrown. </li></ul>
 * @param alpha the desired significance level
 * @return half-width of 95% confidence interval for the slope estimate
 * @throws OutOfRangeException if the confidence interval can not be computed.
 */
public double getSlopeConfidenceInterval(final double alpha) throws OutOfRangeException {
  if (n < 3) {
    return Double.NaN;
  }
  if (alpha >= 1 || alpha <= 0) {
    throw new OutOfRangeException(LocalizedFormats.SIGNIFICANCE_LEVEL,alpha,0,1);
  }
  TDistribution distribution=new TDistribution(n - 2);
  return getSlopeStdErr() * distribution.inverseCumulativeProbability(1d - alpha / 2d);
}