MATH-1279
Check precondition. Thanks to David Georg Reichelt for the report.
This commit is contained in:
parent
2aa4681cb8
commit
66d0a9a0a0
|
@ -54,6 +54,9 @@ If the output is not quite correct, check for invisible trailing spaces!
|
|||
</release>
|
||||
|
||||
<release version="4.0" date="XXXX-XX-XX" description="">
|
||||
<action dev="erans" type="fix" issue="MATH-1279"> <!-- backported to 3.6 -->
|
||||
Check precondition (class "o.a.c.m.random.EmpiricalDistribution").
|
||||
</action>
|
||||
<action dev="erans" type="add" issue="MATH-1278"> <!-- backported to 3.6 -->
|
||||
Deep copy of "Network" (package "o.a.c.m.ml.neuralnet") to allow evaluation of
|
||||
of intermediate states during training.
|
||||
|
|
|
@ -37,6 +37,7 @@ import org.apache.commons.math4.exception.MathInternalError;
|
|||
import org.apache.commons.math4.exception.NullArgumentException;
|
||||
import org.apache.commons.math4.exception.OutOfRangeException;
|
||||
import org.apache.commons.math4.exception.ZeroException;
|
||||
import org.apache.commons.math4.exception.NotStrictlyPositiveException;
|
||||
import org.apache.commons.math4.exception.util.LocalizedFormats;
|
||||
import org.apache.commons.math4.stat.descriptive.StatisticalSummary;
|
||||
import org.apache.commons.math4.stat.descriptive.SummaryStatistics;
|
||||
|
@ -147,7 +148,8 @@ public class EmpiricalDistribution extends AbstractRealDistribution {
|
|||
/**
|
||||
* Creates a new EmpiricalDistribution with the specified bin count.
|
||||
*
|
||||
* @param binCount number of bins
|
||||
* @param binCount number of bins. Must be strictly positive.
|
||||
* @throws NotStrictlyPositiveException if {@code binCount <= 0}.
|
||||
*/
|
||||
public EmpiricalDistribution(int binCount) {
|
||||
this(binCount, new RandomDataGenerator());
|
||||
|
@ -157,8 +159,9 @@ public class EmpiricalDistribution extends AbstractRealDistribution {
|
|||
* Creates a new EmpiricalDistribution with the specified bin count using the
|
||||
* provided {@link RandomGenerator} as the source of random data.
|
||||
*
|
||||
* @param binCount number of bins
|
||||
* @param binCount number of bins. Must be strictly positive.
|
||||
* @param generator random data generator (may be null, resulting in default JDK generator)
|
||||
* @throws NotStrictlyPositiveException if {@code binCount <= 0}.
|
||||
* @since 3.0
|
||||
*/
|
||||
public EmpiricalDistribution(int binCount, RandomGenerator generator) {
|
||||
|
@ -180,12 +183,16 @@ public class EmpiricalDistribution extends AbstractRealDistribution {
|
|||
* Private constructor to allow lazy initialisation of the RNG contained
|
||||
* in the {@link #randomData} instance variable.
|
||||
*
|
||||
* @param binCount number of bins
|
||||
* @param binCount number of bins. Must be strictly positive.
|
||||
* @param randomData Random data generator.
|
||||
* @throws NotStrictlyPositiveException if {@code binCount <= 0}.
|
||||
*/
|
||||
private EmpiricalDistribution(int binCount,
|
||||
RandomDataGenerator randomData) {
|
||||
super(randomData.getRandomGenerator());
|
||||
if (binCount <= 0) {
|
||||
throw new NotStrictlyPositiveException(binCount);
|
||||
}
|
||||
this.binCount = binCount;
|
||||
this.randomData = randomData;
|
||||
binStats = new ArrayList<SummaryStatistics>();
|
||||
|
|
|
@ -35,6 +35,7 @@ import org.apache.commons.math4.distribution.RealDistributionAbstractTest;
|
|||
import org.apache.commons.math4.distribution.UniformRealDistribution;
|
||||
import org.apache.commons.math4.exception.MathIllegalStateException;
|
||||
import org.apache.commons.math4.exception.NullArgumentException;
|
||||
import org.apache.commons.math4.exception.NotStrictlyPositiveException;
|
||||
import org.apache.commons.math4.random.EmpiricalDistribution;
|
||||
import org.apache.commons.math4.random.RandomGenerator;
|
||||
import org.apache.commons.math4.stat.descriptive.SummaryStatistics;
|
||||
|
@ -85,6 +86,12 @@ public final class EmpiricalDistributionTest extends RealDistributionAbstractTes
|
|||
}
|
||||
}
|
||||
|
||||
// MATH-1279
|
||||
@Test(expected=NotStrictlyPositiveException.class)
|
||||
public void testPrecondition1() {
|
||||
new EmpiricalDistribution(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test EmpiricalDistrbution.load() using sample data file.<br>
|
||||
* Check that the sampleCount, mu and sigma match data in
|
||||
|
|
Loading…
Reference in New Issue