| 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.List; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
public class DifferenceParameter extends Parameter.Abstract implements VariableListener { |
| 34 |
|
| 35 |
public DifferenceParameter(List<Parameter> parameter) { |
| 36 |
this.paramList = parameter; |
| 37 |
for (Parameter p : paramList) { |
| 38 |
p.addVariableListener(this); |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
public int getDimension() { |
| 43 |
return paramList.get(0).getDimension(); |
| 44 |
} |
| 45 |
|
| 46 |
protected void storeValues() { |
| 47 |
for (Parameter p : paramList) { |
| 48 |
p.storeParameterValues(); |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
protected void restoreValues() { |
| 53 |
for (Parameter p : paramList) { |
| 54 |
p.restoreParameterValues(); |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
protected void acceptValues() { |
| 59 |
for (Parameter p : paramList) { |
| 60 |
p.acceptParameterValues(); |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
protected void adoptValues(Parameter source) { |
| 65 |
throw new RuntimeException("Not implemented"); |
| 66 |
} |
| 67 |
|
| 68 |
public double getParameterValue(int dim) { |
| 69 |
double value = 0; |
| 70 |
for (int i = 0; i < paramList.size(); i++) { |
| 71 |
if (i == 0){ |
| 72 |
value = paramList.get(i).getParameterValue(dim); |
| 73 |
} else { |
| 74 |
value -= paramList.get(i).getParameterValue(dim); |
| 75 |
} |
| 76 |
} |
| 77 |
return value; |
| 78 |
} |
| 79 |
|
| 80 |
public void setParameterValue(int dim, double value) { |
| 81 |
throw new RuntimeException("Not implemented"); |
| 82 |
} |
| 83 |
|
| 84 |
public void setParameterValueQuietly(int dim, double value) { |
| 85 |
throw new RuntimeException("Not implemented"); |
| 86 |
} |
| 87 |
|
| 88 |
public void setParameterValueNotifyChangedAll(int dim, double value){ |
| 89 |
throw new RuntimeException("Not implemented"); |
| 90 |
} |
| 91 |
|
| 92 |
public String getParameterName() { |
| 93 |
if (getId() == null) { |
| 94 |
StringBuilder sb = new StringBuilder("difference"); |
| 95 |
for (Parameter p : paramList) { |
| 96 |
sb.append(".").append(p.getId()); |
| 97 |
} |
| 98 |
setId(sb.toString()); |
| 99 |
} |
| 100 |
return getId(); |
| 101 |
} |
| 102 |
|
| 103 |
public void addBounds(Bounds bounds) { |
| 104 |
this.bounds = bounds; |
| 105 |
} |
| 106 |
|
| 107 |
public Bounds<Double> getBounds() { |
| 108 |
if (bounds == null) { |
| 109 |
return paramList.get(0).getBounds(); |
| 110 |
} else { |
| 111 |
return bounds; |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
public void addDimension(int index, double value) { |
| 116 |
throw new RuntimeException("Not yet implemented."); |
| 117 |
} |
| 118 |
|
| 119 |
public double removeDimension(int index) { |
| 120 |
throw new RuntimeException("Not yet implemented."); |
| 121 |
} |
| 122 |
|
| 123 |
public void variableChangedEvent(Variable variable, int index, ChangeType type) { |
| 124 |
fireParameterChangedEvent(index,type); |
| 125 |
} |
| 126 |
|
| 127 |
private final List<Parameter> paramList; |
| 128 |
private Bounds bounds = null; |
| 129 |
} |