if (m_BestValue > MIN_VALUE) { m_BestThreshold = -Double.MAX_VALUE; } else { m_BestValue = MIN_VALUE; m_BestThreshold = 0.5; }
  protected void findThreshold() throws Exception {    double[] probabilities = collectProbabilities();    int[] sortedIndices = Utils.sortUnsafe(probabilities);    double[][] confusionMatrix = new double[2][2];    m_BestThreshold = -Double.MAX_VALUE;    for (int i = 0; i < sortedIndices.length; i++) {      Instance inst = m_EvalData.instance(sortedIndices[i]);      if ((int) inst.classValue() == m_DesignatedClass) {	confusionMatrix[0][0] += inst.weight();      } else {	confusionMatrix[1][0] += inst.weight();      }    }    m_BestValue = computeValue(confusionMatrix);    for (int i = 0; i < sortedIndices.length; i++) {      Instance inst = m_EvalData.instance(sortedIndices[i]);      if ((int) inst.classValue() == m_DesignatedClass) {	confusionMatrix[0][0] -= inst.weight();	confusionMatrix[0][1] += inst.weight();      } else {	confusionMatrix[1][0] -= inst.weight();	confusionMatrix[1][1] += inst.weight();      }      if (m_Debug) {	for (int j = 0; j < confusionMatrix.length; j++) {	  for (int k = 0; k < confusionMatrix[j].length; k++) 	    System.err.print(confusionMatrix[j][k] + " ");	  System.err.println();	}	System.err.println();      }      if ((i + 1) == sortedIndices.length) {	double curr = computeValue(confusionMatrix);	if (m_Debug) {	  System.err.println(probabilities[sortedIndices[i]] + " " + curr);	}	if (curr > m_BestValue) {	  m_BestValue = curr;	  m_BestThreshold = probabilities[sortedIndices[i]];	}      } else {	double prob1 = probabilities[sortedIndices[i]];	double prob2 = probabilities[sortedIndices[i + 1]];	if (prob2 > prob1) {	  double curr = computeValue(confusionMatrix);	  if (m_Debug) {	    System.err.println(prob1 + " " + curr);	  }	  if (curr > m_BestValue) {	    m_BestValue = curr;	    m_BestThreshold = prob1;	  }	}      }    }  }