APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.badlogic.gdx.math

public Class CumulativeDistribution<T>

extends Object
Class Inheritance
Imports
com.badlogic.gdx.utils.Array

This class represents a cumulative distribution. It can be used in scenarios where there are values with different probabilities and it's required to pick one of those respecting the probability. For example one could represent the frequency of the alphabet letters using a cumulative distribution and use it to randomly pick a letter respecting their probabilities (useful when generating random words). Another example could be point generation on a mesh surface: one could generate a cumulative distribution using triangles areas as interval size, in this way triangles with a large area will be picked more often than triangles with a smaller one. See Wikipedia for a detailed explanation.
Author
Inferno

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final Array<CumulativeDistribution.CumulativeValue<T>>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
add(T value, float intervalSize)

Adds a value with a given interval size to the distribution

public void
add(T value)

Adds a value with interval size equal to zero to the distribution

public void
clear()

Removes all the values from the distribution

public void
generate()

Generate the cumulative distribution

public void
generateNormalized()

Generate the cumulative distribution in [0,1] where each interval will get a frequency between [0,1]

public void
generateUniform()

Generate the cumulative distribution in [0,1] where each value will have the same frequency and interval size

public float
getInterval(int index)

Returns: the interval size for the value at the given position

public T
getValue(int index)

Returns: the value at the given position

public void
setInterval(T obj, float intervalSize)

Set the interval size on the passed in object.

public void
setInterval(int index, float intervalSize)

Sets the interval size for the value at the given index

public int
size()

Returns: the amount of values

public T

Returns:

the value whose interval contains the probability
value
(float probability)

Finds the value whose interval contains the given probability Binary search algorithm is used to find the value.

public T
value()

Returns: the value whose interval contains a random probability in [0,1]

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

valuesback to summary
private final Array<CumulativeDistribution.CumulativeValue<T>> values

Constructor Detail

CumulativeDistributionback to summary
public CumulativeDistribution()

Method Detail

addback to summary
public void add(T value, float intervalSize)

Adds a value with a given interval size to the distribution

addback to summary
public void add(T value)

Adds a value with interval size equal to zero to the distribution

clearback to summary
public void clear()

Removes all the values from the distribution

generateback to summary
public void generate()

Generate the cumulative distribution

generateNormalizedback to summary
public void generateNormalized()

Generate the cumulative distribution in [0,1] where each interval will get a frequency between [0,1]

generateUniformback to summary
public void generateUniform()

Generate the cumulative distribution in [0,1] where each value will have the same frequency and interval size

getIntervalback to summary
public float getInterval(int index)
Returns:float

the interval size for the value at the given position

getValueback to summary
public T getValue(int index)
Returns:T

the value at the given position

setIntervalback to summary
public void setInterval(T obj, float intervalSize)

Set the interval size on the passed in object. The object must be present in the distribution.

setIntervalback to summary
public void setInterval(int index, float intervalSize)

Sets the interval size for the value at the given index

sizeback to summary
public int size()
Returns:int

the amount of values

valueback to summary
public T value(float probability)

Finds the value whose interval contains the given probability Binary search algorithm is used to find the value.

Returns:T

the value whose interval contains the probability

valueback to summary
public T value()
Returns:T

the value whose interval contains a random probability in [0,1]

com.badlogic.gdx.math back to summary

private Class CumulativeDistribution.CumulativeValue<T>

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
public float
public float
public T

Constructor Summary

AccessConstructor and Description
public
CumulativeValue(T value, float frequency, float interval)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

frequencyback to summary
public float frequency
intervalback to summary
public float interval
valueback to summary
public T value

Constructor Detail

CumulativeValueback to summary
public CumulativeValue(T value, float frequency, float interval)