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