Line | |
---|
1 | package geniusweb.opponentmodel.bayesian;
|
---|
2 |
|
---|
3 | /**
|
---|
4 | * A hypothesis is a value with a probability attached to it.
|
---|
5 | * <p>
|
---|
6 | * DO NOT USE THIS. Private use for {@link BayesianOpponentModel}.
|
---|
7 | */
|
---|
8 |
|
---|
9 | abstract class Hypothesis {
|
---|
10 | final private double p;
|
---|
11 |
|
---|
12 | /**
|
---|
13 | *
|
---|
14 | * @param p the probability of the item
|
---|
15 | */
|
---|
16 | public Hypothesis(double p) {
|
---|
17 | if (p < 0 || p > 1)
|
---|
18 | throw new IllegalArgumentException("p must be in [0,1], got " + p);
|
---|
19 | this.p = p;
|
---|
20 | }
|
---|
21 |
|
---|
22 | /**
|
---|
23 | *
|
---|
24 | * @return the probability that this hypothesis holds
|
---|
25 | */
|
---|
26 | public double getProbability() {
|
---|
27 | return p;
|
---|
28 | }
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * Subclasses implement this. We can not implement it here because
|
---|
32 | * subclasses return a more specific class than Hypothesis.
|
---|
33 | *
|
---|
34 | * @param p the new probability value.
|
---|
35 | * @return new Hypothesis with p set to this value (and the rest unchanged).
|
---|
36 | */
|
---|
37 | public abstract Hypothesis with(double p);
|
---|
38 |
|
---|
39 | @Override
|
---|
40 | public int hashCode() {
|
---|
41 | final int prime = 31;
|
---|
42 | int result = 1;
|
---|
43 | long temp;
|
---|
44 | temp = Double.doubleToLongBits(p);
|
---|
45 | result = prime * result + (int) (temp ^ (temp >>> 32));
|
---|
46 | return result;
|
---|
47 | }
|
---|
48 |
|
---|
49 | @Override
|
---|
50 | public boolean equals(Object obj) {
|
---|
51 | if (this == obj)
|
---|
52 | return true;
|
---|
53 | if (obj == null)
|
---|
54 | return false;
|
---|
55 | if (getClass() != obj.getClass())
|
---|
56 | return false;
|
---|
57 | Hypothesis other = (Hypothesis) obj;
|
---|
58 | if (Double.doubleToLongBits(p) != Double.doubleToLongBits(other.p))
|
---|
59 | return false;
|
---|
60 | return true;
|
---|
61 | }
|
---|
62 |
|
---|
63 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.