private static double getConditionedEntropy(double[] val) {
        double gain = 0.0;
        int caseCount = val.length;
        Map<Double, Integer> cases = new TreeMap<Double, Integer>();

        for (int i = 0; i < val.length; i++) {
            if (!cases.containsKey(val[i])) {
                cases.put(val[i], 0);
            }
            cases.put(val[i], cases.get(val[i]) + 1);
        }
        
        Iterator it = cases.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry pairs = (Map.Entry) it.next();
            int value = Integer.parseInt(pairs.getValue().toString());
            double devider = (double) value / caseCount; //Math.abs((double) value) / Math.abs((double) caseCount);//Math.abs((double) value) / Math.abs((double) caseCount);
            double casesValue = Math.log(devider);
            System.out.printf("%d %5.2f %5.2f\n", value, devider, casesValue);
            gain += devider * casesValue;
            it.remove();
        }

        return (gain * -1) / Math.log(2.0);
    }