Program: 21234
Project: 21234
Buggy source:
/** 
 * {@inheritDoc}
 */
@Override public <E extends UnivariateDistribution>E getPosterior(Variable var){
  Variable samplingVar=this.samplingModel.getVariables().getVariableByName(var.getName());
  EF_UnivariateDistribution ef_univariateDistribution=samplingVar.newUnivariateDistribution().toEFUnivariateDistribution();
  AtomicInteger dataInstanceCount=new AtomicInteger(0);
  if (keepDataOnMemory) {
    weightedSampleStream=weightedSampleList.stream().sequential();
  }
 else {
    computeWeightedSampleStream(false);
  }
  if (parallelMode) {
    weightedSampleStream.parallel();
  }
  if (!keepDataOnMemory) {
    weightedSampleList=weightedSampleStream.collect(Collectors.toList());
  }
  double maxLogWeight=weightedSampleList.stream().mapToDouble(weightetAssignment -> weightetAssignment.weight).filter(Double::isFinite).max().getAsDouble();
  SufficientStatistics sumSS=weightedSampleStream.peek(w -> {
    dataInstanceCount.getAndIncrement();
  }
).map(e -> {
    SufficientStatistics SS=ef_univariateDistribution.getSufficientStatistics(e.assignment);
    SS.multiplyBy(Math.exp(e.weight - maxLogWeight));
    return SS;
  }
).filter(ss -> Double.isFinite(ss.sum())).reduce(SufficientStatistics::sumVectorNonStateless).get();
  sumSS.multiplyBy(Math.exp(maxLogWeight));
  sumSS.divideBy(dataInstanceCount.get());
  ef_univariateDistribution.setMomentParameters(sumSS);
  Distribution posteriorDistribution=ef_univariateDistribution.toUnivariateDistribution();
  if (var.isMultinomial()) {
    double[] probabilities=((Multinomial)posteriorDistribution).getProbabilities();
    double probMax=Arrays.stream(probabilities).max().getAsDouble();
    Arrays.stream(probabilities).map(prob -> prob / probMax);
    ((Multinomial)posteriorDistribution).setProbabilities(Utils.normalize(probabilities));
  }
  return (E)posteriorDistribution;
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}
 */
@Override public <E extends UnivariateDistribution>E getPosterior(Variable var){
  Variable samplingVar=this.samplingModel.getVariables().getVariableByName(var.getName());
  EF_UnivariateDistribution ef_univariateDistribution=samplingVar.newUnivariateDistribution().toEFUnivariateDistribution();
  AtomicInteger dataInstanceCount=new AtomicInteger(0);
  if (keepDataOnMemory) {
    weightedSampleStream=weightedSampleList.stream().sequential();
  }
 else {
    computeWeightedSampleStream(false);
  }
  if (parallelMode) {
    weightedSampleStream.parallel();
  }
  if (!keepDataOnMemory) {
    weightedSampleList=weightedSampleStream.collect(Collectors.toList());
  }
  double maxLogWeight=weightedSampleList.stream().mapToDouble(weightetAssignment -> weightetAssignment.weight).filter(Double::isFinite).max().getAsDouble();
  SufficientStatistics sumSS=weightedSampleStream.peek(w -> {
    dataInstanceCount.getAndIncrement();
  }
).map(e -> {
    SufficientStatistics SS=ef_univariateDistribution.getSufficientStatistics(e.assignment);
    SS.multiplyBy(Math.exp(e.weight - maxLogWeight));
    return SS;
  }
).filter(ss -> Double.isFinite(ss.sum())).reduce(SufficientStatistics::sumVectorNonStateless).get();
  sumSS.multiplyBy(Math.exp(maxLogWeight));
  sumSS.divideBy(dataInstanceCount.get());
  sumSS.divideBy(Math.exp(this.getLogProbabilityOfEvidence()));
  ef_univariateDistribution.setMomentParameters(sumSS);
  Distribution posteriorDistribution=ef_univariateDistribution.toUnivariateDistribution();
  if (var.isMultinomial()) {
    double[] probabilities=((Multinomial)posteriorDistribution).getProbabilities();
    double probMax=Arrays.stream(probabilities).max().getAsDouble();
    Arrays.stream(probabilities).map(prob -> prob / probMax);
    ((Multinomial)posteriorDistribution).setProbabilities(Utils.normalize(probabilities));
  }
  return (E)posteriorDistribution;
}