| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
package dr.inference.model; |
| 27 |
|
| 28 |
import java.util.ArrayList; |
| 29 |
|
| 30 |
|
| 31 |
public class IntersectionBounds implements Bounds<Double> { |
| 32 |
|
| 33 |
IntersectionBounds(int dimension) { |
| 34 |
this.dimension = dimension; |
| 35 |
} |
| 36 |
|
| 37 |
public void addBounds(Bounds<Double> boundary) { |
| 38 |
if (boundary.getBoundsDimension() != dimension) { |
| 39 |
throw new IllegalArgumentException("Incorrect dimension of bounds, expected " + |
| 40 |
dimension + " but received " + boundary.getBoundsDimension()); |
| 41 |
} |
| 42 |
if (bounds == null) { |
| 43 |
bounds = new ArrayList<Bounds<Double>>(); |
| 44 |
} |
| 45 |
bounds.add(boundary); |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
public Double getLowerLimit(int index) { |
| 52 |
|
| 53 |
double lower = Double.NEGATIVE_INFINITY; |
| 54 |
if (bounds != null) { |
| 55 |
for (Bounds<Double> boundary : bounds) { |
| 56 |
if (boundary.getLowerLimit(index) > lower) { |
| 57 |
lower = boundary.getLowerLimit(index); |
| 58 |
} |
| 59 |
} |
| 60 |
} |
| 61 |
return lower; |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
public Double getUpperLimit(int index) { |
| 68 |
|
| 69 |
double upper = Double.POSITIVE_INFINITY; |
| 70 |
if (bounds != null) { |
| 71 |
for (Bounds<Double> boundary : bounds) { |
| 72 |
if (boundary.getUpperLimit(index) < upper) { |
| 73 |
upper = boundary.getUpperLimit(index); |
| 74 |
} |
| 75 |
} |
| 76 |
} |
| 77 |
return upper; |
| 78 |
} |
| 79 |
|
| 80 |
public int getBoundsDimension() { |
| 81 |
return dimension; |
| 82 |
} |
| 83 |
|
| 84 |
public String toString() { |
| 85 |
String str = "upper=[" + getUpperLimit(0); |
| 86 |
for (int i = 1; i < getBoundsDimension(); i++) { |
| 87 |
str += ", " + getUpperLimit(i); |
| 88 |
} |
| 89 |
str += "] lower=[" + getLowerLimit(0); |
| 90 |
for (int i = 1; i < getBoundsDimension(); i++) { |
| 91 |
str += ", " + getLowerLimit(i); |
| 92 |
} |
| 93 |
|
| 94 |
str += "]"; |
| 95 |
return str; |
| 96 |
} |
| 97 |
|
| 98 |
private ArrayList<Bounds<Double>> bounds = null; |
| 99 |
private final int dimension; |
| 100 |
} |