1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 /*
19 * This is not the original file distributed by the Apache Software Foundation
20 * It has been modified by the Hipparchus project
21 */
22
23 package org.hipparchus.distribution.continuous;
24
25 import org.hipparchus.exception.MathIllegalArgumentException;
26 import org.hipparchus.util.MathUtils;
27
28 /**
29 * Implementation of the constant real distribution.
30 */
31 public class ConstantRealDistribution extends AbstractRealDistribution {
32
33 /** Serialization ID */
34 private static final long serialVersionUID = 20160320L;
35 /** Constant value of the distribution */
36 private final double value;
37
38 /**
39 * Create a constant real distribution with the given value.
40 *
41 * @param value the constant value of this distribution
42 */
43 public ConstantRealDistribution(double value) {
44 this.value = value;
45 }
46
47 /** {@inheritDoc} */
48 @Override
49 public double density(double x) {
50 return x == value ? 1 : 0;
51 }
52
53 /** {@inheritDoc} */
54 @Override
55 public double cumulativeProbability(double x) {
56 return x < value ? 0 : 1;
57 }
58
59 /** {@inheritDoc} */
60 @Override
61 public double inverseCumulativeProbability(final double p)
62 throws MathIllegalArgumentException {
63 MathUtils.checkRangeInclusive(p, 0, 1);
64 return value;
65 }
66
67 /**
68 * {@inheritDoc}
69 */
70 @Override
71 public double getNumericalMean() {
72 return value;
73 }
74
75 /**
76 * {@inheritDoc}
77 */
78 @Override
79 public double getNumericalVariance() {
80 return 0;
81 }
82
83 /**
84 * {@inheritDoc}
85 */
86 @Override
87 public double getSupportLowerBound() {
88 return value;
89 }
90
91 /**
92 * {@inheritDoc}
93 */
94 @Override
95 public double getSupportUpperBound() {
96 return value;
97 }
98
99 /**
100 * {@inheritDoc}
101 */
102 @Override
103 public boolean isSupportConnected() {
104 return true;
105 }
106 }