source: src/main/java/agents/anac/y2019/harddealer/math3/distribution/ConstantRealDistribution.java

Last change on this file was 204, checked in by Katsuhide Fujita, 5 years ago

Fixed errors of ANAC2019 agents

  • Property svn:executable set to *
File size: 3.0 KB
Line 
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 * http://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
18package agents.anac.y2019.harddealer.math3.distribution;
19
20import agents.anac.y2019.harddealer.math3.exception.OutOfRangeException;
21
22/**
23 * Implementation of the constant real distribution.
24 *
25 * @since 3.4
26 */
27public class ConstantRealDistribution extends AbstractRealDistribution {
28
29 /** Serialization ID */
30 private static final long serialVersionUID = -4157745166772046273L;
31
32 /** Constant value of the distribution */
33 private final double value;
34
35 /**
36 * Create a constant real distribution with the given value.
37 *
38 * @param value the constant value of this distribution
39 */
40 public ConstantRealDistribution(double value) {
41 super(null); // Avoid creating RandomGenerator
42 this.value = value;
43 }
44
45 /** {@inheritDoc} */
46 public double density(double x) {
47 return x == value ? 1 : 0;
48 }
49
50 /** {@inheritDoc} */
51 public double cumulativeProbability(double x) {
52 return x < value ? 0 : 1;
53 }
54
55 /** {@inheritDoc} */
56 @Override
57 public double inverseCumulativeProbability(final double p)
58 throws OutOfRangeException {
59 if (p < 0.0 || p > 1.0) {
60 throw new OutOfRangeException(p, 0, 1);
61 }
62 return value;
63 }
64
65 /**
66 * {@inheritDoc}
67 */
68 public double getNumericalMean() {
69 return value;
70 }
71
72 /**
73 * {@inheritDoc}
74 */
75 public double getNumericalVariance() {
76 return 0;
77 }
78
79 /**
80 * {@inheritDoc}
81 */
82 public double getSupportLowerBound() {
83 return value;
84 }
85
86 /**
87 * {@inheritDoc}
88 */
89 public double getSupportUpperBound() {
90 return value;
91 }
92
93 /** {@inheritDoc} */
94 public boolean isSupportLowerBoundInclusive() {
95 return true;
96 }
97
98 /** {@inheritDoc} */
99 public boolean isSupportUpperBoundInclusive() {
100 return true;
101 }
102
103 /**
104 * {@inheritDoc}
105 */
106 public boolean isSupportConnected() {
107 return true;
108 }
109
110 /** {@inheritDoc} */
111 @Override
112 public double sample() {
113 return value;
114 }
115
116 /**
117 * Override with no-op (there is no generator).
118 * @param seed (ignored)
119 */
120 @Override
121 public void reseedRandomGenerator(long seed) {}
122}
Note: See TracBrowser for help on using the repository browser.