nus-yam/ex-repair huggingface dataset:
Program: 21183
Project: 21183
Buggy source:
/** 
 * Fills for every user a map which contains weights (based on tag, time and tag-time score) for his resources
 */
private void fillChengWeights(){
  for (  Bookmark data : trainList) {
    int user=data.getUserID();
    int resource=data.getWikiID();
    List<Integer> tags=data.getTags();
    Map<Integer,Double> tagUserWeights=null;
    if (user >= userTagWeights.size()) {
      tagUserWeights=new LinkedHashMap<Integer,Double>();
      userTagWeights.add(tagUserWeights);
    }
 else {
      tagUserWeights=userTagWeights.get(user);
    }
    Map<Integer,Double> tagResourceWeights=resourceTagWeights.get(resource);
    if (tagResourceWeights == null) {
      tagResourceWeights=new HashMap<Integer,Double>();
    }
    for (    Integer tag : tags) {
      if (!tagUserWeights.containsKey(tag)) {
        tagUserWeights.put(tag,huangApproach.getUserTagWeight(user,tag));
      }
      if (!tagResourceWeights.containsKey(tag)) {
        tagResourceWeights.put(tag,huangApproach.getItemTagWeight(resource,tag));
      }
    }
    resourceTagWeights.put(resource,tagResourceWeights);
  }
}

Fixed version (ground truth):
/** 
 * Fills for every user a map which contains weights (based on tag, time and tag-time score) for his resources
 */
private void fillChengWeights(){
  for (  Bookmark data : trainList) {
    int user=data.getUserID();
    int resource=data.getResourceID();
    List<Integer> tags=data.getTags();
    Map<Integer,Double> tagUserWeights=null;
    if (user >= userTagWeights.size()) {
      tagUserWeights=new LinkedHashMap<Integer,Double>();
      userTagWeights.add(tagUserWeights);
    }
 else {
      tagUserWeights=userTagWeights.get(user);
    }
    Map<Integer,Double> tagResourceWeights=resourceTagWeights.get(resource);
    if (tagResourceWeights == null) {
      tagResourceWeights=new HashMap<Integer,Double>();
    }
    for (    Integer tag : tags) {
      if (!tagUserWeights.containsKey(tag)) {
        tagUserWeights.put(tag,huangApproach.getUserTagWeight(user,tag));
      }
      if (!tagResourceWeights.containsKey(tag)) {
        tagResourceWeights.put(tag,huangApproach.getItemTagWeight(resource,tag));
      }
    }
    resourceTagWeights.put(resource,tagResourceWeights);
  }
}
Program: 21184
Project: 21184
Buggy source:
public ZhengApproach(List<Bookmark> trainList){
  userResourceTagMaping=new HashMap<Integer,Map<Integer,List<Integer>>>();
  userResourceTimeMaping=new HashMap<Integer,Map<Integer,Long>>();
  userMaxTimeMaping=new HashMap<Integer,Long>();
  userMinTimeMaping=new HashMap<Integer,Long>();
  for (  Bookmark trainData : trainList) {
    Integer userID=trainData.getUserID();
    Integer resID=trainData.getWikiID();
    List<Integer> tags=trainData.getTags();
    Long day=TimeUnit.SECONDS.toDays(Long.parseLong(trainData.getTimestamp()));
    Map<Integer,List<Integer>> resourceTagMaping=userResourceTagMaping.get(userID);
    Map<Integer,Long> resourceTimeMaping=userResourceTimeMaping.get(userID);
    if (resourceTagMaping == null) {
      resourceTagMaping=new HashMap<Integer,List<Integer>>();
    }
    if (resourceTimeMaping == null) {
      resourceTimeMaping=new HashMap<Integer,Long>();
    }
    resourceTagMaping.put(resID,tags);
    resourceTimeMaping.put(resID,day);
    Long maxUserTime=userMaxTimeMaping.get(userID);
    Long minUserTime=userMinTimeMaping.get(userID);
    if (maxUserTime == null) {
      maxUserTime=day;
      minUserTime=day;
    }
 else {
      if (maxUserTime < day) {
        maxUserTime=day;
      }
      if (minUserTime > day) {
        minUserTime=day;
      }
    }
    userMaxTimeMaping.put(userID,maxUserTime);
    userMinTimeMaping.put(userID,minUserTime);
    userResourceTagMaping.put(userID,resourceTagMaping);
    userResourceTimeMaping.put(userID,resourceTimeMaping);
  }
}

Fixed version (ground truth):
public ZhengApproach(List<Bookmark> trainList){
  userResourceTagMaping=new HashMap<Integer,Map<Integer,List<Integer>>>();
  userResourceTimeMaping=new HashMap<Integer,Map<Integer,Long>>();
  userMaxTimeMaping=new HashMap<Integer,Long>();
  userMinTimeMaping=new HashMap<Integer,Long>();
  for (  Bookmark trainData : trainList) {
    Integer userID=trainData.getUserID();
    Integer resID=trainData.getResourceID();
    List<Integer> tags=trainData.getTags();
    Long day=TimeUnit.SECONDS.toDays(Long.parseLong(trainData.getTimestamp()));
    Map<Integer,List<Integer>> resourceTagMaping=userResourceTagMaping.get(userID);
    Map<Integer,Long> resourceTimeMaping=userResourceTimeMaping.get(userID);
    if (resourceTagMaping == null) {
      resourceTagMaping=new HashMap<Integer,List<Integer>>();
    }
    if (resourceTimeMaping == null) {
      resourceTimeMaping=new HashMap<Integer,Long>();
    }
    resourceTagMaping.put(resID,tags);
    resourceTimeMaping.put(resID,day);
    Long maxUserTime=userMaxTimeMaping.get(userID);
    Long minUserTime=userMinTimeMaping.get(userID);
    if (maxUserTime == null) {
      maxUserTime=day;
      minUserTime=day;
    }
 else {
      if (maxUserTime < day) {
        maxUserTime=day;
      }
      if (minUserTime > day) {
        minUserTime=day;
      }
    }
    userMaxTimeMaping.put(userID,maxUserTime);
    userMinTimeMaping.put(userID,minUserTime);
    userResourceTagMaping.put(userID,resourceTagMaping);
    userResourceTimeMaping.put(userID,resourceTimeMaping);
  }
}
Program: 21186
Project: 21186
Buggy source:
private static List<Map<Integer,Double>> startActCreation(BookmarkReader reader,int sampleSize,boolean sorting,boolean userBased,boolean resBased,int dVal,int beta,CalculationType cType){
  int size=reader.getBookmarks().size();
  int trainSize=size - sampleSize;
  Stopwatch timer=new Stopwatch();
  timer.start();
  BLLCalculator calculator=new BLLCalculator(reader,trainSize,dVal,beta,userBased,resBased,cType);
  timer.stop();
  long trainingTime=timer.elapsed(TimeUnit.MILLISECONDS);
  List<Map<Integer,Double>> results=new ArrayList<Map<Integer,Double>>();
  if (trainSize == size) {
    trainSize=0;
  }
  timer.reset();
  timer.start();
  for (int i=trainSize; i < size; i++) {
    Bookmark data=reader.getBookmarks().get(i);
    Map<Integer,Double> map=calculator.getRankedTagList(data.getUserID(),data.getWikiID(),sorting,cType);
    results.add(map);
  }
  timer.stop();
  long testTime=timer.elapsed(TimeUnit.MILLISECONDS);
  timeString=PerformanceMeasurement.addTimeMeasurement(timeString,true,trainingTime,testTime,sampleSize);
  return results;
}

Fixed version (ground truth):
private static List<Map<Integer,Double>> startActCreation(BookmarkReader reader,int sampleSize,boolean sorting,boolean userBased,boolean resBased,int dVal,int beta,CalculationType cType){
  int size=reader.getBookmarks().size();
  int trainSize=size - sampleSize;
  Stopwatch timer=new Stopwatch();
  timer.start();
  BLLCalculator calculator=new BLLCalculator(reader,trainSize,dVal,beta,userBased,resBased,cType);
  timer.stop();
  long trainingTime=timer.elapsed(TimeUnit.MILLISECONDS);
  List<Map<Integer,Double>> results=new ArrayList<Map<Integer,Double>>();
  if (trainSize == size) {
    trainSize=0;
  }
  timer.reset();
  timer.start();
  for (int i=trainSize; i < size; i++) {
    Bookmark data=reader.getBookmarks().get(i);
    Map<Integer,Double> map=calculator.getRankedTagList(data.getUserID(),data.getResourceID(),sorting,cType);
    results.add(map);
  }
  timer.stop();
  long testTime=timer.elapsed(TimeUnit.MILLISECONDS);
  timeString=PerformanceMeasurement.addTimeMeasurement(timeString,true,trainingTime,testTime,sampleSize);
  return results;
}
Program: 21187
Project: 21187
Buggy source:
public static List<Integer> getResourcesFromUser(List<Bookmark> lines,int userID){
  Set<Integer> resourceList=new HashSet<Integer>();
  for (  Bookmark data : lines) {
    if (data.userID == userID) {
      resourceList.add(data.resID);
    }
  }
  return new ArrayList<Integer>(resourceList);
}

Fixed version (ground truth):
public static List<Integer> getResourcesFromUser(List<Bookmark> lines,int userID){
  if (userID == -1) {
    return null;
  }
  Set<Integer> resourceList=new HashSet<Integer>();
  for (  Bookmark data : lines) {
    if (data.userID == userID) {
      resourceList.add(data.resID);
    }
  }
  return new ArrayList<Integer>(resourceList);
}
Program: 21188
Project: 21188
Buggy source:
public synchronized Map<String,Double> getEntitiesWithLikelihood(String user,String resource,List<String> topics,Integer count,Boolean filterOwnEntities){
  if (count == null || count.doubleValue() < 1) {
    count=10;
  }
  if (filterOwnEntities == null) {
    filterOwnEntities=true;
  }
  Map<String,Double> resourceMap=new LinkedHashMap<>();
  if (this.reader == null || this.calculator == null) {
    System.out.println("String_Node_Str");
    return resourceMap;
  }
  int userID=-1;
  if (user != null) {
    userID=this.reader.getUsers().indexOf(user);
  }
  Map<Integer,Double> resourceIDs=this.calculator.getRankedResourcesList(userID,true,false,false,filterOwnEntities.booleanValue());
  for (  Map.Entry<Integer,Double> tEntry : resourceIDs.entrySet()) {
    if (resourceMap.size() < count) {
      resourceMap.put(this.reader.getResources().get(tEntry.getKey()),tEntry.getValue());
    }
  }
  if (resourceMap.size() < count) {
    for (    Map.Entry<String,Double> t : this.topResources.entrySet()) {
      if (resourceMap.size() < count) {
        if (!resourceMap.containsKey(t.getKey())) {
          resourceMap.put(t.getKey(),t.getValue());
        }
      }
 else {
        break;
      }
    }
  }
  return resourceMap;
}

Fixed version (ground truth):
public synchronized Map<String,Double> getEntitiesWithLikelihood(String user,String resource,List<String> topics,Integer count,Boolean filterOwnEntities){
  if (count == null || count.doubleValue() < 1) {
    count=10;
  }
  if (filterOwnEntities == null) {
    filterOwnEntities=true;
  }
  Map<String,Double> resourceMap=new LinkedHashMap<>();
  if (this.reader == null || this.calculator == null) {
    System.out.println("String_Node_Str");
    return resourceMap;
  }
  int userID=-1;
  if (user != null) {
    userID=this.reader.getUsers().indexOf(user);
  }
  List<Integer> userResources=null;
  if (filterOwnEntities.booleanValue()) {
    userResources=Bookmark.getResourcesFromUser(this.reader.getBookmarks(),userID);
  }
  Map<Integer,Double> resourceIDs=this.calculator.getRankedResourcesList(userID,true,false,false,filterOwnEntities.booleanValue());
  for (  Map.Entry<Integer,Double> tEntry : resourceIDs.entrySet()) {
    if (resourceMap.size() < count) {
      resourceMap.put(this.reader.getResources().get(tEntry.getKey()),tEntry.getValue());
    }
  }
  if (resourceMap.size() < count) {
    for (    Map.Entry<String,Double> t : this.topResources.entrySet()) {
      if (resourceMap.size() < count) {
        if (!resourceMap.containsKey(t.getKey()) && (userResources == null || userResources.contains(t.getKey()))) {
          resourceMap.put(t.getKey(),t.getValue());
        }
      }
 else {
        break;
      }
    }
  }
  return resourceMap;
}
Program: 21190
Project: 21190
Buggy source:
@Override public void updateMomentFromNaturalParameters(){
  double delta=this.getNaturalParameters().get(0);
  if (Math.exp(delta) > Double.MAX_VALUE) {
    this.momentParameters.set(0,1.0 - 1 / delta);
  }
 else {
    double width=(this.upperInterval - this.lowerInterval);
    double val=this.upperInterval - width / (1 - Math.exp(delta * width)) - 1 / delta;
    this.momentParameters.set(0,val);
  }
}

Fixed version (ground truth):
@Override public void updateMomentFromNaturalParameters(){
  double delta=this.getNaturalParameters().get(0);
  double width=(this.upperInterval - this.lowerInterval);
  if (Math.exp(width * delta) > Double.MAX_VALUE) {
    this.momentParameters.set(0,this.upperInterval - 1 / delta);
  }
 else {
    double val=this.upperInterval - width / (1 - Math.exp(delta * width)) - 1 / delta;
    this.momentParameters.set(0,val);
  }
}
Program: 21191
Project: 21191
Buggy source:
@Override public EF_LearningBayesianNetwork transitionModel(EF_LearningBayesianNetwork ef_extendedBN,PlateuStructure plateuStructure){
  ef_extendedBN.getParametersVariables().getListOfParamaterVariables().stream().forEach(var -> {
    EF_UnivariateDistribution prior=ef_extendedBN.getDistribution(var);
    NaturalParameters naturalParameters=prior.getNaturalParameters();
    naturalParameters.multiplyBy(fadingFactor);
    prior.setNaturalParameters(naturalParameters);
    ef_extendedBN.setDistribution(var,prior);
    plateuStructure.getNodeOfVar(var,0).setPDist(prior);
  }
);
  return ef_extendedBN;
}

Fixed version (ground truth):
@Override public EF_LearningBayesianNetwork transitionModel(EF_LearningBayesianNetwork ef_extendedBN,PlateuStructure plateuStructure){
  plateuStructure.getNonReplicatedVariables().forEach(var -> {
    EF_UnivariateDistribution prior=ef_extendedBN.getDistribution(var);
    NaturalParameters naturalParameters=prior.getNaturalParameters();
    naturalParameters.multiplyBy(fadingFactor);
    prior.setNaturalParameters(naturalParameters);
    ef_extendedBN.setDistribution(var,prior);
    plateuStructure.getNodeOfVar(var,0).setPDist(prior);
  }
);
  return ef_extendedBN;
}
Program: 21192
Project: 21192
Buggy source:
/** 
 * Creates a new exponential family univariate distribution.
 * @return an exponential family Gamma distribution.
 */
@Override public EF_TruncatedExponential newEFUnivariateDistribution(){
  EF_TruncatedExponential ef_TruncatedExponential=new EF_TruncatedExponential(this.variable);
  ef_TruncatedExponential.getNaturalParameters().set(0,0.1);
  ef_TruncatedExponential.fixNumericalInstability();
  ef_TruncatedExponential.updateMomentFromNaturalParameters();
  return ef_TruncatedExponential;
}

Fixed version (ground truth):
/** 
 * Creates a new exponential family univariate distribution.
 * @param args, a sequence with the initial natural parameters.
 * @return an exponential family Gamma distribution.
 */
@Override public EF_TruncatedExponential newEFUnivariateDistribution(double... args){
  EF_TruncatedExponential ef_TruncatedExponential=new EF_TruncatedExponential(this.variable);
  for (  double a : args) {
    ef_TruncatedExponential.getNaturalParameters().set(0,-a);
  }
  ef_TruncatedExponential.fixNumericalInstability();
  ef_TruncatedExponential.updateMomentFromNaturalParameters();
  return ef_TruncatedExponential;
}
Program: 21193
Project: 21193
Buggy source:
/** 
 * Creates a new exponential family univariate distribution.
 * @return an exponential family Gamma distribution.
 */
@Override public EF_TruncatedNormal newEFUnivariateDistribution(){
  EF_TruncatedNormal ef_TruncatedNormal=new EF_TruncatedNormal(this.variable);
  ef_TruncatedNormal.getNaturalParameters().set(0,1);
  ef_TruncatedNormal.fixNumericalInstability();
  ef_TruncatedNormal.updateMomentFromNaturalParameters();
  return ef_TruncatedNormal;
}

Fixed version (ground truth):
/** 
 * Creates a new exponential family univariate distribution.
 * @param args, a sequence with the initial natural parameters.
 * @return an exponential family Truncated Normal distribution.
 */
@Override public EF_TruncatedNormal newEFUnivariateDistribution(double... args){
  EF_TruncatedNormal ef_TruncatedNormal=new EF_TruncatedNormal(this.variable);
  for (  double a : args) {
    ef_TruncatedNormal.getNaturalParameters().set(0,-a);
  }
  ef_TruncatedNormal.fixNumericalInstability();
  ef_TruncatedNormal.updateMomentFromNaturalParameters();
  return ef_TruncatedNormal;
}
Program: 21194
Project: 21194
Buggy source:
@Override public Attributes getAttributes(){
  return this.getAttributes();
}

Fixed version (ground truth):
@Override public Attributes getAttributes(){
  return initialStream.getAttributes();
}
Program: 21195
Project: 21195
Buggy source:
@Override public void restart(){
  this.restart();
}

Fixed version (ground truth):
@Override public void restart(){
  initialStream.restart();
}
Program: 21196
Project: 21196
Buggy source:
/** 
 * Returns a data stream consisting of the elements of this stream that match the given predicate. <p>This is an <a href="package-summary.html#StreamOps">intermediate operation</a>.
 * @param predicate a <a href="package-summary.html#NonInterference">non-interfering</a>,<a href="package-summary.html#Statelessness">stateless</a> predicate to apply to each element to determine if it should be included
 * @return the new stream
 */
default DataStream<E> filter(Predicate<? super E> predicate){
  return new DataStream<E>(){
    @Override public Attributes getAttributes(){
      return this.getAttributes();
    }
    @Override public void close(){
      this.close();
    }
    @Override public boolean isRestartable(){
      return this.isRestartable();
    }
    @Override public void restart(){
      this.restart();
    }
    @Override public Stream<E> stream(){
      return this.stream().filter(predicate);
    }
  }
;
}

Fixed version (ground truth):
/** 
 * Returns a data stream consisting of the elements of this stream that match the given predicate. <p>This is an <a href="package-summary.html#StreamOps">intermediate operation</a>.
 * @param predicate a <a href="package-summary.html#NonInterference">non-interfering</a>,<a href="package-summary.html#Statelessness">stateless</a> predicate to apply to each element to determine if it should be included
 * @return the new stream
 */
default DataStream<E> filter(Predicate<? super E> predicate){
  DataStream<E> initialStream=this;
  return new DataStream<E>(){
    @Override public Attributes getAttributes(){
      return initialStream.getAttributes();
    }
    @Override public void close(){
      initialStream.close();
    }
    @Override public boolean isRestartable(){
      return initialStream.isRestartable();
    }
    @Override public void restart(){
      initialStream.restart();
    }
    @Override public Stream<E> stream(){
      return initialStream.stream().filter(predicate);
    }
  }
;
}
Program: 21197
Project: 21197
Buggy source:
@Override public Stream<R> stream(){
  return ((Stream<E>)this.stream()).map(mapper);
}

Fixed version (ground truth):
@Override public Stream<R> stream(){
  return ((Stream<E>)initialStream.stream()).map(mapper);
}
Program: 21198
Project: 21198
Buggy source:
@Override public void close(){
  this.close();
}

Fixed version (ground truth):
@Override public void close(){
  initialStream.close();
}
Program: 21199
Project: 21199
Buggy source:
/** 
 * Returns a data stream consisting of the results of applying the given function to the elements of this stream. <p>This is an <a href="package-summary.html#StreamOps">intermediate operation</a>.
 * @param mapper a <a href="package-summary.html#NonInterference">non-interfering</a>,<a href="package-summary.html#Statelessness">stateless</a> function to apply to each element
 * @return the new data stream
 */
default <R extends DataInstance>DataStream<R> map(Function<? super E,? extends R> mapper){
  return new DataStream<R>(){
    @Override public Attributes getAttributes(){
      return this.getAttributes();
    }
    @Override public void close(){
      this.close();
    }
    @Override public boolean isRestartable(){
      return this.isRestartable();
    }
    @Override public void restart(){
      this.restart();
    }
    @Override public Stream<R> stream(){
      return ((Stream<E>)this.stream()).map(mapper);
    }
  }
;
}

Fixed version (ground truth):
/** 
 * Returns a data stream consisting of the results of applying the given function to the elements of this stream. <p>This is an <a href="package-summary.html#StreamOps">intermediate operation</a>.
 * @param mapper a <a href="package-summary.html#NonInterference">non-interfering</a>,<a href="package-summary.html#Statelessness">stateless</a> function to apply to each element
 * @return the new data stream
 */
default <R extends DataInstance>DataStream<R> map(Function<? super E,? extends R> mapper){
  DataStream<E> initialStream=this;
  return new DataStream<R>(){
    @Override public Attributes getAttributes(){
      return initialStream.getAttributes();
    }
    @Override public void close(){
      initialStream.close();
    }
    @Override public boolean isRestartable(){
      return initialStream.isRestartable();
    }
    @Override public void restart(){
      initialStream.restart();
    }
    @Override public Stream<R> stream(){
      return ((Stream<E>)initialStream.stream()).map(mapper);
    }
  }
;
}
Program: 21200
Project: 21200
Buggy source:
@Override public boolean isRestartable(){
  return this.isRestartable();
}

Fixed version (ground truth):
@Override public boolean isRestartable(){
  return initialStream.isRestartable();
}
Program: 21201
Project: 21201
Buggy source:
private void updateFirstBatch(DataOnMemory<DataInstance> firstBatch){
  this.svb.getPlateuStructure().setVmp(new VMP());
  this.svb.getPlateuStructure().getVMP().setMaxIter(this.maximumLocalIterations);
  this.svb.getPlateuStructure().getVMP().setThreshold(this.localThreshold);
  this.svb.setDAG(this.dag);
  this.svb.setWindowsSize(batchSize);
  this.svb.initLearning();
  initialPosterior=Serialization.deepCopy(this.svb.getPlateuStructure().getPlateauNaturalParameterPosterior());
  initialPosterior.sum(prior);
  this.svb.updateNaturalParameterPosteriors(initialPosterior);
  this.svb.updateModel(firstBatch);
  currentParam=Serialization.deepCopy(svb.getPlateuStructure().getPlateauNaturalParameterPosterior());
  VMPLocalUpdates vmpLocalUpdates=new VMPLocalUpdates(this.svb.getPlateuStructure());
  this.svb.getPlateuStructure().setVmp(vmpLocalUpdates);
  this.svb.getPlateuStructure().getVMP().setMaxIter(this.maximumLocalIterations);
  this.svb.getPlateuStructure().getVMP().setThreshold(this.localThreshold);
  this.svb.setDAG(this.dag);
  this.svb.setWindowsSize(batchSize);
  this.svb.initLearning();
  prior=svb.getNaturalParameterPrior();
  this.svb.updateNaturalParameterPosteriors(currentParam);
  iteration=0;
}

Fixed version (ground truth):
private double updateFirstBatch(DataOnMemory<DataInstance> firstBatch){
  this.svb.getPlateuStructure().setVmp(new VMP());
  this.svb.getPlateuStructure().getVMP().setMaxIter(this.maximumLocalIterations);
  this.svb.getPlateuStructure().getVMP().setThreshold(this.localThreshold);
  this.svb.setDAG(this.dag);
  this.svb.setWindowsSize(batchSize);
  this.svb.initLearning();
  initialPosterior=Serialization.deepCopy(this.svb.getPlateuStructure().getPlateauNaturalParameterPosterior());
  initialPosterior.sum(prior);
  this.svb.updateNaturalParameterPosteriors(initialPosterior);
  double out=this.svb.updateModel(firstBatch);
  currentParam=Serialization.deepCopy(svb.getPlateuStructure().getPlateauNaturalParameterPosterior());
  VMPLocalUpdates vmpLocalUpdates=new VMPLocalUpdates(this.svb.getPlateuStructure());
  this.svb.getPlateuStructure().setVmp(vmpLocalUpdates);
  this.svb.getPlateuStructure().getVMP().setMaxIter(this.maximumLocalIterations);
  this.svb.getPlateuStructure().getVMP().setThreshold(this.localThreshold);
  this.svb.setDAG(this.dag);
  this.svb.setWindowsSize(batchSize);
  this.svb.initLearning();
  prior=svb.getNaturalParameterPrior();
  this.svb.updateNaturalParameterPosteriors(currentParam);
  iteration=0;
  return out;
}
Program: 21202
Project: 21202
Buggy source:
@Override public double updateModel(DataOnMemory<DataInstance> batch){
  if (firstBatch) {
    this.updateFirstBatch(batch);
    firstBatch=false;
  }
  NaturalParameters newParam=svb.updateModelOnBatchParallel(batch).getVector();
  newParam.multiplyBy(this.dataSetSize / (double)this.batchSize);
  newParam.sum(prior);
  double stepSize=Math.pow(1 + iteration,-learningFactor);
  newParam.multiplyBy(stepSize);
  currentParam.multiplyBy((1 - stepSize));
  currentParam.sum(newParam);
  this.svb.updateNaturalParameterPosteriors(currentParam);
  iteration++;
  return Double.NaN;
}

Fixed version (ground truth):
@Override public double updateModel(DataOnMemory<DataInstance> batch){
  if (firstBatch) {
    firstBatch=false;
    return this.updateFirstBatch(batch);
  }
  NaturalParameters newParam=svb.updateModelOnBatchParallel(batch).getVector();
  newParam.multiplyBy(this.dataSetSize / (double)this.batchSize);
  newParam.sum(prior);
  double stepSize=Math.pow(1 + iteration,-learningFactor);
  newParam.multiplyBy(stepSize);
  currentParam.multiplyBy((1 - stepSize));
  currentParam.sum(newParam);
  this.svb.updateNaturalParameterPosteriors(currentParam);
  iteration++;
  return Double.NaN;
}
Program: 21203
Project: 21203
Buggy source:
public static void main(String[] args) throws Exception {
  int nContinuousAttributes=4;
  int nDiscreteAttributes=0;
  String names[]={"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"};
  String path="String_Node_Str";
  int nSamples=1000;
  DataStream<DynamicDataInstance> data=DataSetGenerator.generate(1,1000,nDiscreteAttributes,nContinuousAttributes);
  List<Attribute> list=new ArrayList<Attribute>();
  IntStream.range(0,data.getAttributes().getNumberOfAttributes()).forEach(i -> {
    Attribute a=data.getAttributes().getFullListOfAttributes().get(i);
    StateSpaceType s=a.getStateSpaceType();
    Attribute a2=new Attribute(a.getIndex(),names[i],s);
    list.add(a2);
  }
);
  Attributes att2=new Attributes(list);
  List<DynamicDataInstance> listData=data.stream().collect(Collectors.toList());
  DataStream<DynamicDataInstance> data2=new DataOnMemoryListContainer<DynamicDataInstance>(att2,listData);
  DataStreamWriter.writeDataToFile(data2,path + "String_Node_Str");
  final ExecutionEnvironment env=ExecutionEnvironment.getExecutionEnvironment();
  DataFlink<DataInstance> data2Flink=DataFlinkLoader.loadDataFromFile(env,path + "String_Node_Str",false);
  DataFlinkWriter.writeDataToARFFFolder(data2Flink,path + "String_Node_Str");
}

Fixed version (ground truth):
public static void main(String[] args) throws Exception {
  int nContinuousAttributes=4;
  int nDiscreteAttributes=0;
  String names[]={"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"};
  String path="String_Node_Str";
  int nSamples=1000;
  DataStream<DynamicDataInstance> data=DataSetGenerator.generate(1,1000,nDiscreteAttributes,nContinuousAttributes);
  List<Attribute> list=new ArrayList<Attribute>();
  IntStream.range(0,data.getAttributes().getNumberOfAttributes()).forEach(i -> {
    Attribute a=data.getAttributes().getFullListOfAttributes().get(i);
    StateSpaceType s=a.getStateSpaceType();
    Attribute a2=new Attribute(a.getIndex(),names[i],s);
    list.add(a2);
  }
);
  Attributes att2=new Attributes(list);
  List<DynamicDataInstance> listData=data.stream().collect(Collectors.toList());
  DataStream<DynamicDataInstance> data2=new DataOnMemoryListContainer<DynamicDataInstance>(att2,listData);
  DataStreamWriter.writeDataToFile(data2,path + "String_Node_Str");
  Configuration conf=new Configuration();
  conf.setInteger("String_Node_Str",12000);
  final ExecutionEnvironment env=ExecutionEnvironment.createLocalEnvironment(conf);
  env.getConfig().disableSysoutLogging();
  env.setParallelism(Main.PARALLELISM);
  DataFlink<DataInstance> data2Flink=DataFlinkLoader.loadDataFromFile(env,path + "String_Node_Str",false);
  DataFlinkWriter.writeDataToARFFFolder(data2Flink,path + "String_Node_Str");
}
Program: 21204
Project: 21204
Buggy source:
public static void main(String[] args) throws IOException {
  String filename="String_Node_Str";
  DataStream<DataInstance> data=DataStreamLoader.open(filename);
  Model model=new LDA(data.getAttributes());
  model.updateModel(data);
  BayesianNetwork bn=model.getModel();
  System.out.println(bn);
  BayesianNetworkWriter.save(bn,"String_Node_Str");
}

Fixed version (ground truth):
public static void main(String[] args) throws IOException {
  String filename="String_Node_Str";
  DataStream<DataInstance> data=DataStreamLoader.open(filename);
  Model model=new LDA(data.getAttributes());
  model.updateModel(data);
  BayesianNetwork bn=model.getModel();
  BayesianNetworkWriter.save(bn,"String_Node_Str");
}
Program: 21205
Project: 21205
Buggy source:
public static void main(String[] args) throws IOException {
  Configuration conf=new Configuration();
  conf.setInteger("String_Node_Str",12000);
  final ExecutionEnvironment env=ExecutionEnvironment.createLocalEnvironment(conf);
  env.getConfig().disableSysoutLogging();
  env.setParallelism(Main.PARALLELISM);
  String filename="String_Node_Str";
  DataFlink<DataInstance> data=DataFlinkLoader.loadDataFromFolder(env,filename,false);
  Model model=new LDA(data.getAttributes());
  model.updateModel(data);
  BayesianNetwork bn=model.getModel();
  System.out.println(bn);
  BayesianNetworkWriter.save(bn,"String_Node_Str");
}

Fixed version (ground truth):
public static void main(String[] args) throws IOException {
  Configuration conf=new Configuration();
  conf.setInteger("String_Node_Str",12000);
  final ExecutionEnvironment env=ExecutionEnvironment.createLocalEnvironment(conf);
  env.getConfig().disableSysoutLogging();
  env.setParallelism(Main.PARALLELISM);
  String filename="String_Node_Str";
  DataFlink<DataInstance> data=DataFlinkLoader.loadDataFromFolder(env,filename,false);
  Model model=new LDA(data.getAttributes());
  model.updateModel(data);
  BayesianNetwork bn=model.getModel();
  BayesianNetworkWriter.save(bn,"String_Node_Str");
}
Program: 21206
Project: 21206
Buggy source:
@Test public void test() throws Exception {
  try {
    ParallelTANExample.main(null);
  }
 catch (  UnsatisfiedLinkError error) {
    error.printStackTrace();
  }
}

Fixed version (ground truth):
@Test public void test() throws Exception {
  try {
    ParallelTANExample.main(null);
  }
 catch (  UnsatisfiedLinkError error) {
  }
}
Program: 21207
Project: 21207
Buggy source:
/** 
 * {@inheritDoc}
 */
@Override public void copy(Vector vector){
  if (this.size() != vector.size())   throw new IllegalArgumentException("String_Node_Str");
  this.copy((ArrayVectorParameter)vector);
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}
 */
@Override public void copy(Vector vector){
  if (this.size() != vector.size())   throw new IllegalArgumentException("String_Node_Str");
  if (!vector.getClass().isAssignableFrom(ArrayVectorParameter.class))   throw new IllegalArgumentException("String_Node_Str");
  this.copy((ArrayVectorParameter)vector);
}
Program: 21208
Project: 21208
Buggy source:
/** 
 * {@inheritDoc}
 */
@Override public void updateMomentFromNaturalParameters(){
  double sumOfU_i=this.naturalParameters.sum();
  this.momentParameters=this.createZeroMomentParameters();
  this.getSparseMomentParameters().apply(new Function<Double,Double>(){
    @Override public Double apply(    Double aDouble){
      return Gamma.digamma(aDouble) - Gamma.digamma(sumOfU_i);
    }
  }
);
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}
 */
@Override public void updateMomentFromNaturalParameters(){
  double sumOfU_i=this.naturalParameters.sum();
  this.momentParameters=this.createZeroMomentParameters();
  this.momentParameters.copy(this.naturalParameters);
  this.getSparseMomentParameters().apply(new Function<Double,Double>(){
    @Override public Double apply(    Double aDouble){
      return Gamma.digamma(aDouble) - Gamma.digamma(sumOfU_i);
    }
  }
);
}
Program: 21210
Project: 21210
Buggy source:
public static void test(){
  Variables variables=new Variables();
  ParameterVariables parameterVariables=new ParameterVariables(1);
  Variable multiA=variables.newMultinomialVariable("String_Node_Str",10);
  Variable dirichlet=parameterVariables.newDirichletParameter("String_Node_Str",10);
  EF_SparseMultinomial_SparseDirichlet dist=new EF_SparseMultinomial_SparseDirichlet(multiA,dirichlet);
  EF_SparseDirichlet distDirichlet=new EF_SparseDirichlet(dirichlet);
  EF_LearningBayesianNetwork ef_learningBayesianNetwork=new EF_LearningBayesianNetwork(Arrays.asList(dist,distDirichlet));
}

Fixed version (ground truth):
public static void test(){
  Variables variables=new Variables();
  ParameterVariables parameterVariables=new ParameterVariables(1);
  Variable multiA=variables.newSparseMultionomialVariable("String_Node_Str",10);
  Variable dirichlet=parameterVariables.newSparseDirichletParameter("String_Node_Str",10);
  EF_SparseMultinomial_SparseDirichlet dist=new EF_SparseMultinomial_SparseDirichlet(multiA,dirichlet);
  EF_SparseDirichlet distDirichlet=new EF_SparseDirichlet(dirichlet);
  EF_LearningBayesianNetwork ef_learningBayesianNetwork=new EF_LearningBayesianNetwork(Arrays.asList(dist,distDirichlet),Arrays.asList(multiA,dirichlet));
}
Program: 21211
Project: 21211
Buggy source:
private void updateTime0(DataFlink<DynamicDataInstance> data){
  DataFlink<DataInstance> newdata=DataFlinkConverter.convertToStatic(data);
  this.parallelVBTime0.updateModel(newdata);
  List<Variable> vars=this.latentVariablesNames.stream().map(name -> this.dagTime0.getVariables().getVariableByName(name)).collect(Collectors.toList());
  this.dataPosteriorDataSet=this.parallelVBTime0.computePosteriorAssignment(vars);
}

Fixed version (ground truth):
private void updateTime0(DataFlink<DynamicDataInstance> data){
  DataFlink<DataInstance> newdata=DataFlinkConverter.convertToStatic(data);
  this.parallelVBTime0.updateModel(newdata);
  List<Variable> vars=this.latentVariablesNames.stream().map(name -> this.dagTime0.getVariables().getVariableByName(name)).collect(Collectors.toList());
  this.dataPosteriorDataSet=this.parallelVBTime0.computePosteriorAssignment(newdata,vars);
}
Program: 21212
Project: 21212
Buggy source:
/** 
 * {@inheritDoc}
 */
@Override public double updateModel(DataFlink<DataInstance> dataUpdate){
  try {
    Configuration config=new Configuration();
    config.setString(BN_NAME,this.dag.getName());
    config.setBytes(EFBN_NAME,Serialization.serializeObject(efBayesianNetwork));
    DataSet<DataInstance> dataset=this.dataFlink.getDataSet();
    this.sumSS=dataset.map(new SufficientSatisticsMAP()).withParameters(config).reduce(new SufficientSatisticsReduce()).collect().get(0);
    sumSS.sum(efBayesianNetwork.createInitSufficientStatistics());
    JobExecutionResult result=dataset.getExecutionEnvironment().getLastJobExecutionResult();
    numInstances=result.getAccumulatorResult(ParallelMaximumLikelihood.COUNTER_NAME + "String_Node_Str" + this.dag.getName());
    numInstances++;
  }
 catch (  Exception ex) {
    throw new UndeclaredThrowableException(ex);
  }
  return this.getLogMarginalProbability();
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}
 */
@Override public double updateModel(DataFlink<DataInstance> dataUpdate){
  try {
    Configuration config=new Configuration();
    config.setString(BN_NAME,this.dag.getName());
    config.setBytes(EFBN_NAME,Serialization.serializeObject(efBayesianNetwork));
    DataSet<DataInstance> dataset=dataUpdate.getDataSet();
    this.sumSS=dataset.map(new SufficientSatisticsMAP()).withParameters(config).reduce(new SufficientSatisticsReduce()).collect().get(0);
    sumSS.sum(efBayesianNetwork.createInitSufficientStatistics());
    JobExecutionResult result=dataset.getExecutionEnvironment().getLastJobExecutionResult();
    numInstances=result.getAccumulatorResult(ParallelMaximumLikelihood.COUNTER_NAME + "String_Node_Str" + this.dag.getName());
    numInstances++;
  }
 catch (  Exception ex) {
    throw new UndeclaredThrowableException(ex);
  }
  return this.getLogMarginalProbability();
}
Program: 21213
Project: 21213
Buggy source:
/** 
 * {@inheritDoc}
 */
@Override public double updateModel(DataFlink<DataInstance> dataUpdate){
  try {
    this.initLearning();
    Configuration config=new Configuration();
    config.setString(ParameterLearningAlgorithm.BN_NAME,this.dag.getName());
    config.setBytes(EFBN_NAME,Serialization.serializeObject(efBayesianNetwork));
    DataSet<DataInstance> dataset=this.dataFlink.getDataSet();
    this.sumSS=dataset.mapPartition(new SufficientSatisticsMAP()).withParameters(config).reduce(new SufficientSatisticsReduce()).collect().get(0);
    sumSS.sum(efBayesianNetwork.createInitSufficientStatistics());
    JobExecutionResult result=dataset.getExecutionEnvironment().getLastJobExecutionResult();
    numInstances=result.getAccumulatorResult(ParallelMaximumLikelihood2.COUNTER_NAME + "String_Node_Str" + this.dag.getName());
    numInstances++;
  }
 catch (  Exception ex) {
    throw new UndeclaredThrowableException(ex);
  }
  return this.getLogMarginalProbability();
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}
 */
@Override public double updateModel(DataFlink<DataInstance> dataUpdate){
  try {
    this.initLearning();
    Configuration config=new Configuration();
    config.setString(ParameterLearningAlgorithm.BN_NAME,this.dag.getName());
    config.setBytes(EFBN_NAME,Serialization.serializeObject(efBayesianNetwork));
    DataSet<DataInstance> dataset=dataUpdate.getDataSet();
    this.sumSS=dataset.mapPartition(new SufficientSatisticsMAP()).withParameters(config).reduce(new SufficientSatisticsReduce()).collect().get(0);
    sumSS.sum(efBayesianNetwork.createInitSufficientStatistics());
    JobExecutionResult result=dataset.getExecutionEnvironment().getLastJobExecutionResult();
    numInstances=result.getAccumulatorResult(ParallelMaximumLikelihood2.COUNTER_NAME + "String_Node_Str" + this.dag.getName());
    numInstances++;
  }
 catch (  Exception ex) {
    throw new UndeclaredThrowableException(ex);
  }
  return this.getLogMarginalProbability();
}
Program: 21214
Project: 21214
Buggy source:
/** 
 * {@inheritDoc}
 */
@Override public double getLogMarginalProbability(){
  throw new UnsupportedOperationException("String_Node_Str");
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}
 */
@Override public double getLogMarginalProbability(){
  return Double.NaN;
}
Program: 21215
Project: 21215
Buggy source:
public DataSet<DataPosteriorAssignment> computePosteriorAssignment(List<Variable> latentVariables){
  Attribute seq_id=this.dataFlink.getAttributes().getSeq_id();
  if (seq_id == null)   throw new IllegalArgumentException("String_Node_Str");
  try {
    Configuration config=new Configuration();
    config.setString(ParameterLearningAlgorithm.BN_NAME,this.dag.getName());
    config.setBytes(SVB,Serialization.serializeObject(svb));
    config.setBytes(LATENT_VARS,Serialization.serializeObject(latentVariables));
    return this.dataFlink.getBatchedDataSet(this.batchSize).flatMap(new ParallelVBMapInferenceAssignment()).withParameters(config);
  }
 catch (  Exception ex) {
    throw new UndeclaredThrowableException(ex);
  }
}

Fixed version (ground truth):
public DataSet<DataPosteriorAssignment> computePosteriorAssignment(DataFlink<DataInstance> dataFlink,List<Variable> latentVariables){
  Attribute seq_id=dataFlink.getAttributes().getSeq_id();
  if (seq_id == null)   throw new IllegalArgumentException("String_Node_Str");
  try {
    Configuration config=new Configuration();
    config.setString(ParameterLearningAlgorithm.BN_NAME,this.dag.getName());
    config.setBytes(SVB,Serialization.serializeObject(svb));
    config.setBytes(LATENT_VARS,Serialization.serializeObject(latentVariables));
    return dataFlink.getBatchedDataSet(this.batchSize).flatMap(new ParallelVBMapInferenceAssignment()).withParameters(config);
  }
 catch (  Exception ex) {
    throw new UndeclaredThrowableException(ex);
  }
}
Program: 21216
Project: 21216
Buggy source:
public DataSet<DataPosterior> computePosterior(){
  Attribute seq_id=this.dataFlink.getAttributes().getSeq_id();
  if (seq_id == null)   throw new IllegalArgumentException("String_Node_Str");
  try {
    Configuration config=new Configuration();
    config.setString(ParameterLearningAlgorithm.BN_NAME,this.dag.getName());
    config.setBytes(SVB,Serialization.serializeObject(svb));
    return this.dataFlink.getBatchedDataSet(this.batchSize).flatMap(new ParallelVBMapInference()).withParameters(config);
  }
 catch (  Exception ex) {
    throw new UndeclaredThrowableException(ex);
  }
}

Fixed version (ground truth):
public DataSet<DataPosterior> computePosterior(DataFlink<DataInstance> dataFlink){
  Attribute seq_id=dataFlink.getAttributes().getSeq_id();
  if (seq_id == null)   throw new IllegalArgumentException("String_Node_Str");
  try {
    Configuration config=new Configuration();
    config.setString(ParameterLearningAlgorithm.BN_NAME,this.dag.getName());
    config.setBytes(SVB,Serialization.serializeObject(svb));
    return dataFlink.getBatchedDataSet(this.batchSize).flatMap(new ParallelVBMapInference()).withParameters(config);
  }
 catch (  Exception ex) {
    throw new UndeclaredThrowableException(ex);
  }
}
Program: 21218
Project: 21218
Buggy source:
/** 
 * {@inheritDoc}
 */
@Override public void runLearning(){
  this.initLearning();
  boolean convergence=false;
  double totalTimeElbo=0;
  double totalTime=0;
  Iterator<DataOnMemory<DataInstance>> iterator=this.dataStream.iterableOverBatches(this.batchSize).iterator();
  while (!convergence) {
    long startBatch=System.nanoTime();
    DataOnMemory<DataInstance> batch=iterator.next();
    if (!iterator.hasNext())     iterator=this.dataStream.iterableOverBatches(this.batchSize).iterator();
    NaturalParameters newParam=svb.updateModelOnBatchParallel(batch).getVector();
    newParam.multiplyBy(this.dataSetSize / (double)this.batchSize);
    newParam.sum(prior);
    double stepSize=Math.pow(1 + iteration,-learningFactor);
    newParam.multiplyBy(stepSize);
    currentParam.multiplyBy((1 - stepSize));
    currentParam.sum(newParam);
    this.svb.updateNaturalParameterPosteriors(currentParam);
    long startBatchELBO=System.nanoTime();
    long endBatch=System.nanoTime();
    totalTimeElbo+=endBatch - startBatchELBO;
    System.out.println("String_Node_Str" + totalTimeElbo / 1e9);
    totalTime+=endBatch - startBatch;
    System.out.println("String_Node_Str" + iteration + "String_Node_Str"+ stepSize+ "String_Node_Str"+ totalTime / 1e9 + "String_Node_Str" + totalTimeElbo / 1e9 + "String_Node_Str" + (totalTime - totalTimeElbo) / 1e9 + "String_Node_Str");
    if ((totalTime - totalTimeElbo) / 1e9 > timiLimit) {
      convergence=true;
    }
    iteration++;
  }
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}
 */
@Override public void runLearning(){
  this.initLearning();
  boolean convergence=false;
  double totalTimeElbo=0;
  double totalTime=0;
  Iterator<DataOnMemory<DataInstance>> iterator=this.dataStream.iterableOverBatches(this.batchSize).iterator();
  while (!convergence) {
    long startBatch=System.nanoTime();
    DataOnMemory<DataInstance> batch=iterator.next();
    if (!iterator.hasNext())     iterator=this.dataStream.iterableOverBatches(this.batchSize).iterator();
    NaturalParameters newParam=svb.updateModelOnBatchParallel(batch).getVector();
    newParam.multiplyBy(this.dataSetSize / (double)this.batchSize);
    newParam.sum(prior);
    double stepSize=Math.pow(1 + iteration,-learningFactor);
    newParam.multiplyBy(stepSize);
    currentParam.multiplyBy((1 - stepSize));
    currentParam.sum(newParam);
    this.svb.updateNaturalParameterPosteriors(currentParam);
    long startBatchELBO=System.nanoTime();
    long endBatch=System.nanoTime();
    totalTimeElbo+=endBatch - startBatchELBO;
    System.out.println("String_Node_Str" + totalTimeElbo / 1e9);
    totalTime+=endBatch - startBatch;
    System.out.println("String_Node_Str" + iteration + "String_Node_Str"+ stepSize+ "String_Node_Str"+ totalTime / 1e9 + "String_Node_Str" + totalTimeElbo / 1e9 + "String_Node_Str" + (totalTime - totalTimeElbo) / 1e9 + "String_Node_Str");
    if ((totalTime - totalTimeElbo) / 1e9 > timiLimit || iteration > this.maximumLocalIterations) {
      convergence=true;
    }
    iteration++;
  }
}
Program: 21220
Project: 21220
Buggy source:
public static void baseTest(ExecutionEnvironment env,DataStream<DataInstance> data,BayesianNetwork network,int dataSetSize,int batchSize,double error) throws IOException, ClassNotFoundException {
  DataStreamWriter.writeDataToFile(data,"String_Node_Str");
  DataFlink<DataInstance> dataFlink=DataFlinkLoader.loadDataFromFile(env,"String_Node_Str",false);
  network.getDAG().getVariables().setAttributes(dataFlink.getAttributes());
  StochasticVI stochasticVI=new StochasticVI();
  stochasticVI.setLearningFactor(0.7);
  stochasticVI.setDataSetSize(dataSetSize);
  stochasticVI.setOutput(true);
  stochasticVI.setSeed(5);
  stochasticVI.setBatchSize(batchSize);
  stochasticVI.setLocalThreshold(0.001);
  stochasticVI.setMaximumLocalIterations(100);
  stochasticVI.setTimiLimit(10);
  stochasticVI.setDAG(network.getDAG());
  stochasticVI.initLearning();
  stochasticVI.updateModel(dataFlink);
  BayesianNetwork bnet=stochasticVI.getLearntBayesianNetwork();
  for (  Variable var : network.getVariables()) {
    System.out.println("String_Node_Str" + var.getName() + "String_Node_Str");
    System.out.println("String_Node_Str" + network.getConditionalDistribution(var));
    System.out.println("String_Node_Str" + bnet.getConditionalDistribution(var));
    Assert.assertTrue(bnet.getConditionalDistribution(var).equalDist(network.getConditionalDistribution(var),error));
  }
  Assert.assertTrue(bnet.equalBNs(network,error));
}

Fixed version (ground truth):
public static void baseTest(ExecutionEnvironment env,DataStream<DataInstance> data,BayesianNetwork network,int dataSetSize,int batchSize,double error) throws IOException, ClassNotFoundException {
  DataStreamWriter.writeDataToFile(data,"String_Node_Str");
  DataFlink<DataInstance> dataFlink=DataFlinkLoader.loadDataFromFile(env,"String_Node_Str",false);
  network.getDAG().getVariables().setAttributes(dataFlink.getAttributes());
  StochasticVI stochasticVI=new StochasticVI();
  stochasticVI.setLearningFactor(0.7);
  stochasticVI.setDataSetSize(dataSetSize);
  stochasticVI.setOutput(true);
  stochasticVI.setSeed(5);
  stochasticVI.setBatchSize(batchSize);
  stochasticVI.setLocalThreshold(0.001);
  stochasticVI.setMaximumLocalIterations(100);
  stochasticVI.setTimiLimit(20);
  stochasticVI.setDAG(network.getDAG());
  stochasticVI.initLearning();
  stochasticVI.updateModel(dataFlink);
  BayesianNetwork bnet=stochasticVI.getLearntBayesianNetwork();
  for (  Variable var : network.getVariables()) {
    System.out.println("String_Node_Str" + var.getName() + "String_Node_Str");
    System.out.println("String_Node_Str" + network.getConditionalDistribution(var));
    System.out.println("String_Node_Str" + bnet.getConditionalDistribution(var));
    Assert.assertTrue(bnet.getConditionalDistribution(var).equalDist(network.getConditionalDistribution(var),error));
  }
  Assert.assertTrue(bnet.equalBNs(network,error));
}
Program: 21221
Project: 21221
Buggy source:
public static void test2(){
  Variables variables=new Variables();
  EF_SparseMultinomial dist=new EF_SparseMultinomial(variables.newMultionomialVariable("String_Node_Str",10));
  int size=10;
  SufficientStatistics sufficientStatistics=dist.getSufficientStatistics(1);
  sufficientStatistics.multiplyBy(size);
  sufficientStatistics.sum(dist.createInitSufficientStatistics());
  System.out.println(sufficientStatistics.output());
  System.out.println();
  dist.setMomentParameters(sufficientStatistics);
  System.out.println(dist.getMomentParameters().output());
  System.out.println();
  dist.updateNaturalFromMomentParameters();
  System.out.println(dist.getNaturalParameters().output());
  System.out.println();
  dist.fixNumericalInstability();
  System.out.println(dist.getNaturalParameters().output());
  System.out.println();
  dist.updateMomentFromNaturalParameters();
  System.out.println(dist.getMomentParameters().output());
  System.out.println((size + 0.1) / (size + 1));
  assertEquals((size + 0.1) / (size + 1),dist.getMomentParameters().get(1),0.0000001);
}

Fixed version (ground truth):
public static void test2(){
  Variables variables=new Variables();
  EF_SparseMultinomial dist=new EF_SparseMultinomial(variables.newMultinomialVariable("String_Node_Str",10));
  int size=10;
  SufficientStatistics sufficientStatistics=dist.getSufficientStatistics(1);
  sufficientStatistics.multiplyBy(size);
  sufficientStatistics.sum(dist.createInitSufficientStatistics());
  System.out.println(sufficientStatistics.output());
  System.out.println();
  dist.setMomentParameters(sufficientStatistics);
  System.out.println(dist.getMomentParameters().output());
  System.out.println();
  dist.updateNaturalFromMomentParameters();
  System.out.println(dist.getNaturalParameters().output());
  System.out.println();
  dist.fixNumericalInstability();
  System.out.println(dist.getNaturalParameters().output());
  System.out.println();
  dist.updateMomentFromNaturalParameters();
  System.out.println(dist.getMomentParameters().output());
  System.out.println((size + 0.1) / (size + 1));
  assertEquals((size + 0.1) / (size + 1),dist.getMomentParameters().get(1),0.0000001);
}