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 double freqSum
    The sum of the frequencies of all items.
    private it.unimi.dsi.fastutil.ints.Int2LongMap frequencies
    For each item in the collection, stores the number of times it has been recommended.
    private it.unimi.dsi.fastutil.longs.Long2IntMap maxs
    The maximum indexes for the different possible frequencies values.
    private it.unimi.dsi.fastutil.longs.Long2IntMap mins
    The minimum indexes for the different possible frequency values.
    private int numElements
    The total number of items.
    private double numSum
    The 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
    boolean decreaseFrequency​(int idx)
    Updates the different variables for the Gini index, considering a unit increment on the value.
    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.
    double getValue()
    Obtains the current value of the Gini index.
    boolean increaseFrequency​(int idx)
    Updates the different variables for the Gini index, considering a unit increment on the value.
    void reset()
    Resets the metric to the state with no initial information.
    void reset​(java.util.Map<java.lang.Integer,​java.lang.Long> frequencies)
    Resets the metric to an initial state.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • frequencies

      private final it.unimi.dsi.fastutil.ints.Int2LongMap frequencies
      For each item in the collection, stores the number of times it has been recommended.
    • mins

      private final it.unimi.dsi.fastutil.longs.Long2IntMap mins
      The minimum indexes for the different possible frequency values.
    • maxs

      private final it.unimi.dsi.fastutil.longs.Long2IntMap maxs
      The maximum indexes for the different possible frequencies values.
    • numElements

      private final int numElements
      The total number of items.
    • freqSum

      private double freqSum
      The sum of the frequencies of all items.
    • numSum

      private double numSum
      The 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.