Program: 140834
Project: 140834
Buggy source:
public static void decomposeVariance(RandomForest existingForest,List<AlgorithmRun> testRuns,ParamConfigurationSpace configSpace,Random rand,boolean compareToDef,double quantileToCompareTo,boolean computePairwiseInteraction,String outputDir,boolean logModel,boolean plotMarginals) throws IOException, InterruptedException {
  RandomForest forest=ModelEvaluation.extractMarginalForest(existingForest,testRuns,configSpace,rand,compareToDef,quantileToCompareTo);
  RandomForestPreprocessor.preprocessRandomForest(forest,configSpace);
  DecimalFormat decim=new DecimalFormat("String_Node_Str");
  DecimalFormat decim2=new DecimalFormat("String_Node_Str");
  String s;
  double timeForComputingMainEffects=0;
  double timeForComputingBinaryEffects=0;
  HashMap<HashSet<Integer>,Double> totalFractionsExplained=new HashMap<HashSet<Integer>,Double>();
  double sumOfFractionsOfBinaries=0;
  int numDim=configSpace.getCategoricalSize().length;
  double[][] allObservations=new double[numDim][];
  double[][] allIntervalSizes=new double[numDim][];
  for (int numTree=0; numTree < forest.Trees.length; numTree++) {
    HashSet<Integer> allVariableIndices=new HashSet<Integer>();
    for (int j=0; j < configSpace.getCategoricalSize().length; j++) {
      allVariableIndices.add(new Integer(j));
    }
    double thisTreeTotalVariance=RandomForestPreprocessor.computeTotalVarianceOfRegressionTree(forest.Trees[numTree],configSpace);
    if (thisTreeTotalVariance == 0.0) {
      s="String_Node_Str" + numTree + "String_Node_Str";
      log.info(s);
      continue;
    }
    s="String_Node_Str" + numTree + "String_Node_Str"+ thisTreeTotalVariance;
    log.info(s);
    double thisTreeFractionOfVarianceExplainedByMarginals=0;
    HashMap<HashSet<Integer>,Double> thisTreeVarianceContributions=new HashMap<HashSet<Integer>,Double>();
    HashMap<Integer,Double> singleVarianceContributions=new HashMap<Integer,Double>();
    double marg;
    long start=System.nanoTime();
    for (int dim=0; dim < numDim; dim++) {
      int numVals=configSpace.getCategoricalSize()[dim];
      if (numVals > 0) {
        allObservations[dim]=new double[numVals];
        allIntervalSizes[dim]=new double[numVals];
        for (int valIndex=0; valIndex < numVals; valIndex++) {
          allObservations[dim][valIndex]=valIndex;
          allIntervalSizes[dim][valIndex]=1.0 / numVals;
        }
      }
 else {
        List<Double> splitPoints=new ArrayList<Double>();
        for (int node_index=0; node_index < forest.Trees[numTree].var.length; node_index++) {
          if (forest.Trees[numTree].var[node_index] == dim + 1) {
            splitPoints.add(forest.Trees[numTree].cut[node_index]);
          }
        }
        splitPoints.add(0.0);
        splitPoints.add(1.0);
        Collections.sort(splitPoints);
        if (splitPoints.size() == 2) {
          allObservations[dim]=new double[0];
          allIntervalSizes[dim]=new double[0];
        }
 else {
          allObservations[dim]=new double[splitPoints.size() - 1];
          allIntervalSizes[dim]=new double[splitPoints.size() - 1];
          for (int lowerIntervalId=0; lowerIntervalId < splitPoints.size() - 1; lowerIntervalId++) {
            allObservations[dim][lowerIntervalId]=(splitPoints.get(lowerIntervalId) + splitPoints.get(lowerIntervalId + 1)) / 2;
            allIntervalSizes[dim][lowerIntervalId]=splitPoints.get(lowerIntervalId + 1) - splitPoints.get(lowerIntervalId);
          }
        }
      }
    }
    for (int dim=0; dim < numDim; dim++) {
      int[] indicesOfObservations=new int[1];
      indicesOfObservations[0]=dim;
      ArrayList<Double> as=new ArrayList<Double>();
      double weightedSum=0, weightedSumOfSquares=0;
      for (int valIndex=0; valIndex < allObservations[dim].length; valIndex++) {
        double[] observations=new double[1];
        observations[0]=allObservations[dim][valIndex];
        log.debug("String_Node_Str" + numTree + "String_Node_Str"+ dim+ "String_Node_Str"+ observations[0]);
        marg=forest.Trees[numTree].marginalPerformance(indicesOfObservations,observations);
        log.debug("String_Node_Str" + numTree + "String_Node_Str"+ dim+ "String_Node_Str"+ marg);
        as.add(marg);
        double intervalSize=allIntervalSizes[dim][valIndex];
        weightedSum+=marg * intervalSize;
        weightedSumOfSquares+=marg * marg * intervalSize;
      }
      double thisMarginalVarianceContribution=weightedSumOfSquares - weightedSum * weightedSum;
      log.debug("String_Node_Str" + numTree + "String_Node_Str"+ thisMarginalVarianceContribution);
      double thisMarginalFractionOfVarianceExplained=thisMarginalVarianceContribution / thisTreeTotalVariance * 100;
      if (Double.isNaN(thisMarginalFractionOfVarianceExplained)) {
        throw new RuntimeException("String_Node_Str");
      }
      thisTreeFractionOfVarianceExplainedByMarginals+=thisMarginalFractionOfVarianceExplained;
      s="String_Node_Str" + numTree + "String_Node_Str"+ decim.format(thisMarginalFractionOfVarianceExplained)+ "String_Node_Str"+ configSpace.getParameterNames().get(dim);
      log.info(s);
      HashSet<Integer> set=new HashSet<Integer>();
      set.add(dim);
      thisTreeVarianceContributions.put(set,thisMarginalVarianceContribution);
      singleVarianceContributions.put(dim,thisMarginalVarianceContribution);
    }
    double thisTreeTimeForComputingMainEffects=(System.nanoTime() - start) * 1.0e-9;
    timeForComputingMainEffects+=thisTreeTimeForComputingMainEffects;
    s="String_Node_Str" + numTree + "String_Node_Str"+ "String_Node_Str"+ thisTreeFractionOfVarianceExplainedByMarginals+ "String_Node_Str"+ thisTreeTimeForComputingMainEffects+ "String_Node_Str";
    log.info(s);
    double thisTreeFractionOfVarianceExplainedByBinaries=0;
    double thisTreeTimeForComputingBinaryEffects=0;
    if (computePairwiseInteraction) {
      for (int dim1=0; dim1 < numDim; dim1++) {
        for (int dim2=dim1 + 1; dim2 < numDim; dim2++) {
          int[] indicesOfObservations=new int[2];
          indicesOfObservations[0]=dim1;
          ArrayList<Double> as=new ArrayList<Double>();
          indicesOfObservations[1]=dim2;
          double weightedSum=0, weightedSumOfSquares=0;
          for (int valIndex1=0; valIndex1 < allObservations[dim1].length; valIndex1++) {
            for (int valIndex2=0; valIndex2 < allObservations[dim2].length; valIndex2++) {
              double[] observations=new double[2];
              observations[0]=allObservations[dim1][valIndex1];
              observations[1]=allObservations[dim2][valIndex2];
              double intervalSize1=allIntervalSizes[dim1][valIndex1];
              double intervalSize2=allIntervalSizes[dim2][valIndex2];
              marg=forest.Trees[numTree].marginalPerformance(indicesOfObservations,observations);
              weightedSum+=marg * intervalSize1 * intervalSize2;
              weightedSumOfSquares+=marg * marg * intervalSize1* intervalSize2;
              s="String_Node_Str" + configSpace.getParameterNames().get(dim1) + "String_Node_Str"+ observations[0]+ "String_Node_Str"+ configSpace.getParameterNames().get(dim2)+ "String_Node_Str"+ observations[1]+ "String_Node_Str"+ marg;
              as.add(marg);
            }
          }
          double thisBinaryVarianceContribution=weightedSumOfSquares - weightedSum * weightedSum;
          thisBinaryVarianceContribution-=singleVarianceContributions.get(dim1);
          thisBinaryVarianceContribution-=singleVarianceContributions.get(dim2);
          log.debug("String_Node_Str" + dim1 + "String_Node_Str"+ singleVarianceContributions.get(dim1));
          log.debug("String_Node_Str" + dim2 + "String_Node_Str"+ singleVarianceContributions.get(dim2));
          double thisBinaryFractionOfVarianceExplained=thisBinaryVarianceContribution / thisTreeTotalVariance * 100;
          thisTreeFractionOfVarianceExplainedByBinaries+=thisBinaryFractionOfVarianceExplained;
          s=decim.format(thisBinaryFractionOfVarianceExplained) + "String_Node_Str" + configSpace.getParameterNames().get(dim1)+ "String_Node_Str"+ configSpace.getParameterNames().get(dim2);
          log.debug(s);
          HashSet<Integer> set=new HashSet<Integer>();
          set.add(dim1);
          set.add(dim2);
          thisTreeVarianceContributions.put(set,thisBinaryVarianceContribution);
        }
      }
      thisTreeTimeForComputingBinaryEffects=(System.nanoTime() - start) * 1.0e-9 - thisTreeTimeForComputingMainEffects;
      timeForComputingBinaryEffects+=thisTreeTimeForComputingBinaryEffects;
      s="String_Node_Str" + numTree + "String_Node_Str"+ "String_Node_Str"+ thisTreeFractionOfVarianceExplainedByBinaries+ "String_Node_Str"+ thisTreeTimeForComputingBinaryEffects+ "String_Node_Str";
      log.info(s);
    }
    double tmpThisTreeFractionExplained=0;
    for (    HashSet<Integer> indexSet : thisTreeVarianceContributions.keySet()) {
      double previousFractionExplained=0;
      if (numTree > 0) {
        previousFractionExplained=totalFractionsExplained.get(indexSet);
      }
      double thisFractionExplained=thisTreeVarianceContributions.get(indexSet) / thisTreeTotalVariance * 100;
      log.debug("String_Node_Str" + indexSet.toString() + "String_Node_Str"+ numTree+ "String_Node_Str"+ thisTreeVarianceContributions.get(indexSet));
      log.debug("String_Node_Str" + numTree + "String_Node_Str"+ thisTreeTotalVariance);
      tmpThisTreeFractionExplained+=thisFractionExplained;
      totalFractionsExplained.put(indexSet,previousFractionExplained + 1.0 / forest.Trees.length * thisFractionExplained);
      log.debug("String_Node_Str" + numTree + "String_Node_Str"+ totalFractionsExplained.get(indexSet));
    }
    log.debug(tmpThisTreeFractionExplained + "String_Node_Str");
  }
  double tmpFractionExplained=0;
  for (  HashSet<Integer> indexSet : totalFractionsExplained.keySet()) {
    tmpFractionExplained+=totalFractionsExplained.get(indexSet);
  }
  log.debug(tmpFractionExplained + "String_Node_Str");
  double sumOfFractionsOfMarginals=0;
  for (  HashSet<Integer> indexSet : totalFractionsExplained.keySet()) {
    if (indexSet.size() == 1) {
      sumOfFractionsOfMarginals+=totalFractionsExplained.get(indexSet);
    }
  }
  s="String_Node_Str" + sumOfFractionsOfMarginals + "String_Node_Str";
  log.info(s);
  if (computePairwiseInteraction) {
    sumOfFractionsOfBinaries=0;
    for (    HashSet<Integer> indexSet : totalFractionsExplained.keySet()) {
      if (indexSet.size() == 2) {
        sumOfFractionsOfBinaries+=totalFractionsExplained.get(indexSet);
      }
    }
    s="String_Node_Str" + sumOfFractionsOfBinaries + "String_Node_Str";
    log.info(s);
  }
  s="String_Node_Str" + decim.format(sumOfFractionsOfMarginals) + "String_Node_Str"+ decim.format(timeForComputingMainEffects)+ "String_Node_Str"+ decim.format(sumOfFractionsOfBinaries)+ "String_Node_Str"+ decim.format(timeForComputingBinaryEffects)+ "String_Node_Str";
  log.info(s);
  ArrayList<String> paramNamesOrderByMarginalVarianceExplained=new ArrayList<String>();
  int idx=0;
  ArrayList<Map.Entry<HashSet,Double>> list=sortedKeysByValue(totalFractionsExplained);
  int numMaxEffectsToPrint=30;
  s="String_Node_Str" + numMaxEffectsToPrint + "String_Node_Str";
  log.info(s);
  for (  Map.Entry<HashSet,Double> entry : list) {
    HashSet<Integer> set=entry.getKey();
    numMaxEffectsToPrint--;
    if (set.size() == 1) {
      Integer varIndex=(Integer)set.toArray()[0];
      String parameterName=configSpace.getParameterNames().get(varIndex);
      paramNamesOrderByMarginalVarianceExplained.add(parameterName);
      if (numMaxEffectsToPrint > 0) {
        s=decim2.format(entry.getValue()) + "String_Node_Str" + parameterName;
        log.info(s);
      }
    }
 else     if (set.size() == 2) {
      Integer varIndex1=(Integer)set.toArray()[0];
      Integer varIndex2=(Integer)set.toArray()[1];
      String varName1=configSpace.getParameterNames().get(varIndex1);
      String varName2=configSpace.getParameterNames().get(varIndex2);
      if (numMaxEffectsToPrint > 0) {
        s=decim2.format(entry.getValue()) + "String_Node_Str" + varName1+ "String_Node_Str"+ varName2;
        log.info(s);
      }
    }
  }
  String allSingleMarginalsOutputFile=outputDir + "String_Node_Str";
  PrintWriter writer=null;
  try {
    writer=new PrintWriter(allSingleMarginalsOutputFile,"String_Node_Str");
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
  if (plotMarginals) {
    log.info("String_Node_Str");
    for (int dim=0; dim < numDim; dim++) {
      String parameterName=configSpace.getParameterNames().get(dim);
      String parameterFileName=parameterName.replace('/','_');
      double[] valuesToPredictFor;
      if (configSpace.getCategoricalSize()[dim] > 0) {
        valuesToPredictFor=allObservations[dim];
      }
 else {
        int numVals=11;
        valuesToPredictFor=new double[numVals];
        for (int valIndex=0; valIndex < numVals; valIndex++) {
          valuesToPredictFor[valIndex]=(valIndex + 0.0) / (numVals - 1);
        }
      }
      String singleMarginalOutputFile=outputDir + "String_Node_Str" + parameterFileName+ "String_Node_Str";
      PrintWriter singleWriter=null;
      try {
        singleWriter=new PrintWriter(singleMarginalOutputFile,"String_Node_Str");
      }
 catch (      Exception e) {
        e.printStackTrace();
      }
      int[] indicesOfObservations=new int[1];
      indicesOfObservations[0]=dim;
      for (int valIndex=0; valIndex < valuesToPredictFor.length; valIndex++) {
        double[] observations=new double[1];
        observations[0]=valuesToPredictFor[valIndex];
        ArrayList<Double> margs=new ArrayList<Double>();
        for (int numTree=0; numTree < forest.Trees.length; numTree++) {
          margs.add(forest.Trees[numTree].marginalPerformance(indicesOfObservations,observations));
        }
        double avg=0;
        for (        Double marg : margs) {
          avg+=marg / margs.size();
        }
        double std=0;
        for (        Double marg : margs) {
          std+=Math.pow(marg - avg,2) / margs.size();
        }
        std=Math.sqrt(std);
        if (configSpace.getCategoricalSize()[dim] > 0) {
          writer.println(configSpace.getValuesMap().get(parameterName).get(valIndex) + "String_Node_Str" + avg+ "String_Node_Str"+ std);
          singleWriter.println(valIndex + "String_Node_Str" + configSpace.getValuesMap().get(parameterName).get(valIndex)+ "String_Node_Str"+ avg+ "String_Node_Str"+ std);
        }
 else {
          writer.println(valuesToPredictFor[valIndex] + "String_Node_Str" + avg+ "String_Node_Str"+ std);
          Map<String,NormalizedRange> normalizeRangeMap=configSpace.getNormalizedRangeMap();
          NormalizedRange normalizedRange=normalizeRangeMap.get(parameterName);
          singleWriter.println(valIndex + "String_Node_Str" + normalizedRange.unnormalizeValue(valuesToPredictFor[valIndex])+ "String_Node_Str"+ avg+ "String_Node_Str"+ std);
        }
      }
      writer.println();
      singleWriter.close();
      String gnuplotFile=outputDir + "String_Node_Str" + parameterFileName+ "String_Node_Str";
      singleWriter=null;
      try {
        singleWriter=new PrintWriter(gnuplotFile,"String_Node_Str");
      }
 catch (      Exception e) {
        e.printStackTrace();
      }
      singleWriter.println("String_Node_Str");
      singleWriter.println("String_Node_Str");
      String pdfFilename=outputDir + "String_Node_Str" + parameterFileName+ "String_Node_Str";
      singleWriter.println("String_Node_Str" + pdfFilename + "String_Node_Str");
      singleWriter.println("String_Node_Str");
      singleWriter.println("String_Node_Str");
      singleWriter.println("String_Node_Str" + singleMarginalOutputFile + "String_Node_Str");
      singleWriter.println("String_Node_Str" + singleMarginalOutputFile + "String_Node_Str");
      singleWriter.close();
      String cmd="String_Node_Str" + gnuplotFile;
      Process p=Runtime.getRuntime().exec(cmd);
      p.waitFor();
    }
    writer.close();
    log.info("String_Node_Str" + allSingleMarginalsOutputFile);
    log.info("String_Node_Str");
    String texFile=outputDir + "String_Node_Str";
    writer=null;
    try {
      writer=new PrintWriter(texFile,"String_Node_Str");
    }
 catch (    Exception e) {
      e.printStackTrace();
    }
    writer.println("String_Node_Str");
    writer.println("String_Node_Str");
    writer.println("String_Node_Str");
    writer.println("String_Node_Str");
    writer.println("String_Node_Str");
    writer.println("String_Node_Str");
    writer.println("String_Node_Str");
    writer.println("String_Node_Str");
    writer.println("String_Node_Str");
    writer.println("String_Node_Str");
    int count=0;
    for (    String parameterName : paramNamesOrderByMarginalVarianceExplained) {
      String parameterFileName=parameterName.replace('/','_');
      int indexOfParameter=configSpace.getParameterNamesInAuthorativeOrder().indexOf(parameterName);
      HashSet<Integer> set=new HashSet<Integer>();
      set.add(indexOfParameter);
      double fractionExplainedByThisMarginal=totalFractionsExplained.get(set);
      writer.println("String_Node_Str");
      writer.println("String_Node_Str");
      String singleMarginalOutputFile=outputDir + "String_Node_Str" + parameterFileName+ "String_Node_Str";
      writer.println("String_Node_Str" + singleMarginalOutputFile + "String_Node_Str");
      writer.println("String_Node_Str" + parameterName.replace("String_Node_Str","String_Node_Str") + "String_Node_Str"+ decim2.format(fractionExplainedByThisMarginal)+ "String_Node_Str"+ parameterName+ "String_Node_Str");
      writer.println("String_Node_Str");
      writer.println("String_Node_Str");
      if (count++ % 4 == 0)       writer.println("String_Node_Str");
    }
    writer.println("String_Node_Str");
    writer.close();
    String cmd="String_Node_Str" + texFile + "String_Node_Str";
    log.info("String_Node_Str" + cmd);
  }
  log.info("String_Node_Str");
}

Fixed version (ground truth):
public static void decomposeVariance(RandomForest existingForest,List<AlgorithmRun> testRuns,ParamConfigurationSpace configSpace,Random rand,boolean compareToDef,double quantileToCompareTo,boolean computePairwiseInteraction,String outputDir,boolean logModel,boolean plotMarginals) throws IOException, InterruptedException {
  RandomForest forest=ModelEvaluation.extractMarginalForest(existingForest,testRuns,configSpace,rand,compareToDef,quantileToCompareTo);
  RandomForestPreprocessor.preprocessRandomForest(forest,configSpace);
  DecimalFormat decim=new DecimalFormat("String_Node_Str");
  DecimalFormat decim2=new DecimalFormat("String_Node_Str");
  String s;
  double timeForComputingMainEffects=0;
  double timeForComputingBinaryEffects=0;
  HashMap<HashSet<Integer>,Double> totalFractionsExplained=new HashMap<HashSet<Integer>,Double>();
  double sumOfFractionsOfBinaries=0;
  int numDim=configSpace.getCategoricalSize().length;
  double[][] allObservations=new double[numDim][];
  double[][] allIntervalSizes=new double[numDim][];
  for (int numTree=0; numTree < forest.Trees.length; numTree++) {
    HashSet<Integer> allVariableIndices=new HashSet<Integer>();
    for (int j=0; j < configSpace.getCategoricalSize().length; j++) {
      allVariableIndices.add(new Integer(j));
    }
    double thisTreeTotalVariance=RandomForestPreprocessor.computeTotalVarianceOfRegressionTree(forest.Trees[numTree],configSpace);
    if (thisTreeTotalVariance == 0.0) {
      s="String_Node_Str" + numTree + "String_Node_Str";
      log.info(s);
      continue;
    }
    s="String_Node_Str" + numTree + "String_Node_Str"+ thisTreeTotalVariance;
    log.info(s);
    double thisTreeFractionOfVarianceExplainedByMarginals=0;
    HashMap<HashSet<Integer>,Double> thisTreeVarianceContributions=new HashMap<HashSet<Integer>,Double>();
    HashMap<Integer,Double> singleVarianceContributions=new HashMap<Integer,Double>();
    double marg;
    long start=System.nanoTime();
    for (int dim=0; dim < numDim; dim++) {
      int numVals=configSpace.getCategoricalSize()[dim];
      if (numVals > 0) {
        allObservations[dim]=new double[numVals];
        allIntervalSizes[dim]=new double[numVals];
        for (int valIndex=0; valIndex < numVals; valIndex++) {
          allObservations[dim][valIndex]=valIndex;
          allIntervalSizes[dim][valIndex]=1.0 / numVals;
        }
      }
 else {
        List<Double> splitPoints=new ArrayList<Double>();
        for (int node_index=0; node_index < forest.Trees[numTree].var.length; node_index++) {
          if (forest.Trees[numTree].var[node_index] == dim + 1) {
            splitPoints.add(forest.Trees[numTree].cut[node_index]);
          }
        }
        splitPoints.add(0.0);
        splitPoints.add(1.0);
        Collections.sort(splitPoints);
        allObservations[dim]=new double[splitPoints.size() - 1];
        allIntervalSizes[dim]=new double[splitPoints.size() - 1];
        for (int lowerIntervalId=0; lowerIntervalId < splitPoints.size() - 1; lowerIntervalId++) {
          allObservations[dim][lowerIntervalId]=(splitPoints.get(lowerIntervalId) + splitPoints.get(lowerIntervalId + 1)) / 2;
          allIntervalSizes[dim][lowerIntervalId]=splitPoints.get(lowerIntervalId + 1) - splitPoints.get(lowerIntervalId);
        }
      }
    }
    for (int dim=0; dim < numDim; dim++) {
      int[] indicesOfObservations=new int[1];
      indicesOfObservations[0]=dim;
      ArrayList<Double> as=new ArrayList<Double>();
      double weightedSum=0, weightedSumOfSquares=0;
      for (int valIndex=0; valIndex < allObservations[dim].length; valIndex++) {
        double[] observations=new double[1];
        observations[0]=allObservations[dim][valIndex];
        log.debug("String_Node_Str" + numTree + "String_Node_Str"+ dim+ "String_Node_Str"+ observations[0]);
        marg=forest.Trees[numTree].marginalPerformance(indicesOfObservations,observations);
        log.debug("String_Node_Str" + numTree + "String_Node_Str"+ dim+ "String_Node_Str"+ marg);
        as.add(marg);
        double intervalSize=allIntervalSizes[dim][valIndex];
        weightedSum+=marg * intervalSize;
        weightedSumOfSquares+=marg * marg * intervalSize;
      }
      double thisMarginalVarianceContribution=weightedSumOfSquares - weightedSum * weightedSum;
      log.debug("String_Node_Str" + numTree + "String_Node_Str"+ thisMarginalVarianceContribution);
      double thisMarginalFractionOfVarianceExplained=thisMarginalVarianceContribution / thisTreeTotalVariance * 100;
      if (Double.isNaN(thisMarginalFractionOfVarianceExplained)) {
        throw new RuntimeException("String_Node_Str");
      }
      thisTreeFractionOfVarianceExplainedByMarginals+=thisMarginalFractionOfVarianceExplained;
      s="String_Node_Str" + numTree + "String_Node_Str"+ decim.format(thisMarginalFractionOfVarianceExplained)+ "String_Node_Str"+ configSpace.getParameterNames().get(dim);
      log.info(s);
      HashSet<Integer> set=new HashSet<Integer>();
      set.add(dim);
      thisTreeVarianceContributions.put(set,thisMarginalVarianceContribution);
      singleVarianceContributions.put(dim,thisMarginalVarianceContribution);
    }
    double thisTreeTimeForComputingMainEffects=(System.nanoTime() - start) * 1.0e-9;
    timeForComputingMainEffects+=thisTreeTimeForComputingMainEffects;
    s="String_Node_Str" + numTree + "String_Node_Str"+ "String_Node_Str"+ thisTreeFractionOfVarianceExplainedByMarginals+ "String_Node_Str"+ thisTreeTimeForComputingMainEffects+ "String_Node_Str";
    log.info(s);
    double thisTreeFractionOfVarianceExplainedByBinaries=0;
    double thisTreeTimeForComputingBinaryEffects=0;
    if (computePairwiseInteraction) {
      for (int dim1=0; dim1 < numDim; dim1++) {
        for (int dim2=dim1 + 1; dim2 < numDim; dim2++) {
          int[] indicesOfObservations=new int[2];
          indicesOfObservations[0]=dim1;
          ArrayList<Double> as=new ArrayList<Double>();
          indicesOfObservations[1]=dim2;
          double weightedSum=0, weightedSumOfSquares=0;
          for (int valIndex1=0; valIndex1 < allObservations[dim1].length; valIndex1++) {
            for (int valIndex2=0; valIndex2 < allObservations[dim2].length; valIndex2++) {
              double[] observations=new double[2];
              observations[0]=allObservations[dim1][valIndex1];
              observations[1]=allObservations[dim2][valIndex2];
              double intervalSize1=allIntervalSizes[dim1][valIndex1];
              double intervalSize2=allIntervalSizes[dim2][valIndex2];
              marg=forest.Trees[numTree].marginalPerformance(indicesOfObservations,observations);
              weightedSum+=marg * intervalSize1 * intervalSize2;
              weightedSumOfSquares+=marg * marg * intervalSize1* intervalSize2;
              s="String_Node_Str" + configSpace.getParameterNames().get(dim1) + "String_Node_Str"+ observations[0]+ "String_Node_Str"+ configSpace.getParameterNames().get(dim2)+ "String_Node_Str"+ observations[1]+ "String_Node_Str"+ marg;
              as.add(marg);
            }
          }
          double thisBinaryVarianceContribution=weightedSumOfSquares - weightedSum * weightedSum;
          thisBinaryVarianceContribution-=singleVarianceContributions.get(dim1);
          thisBinaryVarianceContribution-=singleVarianceContributions.get(dim2);
          log.debug("String_Node_Str" + dim1 + "String_Node_Str"+ singleVarianceContributions.get(dim1));
          log.debug("String_Node_Str" + dim2 + "String_Node_Str"+ singleVarianceContributions.get(dim2));
          double thisBinaryFractionOfVarianceExplained=thisBinaryVarianceContribution / thisTreeTotalVariance * 100;
          thisTreeFractionOfVarianceExplainedByBinaries+=thisBinaryFractionOfVarianceExplained;
          s=decim.format(thisBinaryFractionOfVarianceExplained) + "String_Node_Str" + configSpace.getParameterNames().get(dim1)+ "String_Node_Str"+ configSpace.getParameterNames().get(dim2);
          log.debug(s);
          HashSet<Integer> set=new HashSet<Integer>();
          set.add(dim1);
          set.add(dim2);
          thisTreeVarianceContributions.put(set,thisBinaryVarianceContribution);
        }
      }
      thisTreeTimeForComputingBinaryEffects=(System.nanoTime() - start) * 1.0e-9 - thisTreeTimeForComputingMainEffects;
      timeForComputingBinaryEffects+=thisTreeTimeForComputingBinaryEffects;
      s="String_Node_Str" + numTree + "String_Node_Str"+ "String_Node_Str"+ thisTreeFractionOfVarianceExplainedByBinaries+ "String_Node_Str"+ thisTreeTimeForComputingBinaryEffects+ "String_Node_Str";
      log.info(s);
    }
    double tmpThisTreeFractionExplained=0;
    for (    HashSet<Integer> indexSet : thisTreeVarianceContributions.keySet()) {
      double previousFractionExplained=0;
      if (numTree > 0) {
        previousFractionExplained=totalFractionsExplained.get(indexSet);
      }
      double thisFractionExplained=thisTreeVarianceContributions.get(indexSet) / thisTreeTotalVariance * 100;
      log.debug("String_Node_Str" + indexSet.toString() + "String_Node_Str"+ numTree+ "String_Node_Str"+ thisTreeVarianceContributions.get(indexSet));
      log.debug("String_Node_Str" + numTree + "String_Node_Str"+ thisTreeTotalVariance);
      tmpThisTreeFractionExplained+=thisFractionExplained;
      totalFractionsExplained.put(indexSet,previousFractionExplained + 1.0 / forest.Trees.length * thisFractionExplained);
      log.debug("String_Node_Str" + numTree + "String_Node_Str"+ totalFractionsExplained.get(indexSet));
    }
    log.debug(tmpThisTreeFractionExplained + "String_Node_Str");
  }
  double tmpFractionExplained=0;
  for (  HashSet<Integer> indexSet : totalFractionsExplained.keySet()) {
    tmpFractionExplained+=totalFractionsExplained.get(indexSet);
  }
  log.debug(tmpFractionExplained + "String_Node_Str");
  double sumOfFractionsOfMarginals=0;
  for (  HashSet<Integer> indexSet : totalFractionsExplained.keySet()) {
    if (indexSet.size() == 1) {
      sumOfFractionsOfMarginals+=totalFractionsExplained.get(indexSet);
    }
  }
  s="String_Node_Str" + sumOfFractionsOfMarginals + "String_Node_Str";
  log.info(s);
  if (computePairwiseInteraction) {
    sumOfFractionsOfBinaries=0;
    for (    HashSet<Integer> indexSet : totalFractionsExplained.keySet()) {
      if (indexSet.size() == 2) {
        sumOfFractionsOfBinaries+=totalFractionsExplained.get(indexSet);
      }
    }
    s="String_Node_Str" + sumOfFractionsOfBinaries + "String_Node_Str";
    log.info(s);
  }
  s="String_Node_Str" + decim.format(sumOfFractionsOfMarginals) + "String_Node_Str"+ decim.format(timeForComputingMainEffects)+ "String_Node_Str"+ decim.format(sumOfFractionsOfBinaries)+ "String_Node_Str"+ decim.format(timeForComputingBinaryEffects)+ "String_Node_Str";
  log.info(s);
  ArrayList<String> paramNamesOrderByMarginalVarianceExplained=new ArrayList<String>();
  int idx=0;
  ArrayList<Map.Entry<HashSet,Double>> list=sortedKeysByValue(totalFractionsExplained);
  int numMaxEffectsToPrint=30;
  s="String_Node_Str" + numMaxEffectsToPrint + "String_Node_Str";
  log.info(s);
  for (  Map.Entry<HashSet,Double> entry : list) {
    HashSet<Integer> set=entry.getKey();
    numMaxEffectsToPrint--;
    if (set.size() == 1) {
      Integer varIndex=(Integer)set.toArray()[0];
      String parameterName=configSpace.getParameterNames().get(varIndex);
      paramNamesOrderByMarginalVarianceExplained.add(parameterName);
      if (numMaxEffectsToPrint > 0) {
        s=decim2.format(entry.getValue()) + "String_Node_Str" + parameterName;
        log.info(s);
      }
    }
 else     if (set.size() == 2) {
      Integer varIndex1=(Integer)set.toArray()[0];
      Integer varIndex2=(Integer)set.toArray()[1];
      String varName1=configSpace.getParameterNames().get(varIndex1);
      String varName2=configSpace.getParameterNames().get(varIndex2);
      if (numMaxEffectsToPrint > 0) {
        s=decim2.format(entry.getValue()) + "String_Node_Str" + varName1+ "String_Node_Str"+ varName2;
        log.info(s);
      }
    }
  }
  String allSingleMarginalsOutputFile=outputDir + "String_Node_Str";
  PrintWriter writer=null;
  try {
    writer=new PrintWriter(allSingleMarginalsOutputFile,"String_Node_Str");
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
  if (plotMarginals) {
    log.info("String_Node_Str");
    for (int dim=0; dim < numDim; dim++) {
      String parameterName=configSpace.getParameterNames().get(dim);
      String parameterFileName=parameterName.replace('/','_');
      double[] valuesToPredictFor;
      if (configSpace.getCategoricalSize()[dim] > 0) {
        valuesToPredictFor=allObservations[dim];
      }
 else {
        int numVals=11;
        valuesToPredictFor=new double[numVals];
        for (int valIndex=0; valIndex < numVals; valIndex++) {
          valuesToPredictFor[valIndex]=(valIndex + 0.0) / (numVals - 1);
        }
      }
      String singleMarginalOutputFile=outputDir + "String_Node_Str" + parameterFileName+ "String_Node_Str";
      PrintWriter singleWriter=null;
      try {
        singleWriter=new PrintWriter(singleMarginalOutputFile,"String_Node_Str");
      }
 catch (      Exception e) {
        e.printStackTrace();
      }
      int[] indicesOfObservations=new int[1];
      indicesOfObservations[0]=dim;
      for (int valIndex=0; valIndex < valuesToPredictFor.length; valIndex++) {
        double[] observations=new double[1];
        observations[0]=valuesToPredictFor[valIndex];
        ArrayList<Double> margs=new ArrayList<Double>();
        for (int numTree=0; numTree < forest.Trees.length; numTree++) {
          margs.add(forest.Trees[numTree].marginalPerformance(indicesOfObservations,observations));
        }
        double avg=0;
        for (        Double marg : margs) {
          avg+=marg / margs.size();
        }
        double std=0;
        for (        Double marg : margs) {
          std+=Math.pow(marg - avg,2) / margs.size();
        }
        std=Math.sqrt(std);
        if (configSpace.getCategoricalSize()[dim] > 0) {
          writer.println(configSpace.getValuesMap().get(parameterName).get(valIndex) + "String_Node_Str" + avg+ "String_Node_Str"+ std);
          singleWriter.println(valIndex + "String_Node_Str" + configSpace.getValuesMap().get(parameterName).get(valIndex)+ "String_Node_Str"+ avg+ "String_Node_Str"+ std);
        }
 else {
          writer.println(valuesToPredictFor[valIndex] + "String_Node_Str" + avg+ "String_Node_Str"+ std);
          Map<String,NormalizedRange> normalizeRangeMap=configSpace.getNormalizedRangeMap();
          NormalizedRange normalizedRange=normalizeRangeMap.get(parameterName);
          singleWriter.println(valIndex + "String_Node_Str" + normalizedRange.unnormalizeValue(valuesToPredictFor[valIndex])+ "String_Node_Str"+ avg+ "String_Node_Str"+ std);
        }
      }
      writer.println();
      singleWriter.close();
      String gnuplotFile=outputDir + "String_Node_Str" + parameterFileName+ "String_Node_Str";
      singleWriter=null;
      try {
        singleWriter=new PrintWriter(gnuplotFile,"String_Node_Str");
      }
 catch (      Exception e) {
        e.printStackTrace();
      }
      singleWriter.println("String_Node_Str");
      singleWriter.println("String_Node_Str");
      String pdfFilename=outputDir + "String_Node_Str" + parameterFileName+ "String_Node_Str";
      singleWriter.println("String_Node_Str" + pdfFilename + "String_Node_Str");
      singleWriter.println("String_Node_Str");
      singleWriter.println("String_Node_Str");
      singleWriter.println("String_Node_Str" + singleMarginalOutputFile + "String_Node_Str");
      singleWriter.println("String_Node_Str" + singleMarginalOutputFile + "String_Node_Str");
      singleWriter.close();
      String cmd="String_Node_Str" + gnuplotFile;
      Process p=Runtime.getRuntime().exec(cmd);
      p.waitFor();
    }
    writer.close();
    log.info("String_Node_Str" + allSingleMarginalsOutputFile);
    log.info("String_Node_Str");
    String texFile=outputDir + "String_Node_Str";
    writer=null;
    try {
      writer=new PrintWriter(texFile,"String_Node_Str");
    }
 catch (    Exception e) {
      e.printStackTrace();
    }
    writer.println("String_Node_Str");
    writer.println("String_Node_Str");
    writer.println("String_Node_Str");
    writer.println("String_Node_Str");
    writer.println("String_Node_Str");
    writer.println("String_Node_Str");
    writer.println("String_Node_Str");
    writer.println("String_Node_Str");
    writer.println("String_Node_Str");
    writer.println("String_Node_Str");
    int count=0;
    for (    String parameterName : paramNamesOrderByMarginalVarianceExplained) {
      String parameterFileName=parameterName.replace('/','_');
      int indexOfParameter=configSpace.getParameterNamesInAuthorativeOrder().indexOf(parameterName);
      HashSet<Integer> set=new HashSet<Integer>();
      set.add(indexOfParameter);
      double fractionExplainedByThisMarginal=totalFractionsExplained.get(set);
      writer.println("String_Node_Str");
      writer.println("String_Node_Str");
      String singleMarginalOutputFile=outputDir + "String_Node_Str" + parameterFileName+ "String_Node_Str";
      writer.println("String_Node_Str" + singleMarginalOutputFile + "String_Node_Str");
      writer.println("String_Node_Str" + parameterName.replace("String_Node_Str","String_Node_Str") + "String_Node_Str"+ decim2.format(fractionExplainedByThisMarginal)+ "String_Node_Str"+ parameterName+ "String_Node_Str");
      writer.println("String_Node_Str");
      writer.println("String_Node_Str");
      if (count++ % 4 == 0)       writer.println("String_Node_Str");
    }
    writer.println("String_Node_Str");
    writer.close();
    String cmd="String_Node_Str" + texFile + "String_Node_Str";
    log.info("String_Node_Str" + cmd);
  }
  log.info("String_Node_Str");
}