|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
E - the type of elements maintained by this weighted mappublic interface WeightedMap<E>
A map of elements to weights with sampling and ranking functionality.
WeightedMap<String> m = new HashWeightedMap<String>();
m.put("foo", 100.0d);
m.put("bar", 500.0d);
m.put("baz", 1000.0d);
assert(m.get("foo") == 100.0d);
assert(m.weight("foo") == 100.0d);
assert(m.totalWeight() == 1600.0d);
assert(m.normalizedWeight("foo") == 0.0625d);
assert(m.rank("baz") == 1);
assert(m.rank("bar") == 2);
assert(m.rank("foo") == 3);
List<String> list = new ArrayList<String>(100);
for (int i = 0; i < 100; i++) {
list.add(m.sample());
}
assert(cardinality in list of "foo" approximately equal to 6.25)
assert(cardinality in list of "bar" approximately equal to 31.25)
assert(cardinality in list of "baz" approximately equal to 62.5)
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface java.util.Map |
|---|
Map.Entry<K,V> |
| Method Summary | |
|---|---|
int |
maximumRank()
Return the maximum rank in this weighted map. |
Double |
normalizedWeight(E e)
Return the normalized weight for the specified element in this weighted map. |
int |
rank(E e)
Return an integer rank for the specified element in this weighted map based on its weight. |
E |
sample()
Randomly sample an element from this weighted map according to its normalized weight. |
Double |
totalWeight()
Return the sum of the weights in this weighted map. |
Double |
weight(E e)
Return the weight for the specified element in this weighted map. |
| Methods inherited from interface java.util.Map |
|---|
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, values |
| Method Detail |
|---|
E sample()
null if this weighted
map is empty or if the total weight is zerototalWeight(),
normalizedWeight(E)Double weight(E e)
get(E e).
e - element
null if this weighted map is emptyDouble normalizedWeight(E e)
e - element
null if this weighted map is emptyDouble totalWeight()
int rank(E e)
e - element
-1 if this
weighted map is empty or if e is not an element
in this weighted mapint maximumRank()
-1 if this weighted map is empty
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||