Added @since tags, cleaned up code. JIRA: MATH-1287
This commit is contained in:
parent
29dfd9bb66
commit
b38ce47047
|
@ -107,19 +107,17 @@ public class EnumeratedIntegerDistribution extends AbstractIntegerDistribution {
|
||||||
*
|
*
|
||||||
* @param rng random number generator used for sampling
|
* @param rng random number generator used for sampling
|
||||||
* @param data input dataset
|
* @param data input dataset
|
||||||
|
* @since 3.6
|
||||||
*/
|
*/
|
||||||
public EnumeratedIntegerDistribution(final RandomGenerator rng, final int[] data) {
|
public EnumeratedIntegerDistribution(final RandomGenerator rng, final int[] data) {
|
||||||
super(rng);
|
super(rng);
|
||||||
final Map<Integer, Integer> dataMap = new HashMap<Integer, Integer>();
|
final Map<Integer, Integer> dataMap = new HashMap<Integer, Integer>();
|
||||||
|
|
||||||
for (int value : data) {
|
for (int value : data) {
|
||||||
Integer count = dataMap.get(value);
|
Integer count = dataMap.get(value);
|
||||||
if (count == null) {
|
if (count == null) {
|
||||||
count = new Integer(1);
|
count = 0;
|
||||||
} else {
|
|
||||||
count = new Integer(count.intValue() + 1);
|
|
||||||
}
|
}
|
||||||
dataMap.put(value, count);
|
dataMap.put(value, ++count);
|
||||||
}
|
}
|
||||||
final int massPoints = dataMap.size();
|
final int massPoints = dataMap.size();
|
||||||
final double denom = data.length;
|
final double denom = data.length;
|
||||||
|
@ -140,6 +138,7 @@ public class EnumeratedIntegerDistribution extends AbstractIntegerDistribution {
|
||||||
* with values 0, 1 and 2 having probability masses 0.25, 0.5 and 0.25 respectively,
|
* with values 0, 1 and 2 having probability masses 0.25, 0.5 and 0.25 respectively,
|
||||||
*
|
*
|
||||||
* @param data input dataset
|
* @param data input dataset
|
||||||
|
* @since 3.6
|
||||||
*/
|
*/
|
||||||
public EnumeratedIntegerDistribution(final int[] data) {
|
public EnumeratedIntegerDistribution(final int[] data) {
|
||||||
this(new Well19937c(), data);
|
this(new Well19937c(), data);
|
||||||
|
@ -152,7 +151,7 @@ public class EnumeratedIntegerDistribution extends AbstractIntegerDistribution {
|
||||||
* @param probabilities probabilities
|
* @param probabilities probabilities
|
||||||
* @return list of value/probability pairs
|
* @return list of value/probability pairs
|
||||||
*/
|
*/
|
||||||
private List<Pair<Integer, Double>> createDistribution(int[] singletons, double[] probabilities) {
|
private static List<Pair<Integer, Double>> createDistribution(int[] singletons, double[] probabilities) {
|
||||||
if (singletons.length != probabilities.length) {
|
if (singletons.length != probabilities.length) {
|
||||||
throw new DimensionMismatchException(probabilities.length, singletons.length);
|
throw new DimensionMismatchException(probabilities.length, singletons.length);
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,19 +109,17 @@ public class EnumeratedRealDistribution extends AbstractRealDistribution {
|
||||||
*
|
*
|
||||||
* @param rng random number generator used for sampling
|
* @param rng random number generator used for sampling
|
||||||
* @param data input dataset
|
* @param data input dataset
|
||||||
|
* @since 3.6
|
||||||
*/
|
*/
|
||||||
public EnumeratedRealDistribution(final RandomGenerator rng, final double[] data) {
|
public EnumeratedRealDistribution(final RandomGenerator rng, final double[] data) {
|
||||||
super(rng);
|
super(rng);
|
||||||
final Map<Double, Integer> dataMap = new HashMap<Double, Integer>();
|
final Map<Double, Integer> dataMap = new HashMap<Double, Integer>();
|
||||||
|
|
||||||
for (double value : data) {
|
for (double value : data) {
|
||||||
Integer count = dataMap.get(value);
|
Integer count = dataMap.get(value);
|
||||||
if (count == null) {
|
if (count == null) {
|
||||||
count = new Integer(1);
|
count = 0;
|
||||||
} else {
|
|
||||||
count = new Integer(count.intValue() + 1);
|
|
||||||
}
|
}
|
||||||
dataMap.put(value, count);
|
dataMap.put(value, ++count);
|
||||||
}
|
}
|
||||||
final int massPoints = dataMap.size();
|
final int massPoints = dataMap.size();
|
||||||
final double denom = data.length;
|
final double denom = data.length;
|
||||||
|
@ -142,6 +140,7 @@ public class EnumeratedRealDistribution extends AbstractRealDistribution {
|
||||||
* with values 0, 1 and 2 having probability masses 0.25, 0.5 and 0.25 respectively,
|
* with values 0, 1 and 2 having probability masses 0.25, 0.5 and 0.25 respectively,
|
||||||
*
|
*
|
||||||
* @param data input dataset
|
* @param data input dataset
|
||||||
|
* @since 3.6
|
||||||
*/
|
*/
|
||||||
public EnumeratedRealDistribution(final double[] data) {
|
public EnumeratedRealDistribution(final double[] data) {
|
||||||
this(new Well19937c(), data);
|
this(new Well19937c(), data);
|
||||||
|
@ -153,7 +152,7 @@ public class EnumeratedRealDistribution extends AbstractRealDistribution {
|
||||||
* @param probabilities probabilities
|
* @param probabilities probabilities
|
||||||
* @return list of value/probability pairs
|
* @return list of value/probability pairs
|
||||||
*/
|
*/
|
||||||
private List<Pair<Double, Double>> createDistribution(double[] singletons, double[] probabilities) {
|
private static List<Pair<Double, Double>> createDistribution(double[] singletons, double[] probabilities) {
|
||||||
if (singletons.length != probabilities.length) {
|
if (singletons.length != probabilities.length) {
|
||||||
throw new DimensionMismatchException(probabilities.length, singletons.length);
|
throw new DimensionMismatchException(probabilities.length, singletons.length);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue