Class FastGiniIndex
java.lang.Object
es.uam.eps.ir.relison.utils.indexes.FastGiniIndex
public class FastGiniIndex
extends java.lang.Object
Class for computing and updating the Gini index.
-
Field Summary
Fields Modifier and Type Field Description private doublefreqSumThe sum of the frequencies of all items.private it.unimi.dsi.fastutil.ints.Int2LongMapfrequenciesFor each item in the collection, stores the number of times it has been recommended.private it.unimi.dsi.fastutil.longs.Long2IntMapmaxsThe maximum indexes for the different possible frequencies values.private it.unimi.dsi.fastutil.longs.Long2IntMapminsThe minimum indexes for the different possible frequency values.private intnumElementsThe total number of items.private doublenumSumThe main term of the Gini index. -
Constructor Summary
Constructors Constructor Description FastGiniIndex(int numElements)Constructor.FastGiniIndex(int numElements, java.util.Map<java.lang.Integer,java.lang.Long> frequencies)Constructor. -
Method Summary
Modifier and Type Method Description booleandecreaseFrequency(int idx)Updates the different variables for the Gini index, considering a unit increment on the value.private voidfillValues(java.util.Map<java.lang.Integer,java.lang.Long> frequencies)Given a relation of items and frequencies, updates the values of the items indicated in the relation.doublegetValue()Obtains the current value of the Gini index.booleanincreaseFrequency(int idx)Updates the different variables for the Gini index, considering a unit increment on the value.voidreset()Resets the metric to the state with no initial information.voidreset(java.util.Map<java.lang.Integer,java.lang.Long> frequencies)Resets the metric to an initial state.
-
Field Details
-
frequencies
private final it.unimi.dsi.fastutil.ints.Int2LongMap frequenciesFor each item in the collection, stores the number of times it has been recommended. -
mins
private final it.unimi.dsi.fastutil.longs.Long2IntMap minsThe minimum indexes for the different possible frequency values. -
maxs
private final it.unimi.dsi.fastutil.longs.Long2IntMap maxsThe maximum indexes for the different possible frequencies values. -
numElements
private final int numElementsThe total number of items. -
freqSum
private double freqSumThe sum of the frequencies of all items. -
numSum
private double numSumThe main term of the Gini index.
-
-
Constructor Details
-
FastGiniIndex
public FastGiniIndex(int numElements)Constructor. Assumes that the initial values for frequencies are equal to 0.- Parameters:
numElements- the number of elements to consider.
-
FastGiniIndex
public FastGiniIndex(int numElements, java.util.Map<java.lang.Integer,java.lang.Long> frequencies)Constructor. Uses an initial setting for the different values.- Parameters:
numElements- total number of items.frequencies- frequencies for the different item values.
-
-
Method Details
-
getValue
public double getValue()Obtains the current value of the Gini index.- Returns:
- the current value: a number between 0 and 1 representing the proper value of the index, NaN if the frequencies are all equal to zero, or there is less than one element in the collection.
-
increaseFrequency
public boolean increaseFrequency(int idx)Updates the different variables for the Gini index, considering a unit increment on the value.- Parameters:
idx- the index of the element to increase in a unit.- Returns:
- true if everything went OK, false otherwise.
-
decreaseFrequency
public boolean decreaseFrequency(int idx)Updates the different variables for the Gini index, considering a unit increment on the value. The value cannot descend 0.- Parameters:
idx- the index of the element to increase in a unit.- Returns:
- true if everything went OK, false otherwise.
-
fillValues
private void fillValues(java.util.Map<java.lang.Integer,java.lang.Long> frequencies)Given a relation of items and frequencies, updates the values of the items indicated in the relation. This method supposes that the CumulativeGini object is empty.- Parameters:
frequencies- the relation between elements and its frequencies.
-
reset
public void reset()Resets the metric to the state with no initial information. -
reset
public void reset(java.util.Map<java.lang.Integer,java.lang.Long> frequencies)Resets the metric to an initial state.- Parameters:
frequencies- the initial frequencies.
-