| 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 |
public class DuplicatedParameter extends Parameter.Abstract implements VariableListener { |
| 32 |
|
| 33 |
public DuplicatedParameter(Parameter parameter) { |
| 34 |
this.parameter = parameter; |
| 35 |
parameter.addVariableListener(this); |
| 36 |
copies = 1; |
| 37 |
originalBounds = parameter.getBounds(); |
| 38 |
bounds = originalBounds; |
| 39 |
} |
| 40 |
|
| 41 |
public void addDuplicationParameter(Parameter dupParameter) { |
| 42 |
this.dupParameter = dupParameter; |
| 43 |
dupParameter.addParameterListener(this); |
| 44 |
updateDuplication(); |
| 45 |
} |
| 46 |
|
| 47 |
private void updateDuplication() { |
| 48 |
copies = (int) dupParameter.getParameterValue(0); |
| 49 |
final int originalLength = originalBounds.getBoundsDimension(); |
| 50 |
double[] lowers = new double[getDimension()]; |
| 51 |
double[] uppers = new double[getDimension()]; |
| 52 |
for(int i=0; i<originalLength; i++) { |
| 53 |
lowers[i] = originalBounds.getLowerLimit(i); |
| 54 |
uppers[i] = originalBounds.getUpperLimit(i); |
| 55 |
} |
| 56 |
for(int i=1; i<copies; i++) { |
| 57 |
System.arraycopy(lowers,0,lowers,i*originalLength,originalLength); |
| 58 |
System.arraycopy(uppers,0,uppers,i*originalLength,originalLength); |
| 59 |
} |
| 60 |
bounds = new DefaultBounds(uppers,lowers); |
| 61 |
} |
| 62 |
|
| 63 |
public int getDimension() { |
| 64 |
return parameter.getDimension() * copies; |
| 65 |
} |
| 66 |
|
| 67 |
protected void storeValues() { |
| 68 |
parameter.storeParameterValues(); |
| 69 |
} |
| 70 |
|
| 71 |
protected void restoreValues() { |
| 72 |
parameter.restoreParameterValues(); |
| 73 |
} |
| 74 |
|
| 75 |
protected void acceptValues() { |
| 76 |
parameter.acceptParameterValues(); |
| 77 |
} |
| 78 |
|
| 79 |
protected void adoptValues(Parameter source) { |
| 80 |
parameter.adoptParameterValues(source); |
| 81 |
} |
| 82 |
|
| 83 |
public double getParameterValue(int dim) { |
| 84 |
return parameter.getParameterValue(dim % parameter.getDimension()); |
| 85 |
} |
| 86 |
|
| 87 |
public void setParameterValue(int dim, double value) { |
| 88 |
parameter.setParameterValue(dim % parameter.getDimension(), value); |
| 89 |
fireParameterChangedEvent(dim, Parameter.ChangeType.VALUE_CHANGED); |
| 90 |
} |
| 91 |
|
| 92 |
public void setParameterValueQuietly(int dim, double value) { |
| 93 |
parameter.setParameterValueQuietly(dim % parameter.getDimension(), value); |
| 94 |
} |
| 95 |
|
| 96 |
public void setParameterValueNotifyChangedAll(int dim, double value){ |
| 97 |
parameter.setParameterValueNotifyChangedAll(dim % parameter.getDimension(), value); |
| 98 |
} |
| 99 |
|
| 100 |
public String getParameterName() { |
| 101 |
if (getId() == null) |
| 102 |
return "duplicated" + parameter.getParameterName(); |
| 103 |
return getId(); |
| 104 |
} |
| 105 |
|
| 106 |
public void addBounds(Bounds bounds) { |
| 107 |
throw new RuntimeException("Not yet implemented."); |
| 108 |
} |
| 109 |
|
| 110 |
public Bounds<Double> getBounds() { |
| 111 |
return bounds; |
| 112 |
} |
| 113 |
|
| 114 |
public void addDimension(int index, double value) { |
| 115 |
throw new RuntimeException("Not yet implemented."); |
| 116 |
} |
| 117 |
|
| 118 |
public double removeDimension(int index) { |
| 119 |
throw new RuntimeException("Not yet implemented."); |
| 120 |
} |
| 121 |
|
| 122 |
public void variableChangedEvent(Variable variable, int index, ChangeType type) { |
| 123 |
if (variable == dupParameter) { |
| 124 |
updateDuplication(); |
| 125 |
} |
| 126 |
|
| 127 |
for (int i = 0; i < copies; ++i) { |
| 128 |
|
| 129 |
fireParameterChangedEvent(index + i * parameter.getDimension(), Parameter.ChangeType.VALUE_CHANGED); |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
private final Parameter parameter; |
| 134 |
private Parameter dupParameter; |
| 135 |
private int copies; |
| 136 |
private Bounds<Double> bounds; |
| 137 |
private final Bounds<Double> originalBounds; |
| 138 |
|
| 139 |
} |