| 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 |
|
| 29 |
|
| 30 |
|
| 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 |
} |