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>
frequencies
Auxiliar map for storing the frequency of each element in the population.private double
mainsum
Main sum for the Gini coefficientprivate java.util.Map<java.lang.Double,java.lang.Integer>
maximumPos
Auxiliar map for computing Gini coefficient (contains the maximum position for each frequency)private int
maxPerIndiv
Maximum frequency for each individual (maximum income of an individual)private java.util.Map<java.lang.Double,java.lang.Integer>
minimumPos
Auxiliar map for computing Gini coefficient (contains the minimum position for each frequency)private int
populationSize
Size of the populationprivate int
totalFreq
Total frequency (total income of the population)private java.util.TreeSet<java.lang.Double>
values
Auxiliar 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 double
getValue()
Obtains the Gini value.private double
increaseIntermediate(double freq)
Computes the increment for frequencies between old and new.private double
increaseNew(double newfreq)
Computes the increment for new frequencies.private double
increaseOld(double oldfreq)
Computes the increment for old frequencies.void
update(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.
-