Package org.nd4j.common.primitives
Class Counter<T>
- java.lang.Object
-
- org.nd4j.common.primitives.Counter<T>
-
- All Implemented Interfaces:
Serializable
public class Counter<T> extends Object implements Serializable
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classCounter.PairComparatorclassCounter.ReversedPairComparator
-
Field Summary
Fields Modifier and Type Field Description protected AtomicBooleandirtyprotected ConcurrentHashMap<T,AtomicDouble>mapprotected AtomicDoubletotalCount
-
Constructor Summary
Constructors Constructor Description Counter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TargMax()This method returns element with highest counter valuePriorityQueue<Pair<T,Double>>asPriorityQueue()PriorityQueue<Pair<T,Double>>asReversedPriorityQueue()voidclear()This method effectively resets counter to empty statebooleancontainsElement(T element)This method checks, if element exist in this countervoiddropElementsBelowThreshold(double threshold)This method will remove all elements with counts below given threshold from counterSet<Map.Entry<T,AtomicDouble>>entrySet()This method returns Setof this counter booleanequals(Object o)doublegetCount(T element)doublegetProbability(T element)This method returns probability of given elementinthashCode()voidincrementAll(Collection<T> elements, double inc)This method will increment all elements in collection<T2 extends T>
voidincrementAll(Counter<T2> other)This method will increment counts of this counter by counts from other countervoidincrementCount(T element, double inc)booleanisEmpty()This method returns TRUE if counter has no elements, FALSE otherwisevoidkeepTopNElements(int N)This method removes all elements except of top N by counter valuesSet<T>keySet()This method returns Set of elements used in this counterList<T>keySetSorted()This method returns List of elements, sorted by their countsvoidnormalize()This method will apply normalization to counter values and totals.protected voidrebuildTotals()doubleremoveKey(T element)This method removes given key from counterdoublesetCount(T element, double count)This method sets new counter value for given elementintsize()Returns total number of tracked elementsdoubletotalCount()This method returns total sum of counter values
-
-
-
Field Detail
-
map
protected ConcurrentHashMap<T,AtomicDouble> map
-
totalCount
protected AtomicDouble totalCount
-
dirty
protected AtomicBoolean dirty
-
-
Method Detail
-
getCount
public double getCount(T element)
-
incrementCount
public void incrementCount(T element, double inc)
-
incrementAll
public void incrementAll(Collection<T> elements, double inc)
This method will increment all elements in collection- Parameters:
elements-inc-
-
incrementAll
public <T2 extends T> void incrementAll(Counter<T2> other)
This method will increment counts of this counter by counts from other counter- Parameters:
other-
-
getProbability
public double getProbability(T element)
This method returns probability of given element- Parameters:
element-- Returns:
-
setCount
public double setCount(T element, double count)
This method sets new counter value for given element- Parameters:
element- element to be updatedcount- new counter value- Returns:
- previous value
-
isEmpty
public boolean isEmpty()
This method returns TRUE if counter has no elements, FALSE otherwise- Returns:
-
entrySet
public Set<Map.Entry<T,AtomicDouble>> entrySet()
This method returns Setof this counter - Returns:
-
keySetSorted
public List<T> keySetSorted()
This method returns List of elements, sorted by their counts- Returns:
-
normalize
public void normalize()
This method will apply normalization to counter values and totals.
-
rebuildTotals
protected void rebuildTotals()
-
totalCount
public double totalCount()
This method returns total sum of counter values- Returns:
-
removeKey
public double removeKey(T element)
This method removes given key from counter- Parameters:
element-- Returns:
- counter value
-
argMax
public T argMax()
This method returns element with highest counter value- Returns:
-
dropElementsBelowThreshold
public void dropElementsBelowThreshold(double threshold)
This method will remove all elements with counts below given threshold from counter- Parameters:
threshold-
-
containsElement
public boolean containsElement(T element)
This method checks, if element exist in this counter- Parameters:
element-- Returns:
-
clear
public void clear()
This method effectively resets counter to empty state
-
size
public int size()
Returns total number of tracked elements- Returns:
-
keepTopNElements
public void keepTopNElements(int N)
This method removes all elements except of top N by counter values- Parameters:
N-
-
asPriorityQueue
public PriorityQueue<Pair<T,Double>> asPriorityQueue()
-
asReversedPriorityQueue
public PriorityQueue<Pair<T,Double>> asReversedPriorityQueue()
-
-