public class WeightedSet extends AbstractSet implements Serializable
Inspred by the BioJava Distribution objects the WeightedSet is a map from a Key to a Weight. Unlike Distributions the Keys do not have to be Symbols. In the GA package the WeightedMap is useful for sampling Organisms according to their fitness.
When Symbols are added or their weights are set then the weights are internally normalized to 1
| Constructor and Description |
|---|
WeightedSet() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(Object o)
Adds a new
Object with a weight of zero. |
boolean |
addAll(Collection c) |
Map |
asMap()
Converts the Set to a map from key
Objects to Double
weights. |
void |
clear() |
boolean |
contains(Object o) |
boolean |
containsAll(Collection c) |
protected double |
getTotalWeight()
The total weight that has been added to this Set.
|
double |
getWeight(Object o)
Determines the normalized weight for
o |
boolean |
isEmpty() |
Iterator |
iterator()
Returns an unmodifiable iterator over the keys of the set.
|
boolean |
remove(Object o) |
boolean |
retainAll(Collection c) |
Object |
sample()
Randomly samples an
Object from the Set according
to its weight. |
void |
setWeight(Object o,
double w)
Sets the weight of an
Object. |
int |
size() |
Object[] |
toArray() |
equals, hashCode, removeAlltoArray, toStringclone, finalize, getClass, notify, notifyAll, wait, wait, waitspliterator, toArrayparallelStream, removeIf, streampublic WeightedSet()
public Map asMap()
Objects to Double
weights.public Object sample()
Object from the Set according
to its weight.public double getWeight(Object o) throws NoSuchElementException
oo - the Object you want to know the weight ofNoSuchElementException - if o is not found in this setprotected double getTotalWeight()
public void setWeight(Object o, double w)
Object. If the Object is
not in this Set then it is added.o - the Objectw - the weight.IllegalArgumentException - if w is < 0.0public boolean contains(Object o)
contains in interface Collectioncontains in interface Setcontains in class AbstractCollectionpublic boolean remove(Object o)
remove in interface Collectionremove in interface Setremove in class AbstractCollectionpublic boolean isEmpty()
isEmpty in interface CollectionisEmpty in interface SetisEmpty in class AbstractCollectionpublic boolean retainAll(Collection c)
retainAll in interface CollectionretainAll in interface SetretainAll in class AbstractCollectionpublic boolean add(Object o)
Object with a weight of zero. Equivalent to
setWeight(o, 0.0);add in interface Collectionadd in interface Setadd in class AbstractCollectiono - the object to add.public int size()
size in interface Collectionsize in interface Setsize in class AbstractCollectionpublic boolean containsAll(Collection c)
containsAll in interface CollectioncontainsAll in interface SetcontainsAll in class AbstractCollectionpublic Object[] toArray()
toArray in interface CollectiontoArray in interface SettoArray in class AbstractCollectionpublic void clear()
clear in interface Collectionclear in interface Setclear in class AbstractCollectionpublic Iterator iterator()
iterator in interface Iterableiterator in interface Collectioniterator in interface Setiterator in class AbstractCollectionpublic boolean addAll(Collection c)
addAll in interface CollectionaddAll in interface SetaddAll in class AbstractCollectionCopyright © 2020 BioJava. All rights reserved.