source: src/main/java/agents/anac/y2019/harddealer/math3/stat/interval/ConfidenceInterval.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.6 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 */
17package agents.anac.y2019.harddealer.math3.stat.interval;
18
19import agents.anac.y2019.harddealer.math3.exception.MathIllegalArgumentException;
20import agents.anac.y2019.harddealer.math3.exception.util.LocalizedFormats;
21
22/**
23 * Represents an interval estimate of a population parameter.
24 *
25 * @since 3.3
26 */
27public class ConfidenceInterval {
28
29 /** Lower endpoint of the interval */
30 private double lowerBound;
31
32 /** Upper endpoint of the interval */
33 private double upperBound;
34
35 /**
36 * The asserted probability that the interval contains the population
37 * parameter
38 */
39 private double confidenceLevel;
40
41 /**
42 * Create a confidence interval with the given bounds and confidence level.
43 * <p>
44 * Preconditions:
45 * <ul>
46 * <li>{@code lower} must be strictly less than {@code upper}</li>
47 * <li>{@code confidenceLevel} must be strictly between 0 and 1 (exclusive)</li>
48 * </ul>
49 * </p>
50 *
51 * @param lowerBound lower endpoint of the interval
52 * @param upperBound upper endpoint of the interval
53 * @param confidenceLevel coverage probability
54 * @throws MathIllegalArgumentException if the preconditions are not met
55 */
56 public ConfidenceInterval(double lowerBound, double upperBound, double confidenceLevel) {
57 checkParameters(lowerBound, upperBound, confidenceLevel);
58 this.lowerBound = lowerBound;
59 this.upperBound = upperBound;
60 this.confidenceLevel = confidenceLevel;
61 }
62
63 /**
64 * @return the lower endpoint of the interval
65 */
66 public double getLowerBound() {
67 return lowerBound;
68 }
69
70 /**
71 * @return the upper endpoint of the interval
72 */
73 public double getUpperBound() {
74 return upperBound;
75 }
76
77 /**
78 * @return the asserted probability that the interval contains the
79 * population parameter
80 */
81 public double getConfidenceLevel() {
82 return confidenceLevel;
83 }
84
85 /**
86 * @return String representation of the confidence interval
87 */
88 @Override
89 public String toString() {
90 return "[" + lowerBound + ";" + upperBound + "] (confidence level:" + confidenceLevel + ")";
91 }
92
93 /**
94 * Verifies that (lower, upper) is a valid non-empty interval and confidence
95 * is strictly between 0 and 1.
96 *
97 * @param lower lower endpoint
98 * @param upper upper endpoint
99 * @param confidence confidence level
100 */
101 private void checkParameters(double lower, double upper, double confidence) {
102 if (lower >= upper) {
103 throw new MathIllegalArgumentException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND, lower, upper);
104 }
105 if (confidence <= 0 || confidence >= 1) {
106 throw new MathIllegalArgumentException(LocalizedFormats.OUT_OF_BOUNDS_CONFIDENCE_LEVEL, confidence, 0, 1);
107 }
108 }
109}
Note: See TracBrowser for help on using the repository browser.