private static double dichotomyComputeBestThreshold(ArrayList<Double> leftClass, ArrayList<Double> rightClass, double lowerBound, double upperBound)
	{
		//System.out.println("=== Compute Optimal Threshold ===");
		ArrayList<Double> leftClassBadPlaced = new ArrayList<Double>();
		ArrayList<Double> rightClassBadPlaced = new ArrayList<Double>();
		int numberOfSamples = leftClass.size() + rightClass.size();
		double lb = lowerBound;
		double ub = upperBound;
		double threshold = 0;

		int i = 0;
		while (ub - lb > 0.0001)
		{
			leftClassBadPlaced.clear();
			rightClassBadPlaced.clear();

			// Compute threshold
			threshold = lb + (ub - lb) / 2.0;
			//System.out.print("[" + i + "] : threshold = " + threshold);

			// Count well placed and bad placed samples
			int wellPlaced = 0;
			for (Double v : leftClass) {
				if (v > threshold)
					leftClassBadPlaced.add(v);
				else wellPlaced++;
			}
			for (Double v : rightClass) {
				if (v < threshold)
					rightClassBadPlaced.add(v);
				else wellPlaced++;
			}

			double wellPlacedPercent = 100.0 * wellPlaced / numberOfSamples;
			//System.out.print(", Well placed = " + wellPlacedPercent + "%");
			//System.out.println();

			// We can't find better
			if (leftClassBadPlaced.size() == rightClassBadPlaced.size()) {
				break;
			}

			// Prepare next step
			if (leftClassBadPlaced.size() > rightClassBadPlaced.size())
				lb = threshold;
			else
				ub = threshold;
			i++;
		}

		//System.out.println("=================================");
		return threshold;
	}