Debian Codegraph @

src/dr/inference/model/Bounds.java

raw symbols SCIP
1 /*
2 * Bounds.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package dr.inference.model;
27
28 import java.io.Serializable;
29 import java.util.ArrayList;
30
31 /**
32 * Represents a multi-dimensional 'regular' boundary (a hypervolume)
33 *
34 * @author Alexei Drummond
35 * @version $Id: Bounds.java,v 1.2 2005/05/24 20:25:59 rambaut Exp $
36 */
37 public interface Bounds<V> extends Serializable {
38
39 /**
40 * @return the upper limit of this hypervolume in the given dimension.
41 */
42 V getUpperLimit(int dimension);
43
44 /**
45 * @return the lower limit of this hypervolume in the given dimension.
46 */
47 V getLowerLimit(int dimension);
48
49 /**
50 * @return the dimensionality of this hypervolume.
51 */
52 int getBoundsDimension();
53
54 public class Int implements Bounds<Integer> {
55
56 int size = 1;
57 int lower = java.lang.Integer.MIN_VALUE;
58 int upper = java.lang.Integer.MAX_VALUE;
59
60 public Int(int size, int lower, int upper) {
61 this.size = size;
62 this.lower = lower;
63 this.upper = upper;
64 }
65
66 public Int(Variable<Integer> variable, int lower, int upper) {
67 this.size = variable.getSize();
68 this.lower = lower;
69 this.upper = upper;
70 }
71
72
73 public Integer getUpperLimit(int dimension) {
74 return upper;
75 }
76
77 public Integer getLowerLimit(int dimension) {
78 return lower;
79 }
80
81 public int getBoundsDimension() {
82 return size;
83 }
84 }
85
86 /**
87 * A staircase bound is used for model averaging and requires each index to have an upper bound equal to its
88 * index. Thus there is always a value 0 in the first entry of the parameter, whereas there is a value of 0 or 1
89 * in the second entry, {0,1,2} in the third entry et cetera. AJD
90 *
91 * But in the code, for simplicity, first entry of the parameter is not implemented,
92 * so that integer parameter size = real size - 1, and 1st digital of paramter = 2nd position of proposed index,
93 * namely {0, 1}. Walter
94 */
95 public class Staircase implements Bounds<Integer> {
96
97 int size = 0;
98
99 public Staircase(int size) {
100 this.size = size;
101 }
102
103 public Staircase(Variable<Integer> variable) {
104 this.size = variable.getSize();
105 }
106
107
108 public Integer getUpperLimit(int dimension) {
109 return dimension + 1; // integer index parameter size = real size - 1
110 }
111
112 public Integer getLowerLimit(int dimension) {
113 return 0;
114 }
115
116 public int getBoundsDimension() {
117 return size;
118 }
119
120 private ArrayList<Bounds<Integer>> bounds = null;
121
122 public void addBounds(Bounds<Integer> boundary) {
123 if (boundary.getBoundsDimension() != size) {
124 throw new IllegalArgumentException("Incorrect dimension of bounds, expected " +
125 size + " but received " + boundary.getBoundsDimension());
126 }
127 if (bounds == null) {
128 bounds = new ArrayList<Bounds<Integer>>();
129 }
130 bounds.add(boundary);
131 }
132 }
133 }