Program: 143978
Project: 143978
Buggy source:
public static ExperimentResults runExperiment(ErrorEstimationMethod method,List<boolean[][]> functionOutputs,List<boolean[]> trueLabels,List<boolean[][]> evaluationFunctionOutputs,double alpha,double gamma){
  double[][] errorRates=new double[functionOutputs.size()][];
  boolean[][] labels=new boolean[functionOutputs.size()][];
  int numberOfClusters=1;
  double logLikelihood=0;
switch (method) {
case BAYESIAN_COMBINATION_OF_CLASSIFIERS:
    BayesianCombinationOfClassifiers bcc=new BayesianCombinationOfClassifiers(functionOutputs,18000,10,200,alpha);
  bcc.runGibbsSampler();
errorRates=bcc.getErrorRatesMeans();
logLikelihood=bcc.logLikelihood(evaluationFunctionOutputs);
double[][] labelMeansBcc=bcc.getLabelMeans();
for (int p=0; p < functionOutputs.size(); p++) {
labels[p]=new boolean[functionOutputs.get(p).length];
for (int i=0; i < functionOutputs.get(p).length; i++) {
labels[p][i]=labelMeansBcc[p][i] >= 0.5;
}
}
break;
case AR_2:
for (int p=0; p < functionOutputs.size(); p++) {
int numberOfFunctions=functionOutputs.get(p)[0].length;
ErrorEstimationData errorEstimationData=new ErrorEstimationData.Builder(Arrays.asList(functionOutputs.get(p)),2,true).build();
ErrorEstimation errorEstimation=new ErrorEstimation.Builder(errorEstimationData).optimizationSolverType(ErrorEstimationInternalSolver.IP_OPT).build();
double[] allErrorRates=errorEstimation.solve().getErrorRates().array;
errorRates[p]=new double[numberOfFunctions];
System.arraycopy(allErrorRates,0,errorRates[p],0,numberOfFunctions);
labels[p]=new boolean[functionOutputs.get(p).length];
for (int i=0; i < functionOutputs.get(p).length; i++) {
double labelsSum=0;
double errorRatesSum=0;
for (int j=0; j < functionOutputs.get(p)[i].length; j++) {
labelsSum+=(1 - errorRates[p][j]) * (functionOutputs.get(p)[i][j] ? 1 : 0);
errorRatesSum+=(1 - errorRates[p][j]);
}
labels[p][i]=labelsSum / errorRatesSum >= 0.5;
}
}
break;
case AR_N:
for (int p=0; p < functionOutputs.size(); p++) {
int numberOfFunctions=functionOutputs.get(p)[0].length;
ErrorEstimationData errorEstimationData=new ErrorEstimationData.Builder(Arrays.asList(functionOutputs.get(p)),functionOutputs.get(0)[0].length,true).build();
ErrorEstimation errorEstimation=new ErrorEstimation.Builder(errorEstimationData).optimizationSolverType(ErrorEstimationInternalSolver.IP_OPT).build();
double[] allErrorRates=errorEstimation.solve().getErrorRates().array;
errorRates[p]=new double[numberOfFunctions];
System.arraycopy(allErrorRates,0,errorRates[p],0,numberOfFunctions);
labels[p]=new boolean[functionOutputs.get(p).length];
for (int i=0; i < functionOutputs.get(p).length; i++) {
double labelsSum=0;
double errorRatesSum=0;
for (int j=0; j < functionOutputs.get(p)[i].length; j++) {
labelsSum+=(1 - errorRates[p][j]) * (functionOutputs.get(p)[i][j] ? 1 : 0);
errorRatesSum+=(1 - errorRates[p][j]);
}
labels[p][i]=labelsSum / errorRatesSum >= 0.5;
}
}
break;
case ERROR_ESTIMATION_GM:
ErrorEstimationGraphicalModel eesgm=new ErrorEstimationGraphicalModel(functionOutputs,4000,10,200);
eesgm.runGibbsSampler();
errorRates=eesgm.getErrorRatesMeans();
double[][] labelMeansEesgm=eesgm.getLabelMeans();
for (int p=0; p < functionOutputs.size(); p++) {
labels[p]=new boolean[functionOutputs.get(p).length];
for (int i=0; i < functionOutputs.get(p).length; i++) {
labels[p][i]=labelMeansEesgm[p][i] >= 0.5;
}
}
break;
case COUPLED_ERROR_ESTIMATION_GM:
CoupledErrorEstimationGraphicalModel eedfdpgm=new CoupledErrorEstimationGraphicalModel(functionOutputs,5000,10,alpha);
eedfdpgm.performGibbsSampling();
errorRates=eedfdpgm.getErrorRatesMeans();
logLikelihood=eedfdpgm.logLikelihood(evaluationFunctionOutputs);
double[][] labelMeansEedfdpgm=eedfdpgm.getLabelMeans();
for (int p=0; p < functionOutputs.size(); p++) {
labels[p]=new boolean[functionOutputs.get(p).length];
for (int i=0; i < functionOutputs.get(p).length; i++) {
labels[p][i]=labelMeansEedfdpgm[p][i] >= 0.5;
}
}
break;
case HIERARCHICAL_COUPLED_ERROR_ESTIMATION_GM:
ErrorEstimationDomainsHDPNew eedfhdp=new ErrorEstimationDomainsHDPNew(functionOutputs,alpha,gamma);
eedfhdp.run_gibbs_collapsed(3000);
eedfhdp.run_gibbs_uncollapsed(1000,10,200);
errorRates=eedfhdp.rates_to_return;
double[][] labelMeansEedfhdpmgm=eedfhdp.labels_to_return;
int li_cnt[][]=new int[functionOutputs.size()][2];
for (int p=0; p < functionOutputs.size(); p++) {
labels[p]=new boolean[functionOutputs.get(p).length];
for (int i=0; i < functionOutputs.get(p).length; i++) {
labels[p][i]=labelMeansEedfhdpmgm[p][i] >= 0.5;
int lid=labelMeansEedfhdpmgm[p][i] >= 0.5 ? 1 : 0;
li_cnt[p][lid]++;
}
}
logLikelihood=eedfhdp.get_log_likelihood(evaluationFunctionOutputs,alpha,gamma,1000,li_cnt);
break;
}
double[] errorRatesMAD=new double[functionOutputs.size()];
double errorRatesMADMean=0;
double[] labelsErrorRate=new double[functionOutputs.size()];
double labelsErrorRateMean=0;
for (int p=0; p < functionOutputs.size(); p++) {
labelsErrorRate[p]=0;
double[] realErrorRates=new double[errorRates[p].length];
for (int i=0; i < trueLabels.get(p).length; i++) {
labelsErrorRate[p]+=(labels[p][i] != trueLabels.get(p)[i]) ? 1 : 0;
for (int j=0; j < errorRates[p].length; j++) realErrorRates[j]+=(functionOutputs.get(p)[i][j] != trueLabels.get(p)[i]) ? 1 : 0;
}
labelsErrorRate[p]/=trueLabels.get(p).length;
labelsErrorRateMean+=labelsErrorRate[p];
errorRatesMAD[p]=0;
for (int j=0; j < errorRates[p].length; j++) {
realErrorRates[j]/=trueLabels.get(p).length;
errorRatesMAD[p]+=Math.abs(errorRates[p][j] - realErrorRates[j]);
}
errorRatesMAD[p]/=errorRates[p].length;
errorRatesMADMean+=errorRatesMAD[p];
}
errorRatesMADMean/=functionOutputs.size();
labelsErrorRateMean/=functionOutputs.size();
return new ExperimentResults(errorRates,errorRatesMADMean,labelsErrorRateMean,logLikelihood);
}

Fixed version (ground truth):
public static ExperimentResults runExperiment(ErrorEstimationMethod method,List<boolean[][]> functionOutputs,List<boolean[]> trueLabels,List<boolean[][]> evaluationFunctionOutputs,double alpha,double gamma){
  double[][] errorRates=new double[functionOutputs.size()][];
  boolean[][] labels=new boolean[functionOutputs.size()][];
  int numberOfClusters=1;
  double logLikelihood=0;
switch (method) {
case BAYESIAN_COMBINATION_OF_CLASSIFIERS:
    BayesianCombinationOfClassifiers bcc=new BayesianCombinationOfClassifiers(functionOutputs,4000,10,200,alpha);
  bcc.runGibbsSampler();
errorRates=bcc.getErrorRatesMeans();
logLikelihood=bcc.logLikelihood(evaluationFunctionOutputs);
double[][] labelMeansBcc=bcc.getLabelMeans();
for (int p=0; p < functionOutputs.size(); p++) {
labels[p]=new boolean[functionOutputs.get(p).length];
for (int i=0; i < functionOutputs.get(p).length; i++) {
labels[p][i]=labelMeansBcc[p][i] >= 0.5;
}
}
break;
case AR_2:
for (int p=0; p < functionOutputs.size(); p++) {
int numberOfFunctions=functionOutputs.get(p)[0].length;
ErrorEstimationData errorEstimationData=new ErrorEstimationData.Builder(Arrays.asList(functionOutputs.get(p)),2,true).build();
ErrorEstimation errorEstimation=new ErrorEstimation.Builder(errorEstimationData).optimizationSolverType(ErrorEstimationInternalSolver.IP_OPT).build();
double[] allErrorRates=errorEstimation.solve().getErrorRates().array;
errorRates[p]=new double[numberOfFunctions];
System.arraycopy(allErrorRates,0,errorRates[p],0,numberOfFunctions);
labels[p]=new boolean[functionOutputs.get(p).length];
for (int i=0; i < functionOutputs.get(p).length; i++) {
double labelsSum=0;
double errorRatesSum=0;
for (int j=0; j < functionOutputs.get(p)[i].length; j++) {
labelsSum+=(1 - errorRates[p][j]) * (functionOutputs.get(p)[i][j] ? 1 : 0);
errorRatesSum+=(1 - errorRates[p][j]);
}
labels[p][i]=labelsSum / errorRatesSum >= 0.5;
}
}
break;
case AR_N:
for (int p=0; p < functionOutputs.size(); p++) {
int numberOfFunctions=functionOutputs.get(p)[0].length;
ErrorEstimationData errorEstimationData=new ErrorEstimationData.Builder(Arrays.asList(functionOutputs.get(p)),functionOutputs.get(0)[0].length,true).build();
ErrorEstimation errorEstimation=new ErrorEstimation.Builder(errorEstimationData).optimizationSolverType(ErrorEstimationInternalSolver.IP_OPT).build();
double[] allErrorRates=errorEstimation.solve().getErrorRates().array;
errorRates[p]=new double[numberOfFunctions];
System.arraycopy(allErrorRates,0,errorRates[p],0,numberOfFunctions);
labels[p]=new boolean[functionOutputs.get(p).length];
for (int i=0; i < functionOutputs.get(p).length; i++) {
double labelsSum=0;
double errorRatesSum=0;
for (int j=0; j < functionOutputs.get(p)[i].length; j++) {
labelsSum+=(1 - errorRates[p][j]) * (functionOutputs.get(p)[i][j] ? 1 : 0);
errorRatesSum+=(1 - errorRates[p][j]);
}
labels[p][i]=labelsSum / errorRatesSum >= 0.5;
}
}
break;
case ERROR_ESTIMATION_GM:
BayesianErrorEstimation eesgm=new BayesianErrorEstimation(functionOutputs,4000,10,200);
eesgm.runGibbsSampler();
errorRates=eesgm.getErrorRatesMeans();
double[][] labelMeansEesgm=eesgm.getLabelMeans();
for (int p=0; p < functionOutputs.size(); p++) {
labels[p]=new boolean[functionOutputs.get(p).length];
for (int i=0; i < functionOutputs.get(p).length; i++) {
labels[p][i]=labelMeansEesgm[p][i] >= 0.5;
}
}
break;
case COUPLED_ERROR_ESTIMATION_GM:
CoupledBayesianErrorEstimation eedfdpgm=new CoupledBayesianErrorEstimation(functionOutputs,5000,10,alpha);
eedfdpgm.performGibbsSampling();
errorRates=eedfdpgm.getErrorRatesMeans();
logLikelihood=eedfdpgm.logLikelihood(evaluationFunctionOutputs);
double[][] labelMeansEedfdpgm=eedfdpgm.getLabelMeans();
for (int p=0; p < functionOutputs.size(); p++) {
labels[p]=new boolean[functionOutputs.get(p).length];
for (int i=0; i < functionOutputs.get(p).length; i++) {
labels[p][i]=labelMeansEedfdpgm[p][i] >= 0.5;
}
}
break;
case HIERARCHICAL_COUPLED_ERROR_ESTIMATION_GM:
HierarchicalCoupledBayesianErrorEstimation hcee=new HierarchicalCoupledBayesianErrorEstimation(functionOutputs,4000,10,200,alpha,gamma);
hcee.runGibbsSampler();
errorRates=hcee.getErrorRatesMeans();
logLikelihood=hcee.logLikelihood(evaluationFunctionOutputs);
double[][] labelMeansHcee=hcee.getLabelMeans();
for (int p=0; p < functionOutputs.size(); p++) {
labels[p]=new boolean[functionOutputs.get(p).length];
for (int i=0; i < functionOutputs.get(p).length; i++) {
labels[p][i]=labelMeansHcee[p][i] >= 0.5;
}
}
break;
}
double[] errorRatesMAD=new double[functionOutputs.size()];
double errorRatesMADMean=0;
double[] labelsErrorRate=new double[functionOutputs.size()];
double labelsErrorRateMean=0;
for (int p=0; p < functionOutputs.size(); p++) {
labelsErrorRate[p]=0;
double[] realErrorRates=new double[errorRates[p].length];
for (int i=0; i < trueLabels.get(p).length; i++) {
labelsErrorRate[p]+=(labels[p][i] != trueLabels.get(p)[i]) ? 1 : 0;
for (int j=0; j < errorRates[p].length; j++) realErrorRates[j]+=(functionOutputs.get(p)[i][j] != trueLabels.get(p)[i]) ? 1 : 0;
}
labelsErrorRate[p]/=trueLabels.get(p).length;
labelsErrorRateMean+=labelsErrorRate[p];
errorRatesMAD[p]=0;
for (int j=0; j < errorRates[p].length; j++) {
realErrorRates[j]/=trueLabels.get(p).length;
errorRatesMAD[p]+=Math.abs(errorRates[p][j] - realErrorRates[j]);
}
errorRatesMAD[p]/=errorRates[p].length;
errorRatesMADMean+=errorRatesMAD[p];
}
errorRatesMADMean/=functionOutputs.size();
labelsErrorRateMean/=functionOutputs.size();
return new ExperimentResults(errorRates,errorRatesMADMean,labelsErrorRateMean,logLikelihood);
}