public static <T extends Serializable> Fuzzy<T> uniform(T value) { return new Fuzzy<T>(new Serializable[] {value}, new BigDecimal[] { new BigDecimal(1.0)}); }
@Override public String convertToString(Fuzzy<T> value) { if (value == null) return "null"; else return value.toString(); }
public void testCorrectPercentage() { final String valueDistribution = "11%: 10, 20%: 100, 40.5%: 1000, 20%: 10000, 8.5%: 100000"; Fuzzy<Integer> fuzzy = new Fuzzy.IntegerConverter().convert(valueDistribution, Integer.class); Map<Integer, BigDecimal> expected = new HashMap<>(); expected.put(10, BigDecimal.valueOf(0.11)); expected.put(100, BigDecimal.valueOf(0.31)); expected.put(1000, BigDecimal.valueOf(0.715)); expected.put(10000, BigDecimal.valueOf(0.915)); expected.put(100000, BigDecimal.valueOf(1)); assertEquals(fuzzy.getProbabilityMap(), expected); }
public void testWeights() { final String valueDistribution = "2: 10, 3: 100"; //2 to 3 ratio (= 40 to 60 %) Fuzzy<Integer> fuzzy = new Fuzzy.IntegerConverter().convert(valueDistribution, Integer.class); Map<Integer, BigDecimal> expected = new HashMap<>(); expected.put(10, BigDecimal.valueOf(0.4)); expected.put(100, BigDecimal.valueOf(1)); assertEquals(fuzzy.getProbabilityMap(), expected); }
public void testCombinedPercentageAndWeights() { //50% taken by percentages and the rest is split 2/3 final String valueDistribution = "10%: 10, 20%: 100, 20%: 1000, 2: 10000, 3: 100000"; Fuzzy<Integer> fuzzy = new Fuzzy.IntegerConverter().convert(valueDistribution, Integer.class); Map<Integer, BigDecimal> expected = new HashMap<>(); expected.put(10, BigDecimal.valueOf(0.1)); expected.put(100, BigDecimal.valueOf(0.3)); expected.put(1000, BigDecimal.valueOf(0.5)); expected.put(10000, BigDecimal.valueOf(0.7)); expected.put(100000, BigDecimal.valueOf(1)); assertEquals(fuzzy.getProbabilityMap(), expected); } }
values.addAll(fixedValues); values.addAll(weightedValues); return new Fuzzy<T>(values.toArray(new Serializable[values.size()]), cumulativeProbability);