Debian Codegraph @

src/dr/inference/model/ParameterChooser.java

raw symbols SCIP
1 /*
2 * ParameterChooser.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 /**
29 * @author Joseph Heled
30 * Date: 31/08/2009
31 */
32 public class ParameterChooser extends Variable.BaseNumerical<Double> implements Variable<Double>, ModelListener {
33 private final ValuesPool pool;
34 private final int which[];
35
36 ParameterChooser(String name, ValuesPool pool, int which[]) {
37 super(name);
38 this.pool = pool;
39 this.which = which;
40
41 pool.addModelListener(this);
42 }
43
44 public int getSize() {
45 return which.length;
46 }
47
48 public Double getValue(int index) {
49 return pool.getValue(which[index]);
50 }
51
52 public void setValue(int index, Double value) {
53 assert false;
54 }
55
56 public Double[] getValues() {
57 final int size = getSize();
58 Double[] copyOfValues = new Double[size];
59 for (int i = 0; i < size; i++) {
60 copyOfValues[i] = getValue(i) ;
61 }
62 return copyOfValues;
63 }
64
65 public void storeVariableValues() {
66 //
67 }
68
69 public void restoreVariableValues() {
70 //
71 }
72
73 public void acceptVariableValues() {
74 //
75 }
76
77 private final Bounds<Double> bounds = new Bounds<Double>() {
78 public Double getUpperLimit(int dimension) {
79 return pool.getBounds().getUpperLimit(which[dimension]);
80 }
81
82 public Double getLowerLimit(int dimension) {
83 return pool.getBounds().getLowerLimit(which[dimension]);
84 }
85
86 public int getBoundsDimension() {
87 return getSize();
88 }
89 };
90
91 public Bounds<Double> getBounds() {
92 return bounds;
93 }
94
95 public void addBounds(Bounds<Double> bounds) {
96 final Bounds<Double> b = getBounds();
97 assert bounds.getBoundsDimension() == b.getBoundsDimension();
98
99 for(int dim = 0; dim < bounds.getBoundsDimension(); ++dim) {
100 if( bounds.getLowerLimit(dim) > b.getLowerLimit(dim) ||
101 bounds.getUpperLimit(dim) < b.getUpperLimit(dim) ) {
102 throw new RuntimeException("can't do that");
103 }
104 }
105 }
106
107 public void modelChangedEvent(Model model, Object object, int index) {
108 for(int k = 0; k < which.length; ++k) {
109 if( pool.hasChanged(which[k], object, index) ) {
110 fireVariableChanged(k);
111 }
112 }
113 }
114
115 public void modelRestored(Model model) {
116 }
117 }