Class MonteCarloGini
java.lang.Object
es.uam.eps.ir.relison.utils.indexes.MonteCarloGini
public class MonteCarloGini
extends java.lang.Object
Gini coefficient of a random distribution
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.Integer,java.lang.Double>frequenciesAuxiliar map for storing the frequency of each element in the population.private doublemainsumMain sum for the Gini coefficientprivate java.util.Map<java.lang.Double,java.lang.Integer>maximumPosAuxiliar map for computing Gini coefficient (contains the maximum position for each frequency)private intmaxPerIndivMaximum frequency for each individual (maximum income of an individual)private java.util.Map<java.lang.Double,java.lang.Integer>minimumPosAuxiliar map for computing Gini coefficient (contains the minimum position for each frequency)private intpopulationSizeSize of the populationprivate inttotalFreqTotal frequency (total income of the population)private java.util.TreeSet<java.lang.Double>valuesAuxiliar set containing the possible values -
Constructor Summary
Constructors Constructor Description MonteCarloGini(int populationSize, int totalFreq)Constructor.MonteCarloGini(int populationSize, int totalFreq, int maxPerIndiv)Constructor. -
Method Summary
Modifier and Type Method Description doublegetValue()Obtains the Gini value.private doubleincreaseIntermediate(double freq)Computes the increment for frequencies between old and new.private doubleincreaseNew(double newfreq)Computes the increment for new frequencies.private doubleincreaseOld(double oldfreq)Computes the increment for old frequencies.voidupdate(int numElems)Updates the value of the Gini metric
-
Field Details
-
populationSize
private final int populationSizeSize of the population -
maxPerIndiv
private final int maxPerIndivMaximum frequency for each individual (maximum income of an individual) -
frequencies
private final java.util.Map<java.lang.Integer,java.lang.Double> frequenciesAuxiliar map for storing the frequency of each element in the population. -
minimumPos
private final java.util.Map<java.lang.Double,java.lang.Integer> minimumPosAuxiliar map for computing Gini coefficient (contains the minimum position for each frequency) -
maximumPos
private final java.util.Map<java.lang.Double,java.lang.Integer> maximumPosAuxiliar map for computing Gini coefficient (contains the maximum position for each frequency) -
values
private final java.util.TreeSet<java.lang.Double> valuesAuxiliar set containing the possible values -
totalFreq
private int totalFreqTotal frequency (total income of the population) -
mainsum
private double mainsumMain sum for the Gini coefficient
-
-
Constructor Details
-
MonteCarloGini
public MonteCarloGini(int populationSize, int totalFreq, int maxPerIndiv)Constructor.- Parameters:
populationSize- the total size of the populationtotalFreq- the total frequency of the elements.maxPerIndiv- maximum frequency by individual (smaller or equal than 0 in case of no limits)
-
MonteCarloGini
public MonteCarloGini(int populationSize, int totalFreq)Constructor. It does not set any constraint to the income of an individual.- Parameters:
populationSize- the total size of the population.totalFreq- total frequency of the elements.
-
-
Method Details
-
getValue
public double getValue()Obtains the Gini value.- Returns:
- the Gini value.
-
update
public void update(int numElems)Updates the value of the Gini metric- Parameters:
numElems- number of elements to add (increase in the total income).
-
increaseOld
private double increaseOld(double oldfreq)Computes the increment for old frequencies.- Parameters:
oldfreq- old frequency.- Returns:
- the variation for the old frequency.
-
increaseNew
private double increaseNew(double newfreq)Computes the increment for new frequencies.- Parameters:
newfreq- new frequency.- Returns:
- the variation for the new frequency.
-
increaseIntermediate
private double increaseIntermediate(double freq)Computes the increment for frequencies between old and new.- Parameters:
freq- new frequency.- Returns:
- the variation for the new frequency.
-