@@ -0,0 +1,1130 @@
+package jeranvier.math.stats;%0A%0Aimport java.util.Map;%0Aimport java.util.TreeMap;%0A%0A/** Represent a probabilistic distribution of items of type T%0A * @param %3CT%3E%0A * %0A */%0A%0Apublic class Distribution%3CT extends Comparable%3CT%3E%3E extends TreeMap%3CT, Double%3E%7B%0A%09private static final long serialVersionUID = 8978630696165523413L;%0A%09private int samplesCounter;%0A%09%0A%09public Distribution(T%5B%5D samples) %7B%0A%09%09samplesCounter = 0;%0A%09%09for(T sample : samples)%7B%0A%09%09%09addSample(sample);%0A%09%09%7D%0A%09%7D%0A%0A%09public void addSample(T sample) %7B%0A%09%09this.put(sample, containsKey(sample) ? get(sample)+1 : 1);%0A%09%09samplesCounter++;%0A%09%7D%0A%09%0A%09public double getProbability(T instance)%7B%0A%09%09return get(instance)/samplesCounter;%0A%09%7D%0A%09%0A%09@Override%0A%09public String toString()%7B%0A%09%09StringBuilder sb = new StringBuilder();%0A%09%09for( Map.Entry%3CT, Double%3E entry : entrySet())%7B%0A%09%09%09sb.append(entry.getKey() + %22: %22 + getProbability(entry.getKey()) +%22%5Cn%22);%0A%09%09%7D%0A%09%09return sb.toString();%0A%09%7D%0A%0A%09public static void main(String%5B%5D args)%7B%0A%09%09Integer%5B%5D integers = new Integer%5B%5D%7B1, 2, 3, 1 ,2, 1, 1, 1, 2, 3, 4, 1%7D;%0A%09%09Distribution%3CInteger%3E distrib = new Distribution%3C%3E(integers);%0A%09%09System.out.println(distrib.toString());%0A%09%7D%0A%0A%7D%0A

update on distribution definition