You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ah...@apache.org on 2021/08/02 07:41:35 UTC

[commons-statistics] branch master updated: Remove ConstantContinuousDistribution

This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-statistics.git


The following commit(s) were added to refs/heads/master by this push:
     new 160bd8f  Remove ConstantContinuousDistribution
160bd8f is described below

commit 160bd8f9bad7f0459972c98b010678eba747a6ac
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Mon Aug 2 08:41:31 2021 +0100

    Remove ConstantContinuousDistribution
    
    This is not a true probability distribution. It is used internally in
    Commons Math for the EmpericalDistribution for sparsely populated
    distribution bins. It has been moved to an inner class in the relevant
    Math code.
---
 .../ConstantContinuousDistribution.java            | 110 ---------------------
 .../ConstantContinuousDistributionTest.java        |  87 ----------------
 2 files changed, 197 deletions(-)

diff --git a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/ConstantContinuousDistribution.java b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/ConstantContinuousDistribution.java
deleted file mode 100644
index dd3778f..0000000
--- a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/ConstantContinuousDistribution.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.statistics.distribution;
-
-import org.apache.commons.rng.UniformRandomProvider;
-
-/**
- * Implementation of the constant real distribution.
- */
-public class ConstantContinuousDistribution extends AbstractContinuousDistribution {
-    /** Constant value of the distribution. */
-    private final double value;
-
-    /**
-     * Create a constant real distribution with the given value.
-     *
-     * @param value Value of this distribution.
-     */
-    public ConstantContinuousDistribution(double value) {
-        this.value = value;
-    }
-
-    /** {@inheritDoc} */
-    @Override
-    public double density(double x) {
-        return x == value ? 1 : 0;
-    }
-
-    /** {@inheritDoc} */
-    @Override
-    public double cumulativeProbability(double x)  {
-        return x < value ? 0 : 1;
-    }
-
-    /** {@inheritDoc} */
-    @Override
-    public double inverseCumulativeProbability(final double p) {
-        if (p < 0 ||
-            p > 1) {
-            throw new DistributionException(DistributionException.INVALID_PROBABILITY, p);
-        }
-        return value;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public double getMean() {
-        return value;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public double getVariance() {
-        return 0;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public double getSupportLowerBound() {
-        return value;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public double getSupportUpperBound() {
-        return value;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public boolean isSupportConnected() {
-        return true;
-    }
-
-    /**
-     * {@inheritDoc}
-     *
-     * @param rng Not used: distribution contains a single value.
-     * @return the value of the distribution.
-     */
-    @Override
-    public ContinuousDistribution.Sampler createSampler(final UniformRandomProvider rng) {
-        return this::getSupportLowerBound;
-    }
-}
diff --git a/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/ConstantContinuousDistributionTest.java b/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/ConstantContinuousDistributionTest.java
deleted file mode 100644
index be882c0..0000000
--- a/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/ConstantContinuousDistributionTest.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.statistics.distribution;
-
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-
-/**
- * Test cases for ConstantContinuousDistribution.
- */
-class ConstantContinuousDistributionTest extends ContinuousDistributionAbstractTest {
-
-    //---------------------- Override tolerance --------------------------------
-
-    @BeforeEach
-    void customSetUp() {
-        setTolerance(0);
-    }
-
-    //-------------- Implementations for abstract methods ----------------------
-
-    @Override
-    public ConstantContinuousDistribution makeDistribution() {
-        return new ConstantContinuousDistribution(1);
-    }
-
-    @Override
-    public double[] makeCumulativeTestPoints() {
-        return new double[] {0, 0.5, 1};
-    }
-
-    @Override
-    public double[] makeCumulativeTestValues() {
-        return new double[] {0, 0, 1};
-    }
-
-    @Override
-    public double[] makeDensityTestValues() {
-        return new double[] {0, 0, 1};
-    }
-
-    @Override
-    @Test
-    void testInverseCumulativeProbabilities() {
-        final ContinuousDistribution dist = getDistribution();
-        for (final double x : getCumulativeTestValues()) {
-            Assertions.assertEquals(1, dist.inverseCumulativeProbability(x));
-        }
-    }
-
-    //-------------------- Additional test cases -------------------------------
-
-    @Test
-    void testMoments() {
-        ConstantContinuousDistribution dist;
-
-        dist = new ConstantContinuousDistribution(-1);
-        Assertions.assertEquals(-1, dist.getMean());
-        Assertions.assertEquals(0, dist.getVariance());
-    }
-
-    @Test
-    @Override
-    void testSampling() {
-        final double value = 12.345;
-        final ContinuousDistribution.Sampler sampler = new ConstantContinuousDistribution(value).createSampler(null);
-        for (int i = 0; i < 10; i++) {
-            Assertions.assertEquals(value, sampler.sample());
-        }
-    }
-}