private Map<T, Double> normalize() { if (isNormalised) return normalised; Map<T, Double> temp = createMapDataStructure(); double sum = 0; for (Entry<T, Double> entry : map.entrySet()) { Double p = entry.getValue(); if (p != null) { sum += p; } } for (Entry<T, Double> entry : temp.entrySet()) { T t = entry.getKey(); Double p = entry.getValue(); if (p != null) { temp.put(t, p / sum); } } normalised = temp; isNormalised = true; return temp; }
private Map<T, Double> normalize() { if (isNormalised) return normalised; Map<T, Double> temp = createMapDataStructure(); double sum = 0; for (Entry<T, Double> entry : map.entrySet()) { Double p = entry.getValue(); if (p != null) { sum += p; } } for (Entry<T, Double> entry : temp.entrySet()) { T t = entry.getKey(); Double p = entry.getValue(); if (p != null) { temp.put(t, p / sum); } } normalised = temp; isNormalised = true; return temp; }
private Map<T, Double> normalize() { if (isNormalised) return normalised; Map<T, Double> temp = createMapDataStructure(); double sum = 0; for (Entry<T, Double> entry : map.entrySet()) { Double p = entry.getValue(); if (p != null) { sum += p; } } for (Entry<T, Double> entry : temp.entrySet()) { T t = entry.getKey(); Double p = entry.getValue(); if (p != null) { temp.put(t, p / sum); } } normalised = temp; isNormalised = true; return temp; }