| 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.evomodel.branchmodel.lineagespecific; |
| 27 |
|
| 28 |
import java.util.LinkedList; |
| 29 |
|
| 30 |
import dr.inference.model.Bounds; |
| 31 |
import dr.inference.model.CompoundParameter; |
| 32 |
import dr.inference.model.Parameter; |
| 33 |
import dr.inference.model.Variable; |
| 34 |
import dr.inference.model.VariableListener; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
@SuppressWarnings("serial") |
| 42 |
public class CountableRealizationsParameter extends Parameter.Abstract implements VariableListener { |
| 43 |
|
| 44 |
private final Parameter categoriesParameter; |
| 45 |
private final CompoundParameter uniquelyRealizedParameters; |
| 46 |
|
| 47 |
|
| 48 |
private final int dim; |
| 49 |
private final int realizationCount; |
| 50 |
|
| 51 |
private final int uniqueRealizationCount; |
| 52 |
|
| 53 |
private final LinkedList<Parameter> paramList; |
| 54 |
private Bounds<Double> bounds = null; |
| 55 |
|
| 56 |
public CountableRealizationsParameter(Parameter categoriesParameter, |
| 57 |
CompoundParameter uniquelyRealizedParameters |
| 58 |
) { |
| 59 |
|
| 60 |
this.categoriesParameter = categoriesParameter; |
| 61 |
this.uniquelyRealizedParameters = uniquelyRealizedParameters; |
| 62 |
|
| 63 |
dim = uniquelyRealizedParameters.getParameter(0).getDimension(); |
| 64 |
|
| 65 |
|
| 66 |
realizationCount = categoriesParameter.getDimension(); |
| 67 |
|
| 68 |
paramList = new LinkedList<Parameter>(); |
| 69 |
paramList.add(categoriesParameter); |
| 70 |
paramList.add(uniquelyRealizedParameters); |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
uniqueRealizationCount = uniquelyRealizedParameters.getDimension(); |
| 78 |
|
| 79 |
} |
| 80 |
|
| 81 |
public int getDimension() { |
| 82 |
return dim * realizationCount; |
| 83 |
} |
| 84 |
|
| 85 |
protected void storeValues() { |
| 86 |
for (Parameter p : paramList) { |
| 87 |
p.storeParameterValues(); |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
protected void restoreValues() { |
| 92 |
for (Parameter p : paramList) { |
| 93 |
p.restoreParameterValues(); |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
protected void acceptValues() { |
| 98 |
for (Parameter p : paramList) { |
| 99 |
p.acceptParameterValues(); |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
protected void adoptValues(Parameter source) { |
| 104 |
throw new RuntimeException("Not implemented"); |
| 105 |
} |
| 106 |
|
| 107 |
public double getParameterValue(int index) { |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
int whichCategoryIndex = categoriesParameter.getValue(index).intValue(); |
| 115 |
int whichDimIndex = 0; |
| 116 |
|
| 117 |
Parameter param = uniquelyRealizedParameters.getParameter(whichCategoryIndex); |
| 118 |
|
| 119 |
return param.getParameterValue(whichDimIndex); |
| 120 |
} |
| 121 |
|
| 122 |
public void setParameterValue(int dim, double value) { |
| 123 |
|
| 124 |
int whichCategoryIndex = (int) categoriesParameter.getParameterValue(dim); |
| 125 |
uniquelyRealizedParameters.setParameterValue(whichCategoryIndex, value); |
| 126 |
|
| 127 |
} |
| 128 |
|
| 129 |
public void setParameterValueQuietly(int dim, double value) { |
| 130 |
throw new RuntimeException("Not implemented"); |
| 131 |
} |
| 132 |
|
| 133 |
public void setParameterValueNotifyChangedAll(int dim, double value){ |
| 134 |
throw new RuntimeException("Not implemented"); |
| 135 |
} |
| 136 |
|
| 137 |
public String getParameterName() { |
| 138 |
if (getId() == null) { |
| 139 |
StringBuilder sb = new StringBuilder("product"); |
| 140 |
for (Parameter p : paramList) { |
| 141 |
sb.append(".").append(p.getId()); |
| 142 |
} |
| 143 |
setId(sb.toString()); |
| 144 |
} |
| 145 |
return getId(); |
| 146 |
} |
| 147 |
|
| 148 |
public void addBounds(Bounds<Double> bounds) { |
| 149 |
this.bounds = bounds; |
| 150 |
} |
| 151 |
|
| 152 |
public Bounds<Double> getBounds() { |
| 153 |
if (bounds == null) { |
| 154 |
return paramList.get(0).getBounds(); |
| 155 |
} else { |
| 156 |
return bounds; |
| 157 |
} |
| 158 |
} |
| 159 |
|
| 160 |
public void addDimension(int index, double value) { |
| 161 |
throw new RuntimeException("Not yet implemented."); |
| 162 |
} |
| 163 |
|
| 164 |
public double removeDimension(int index) { |
| 165 |
throw new RuntimeException("Not yet implemented."); |
| 166 |
} |
| 167 |
|
| 168 |
public void variableChangedEvent(Variable variable, int index, ChangeType type) { |
| 169 |
fireParameterChangedEvent(index,type); |
| 170 |
} |
| 171 |
|
| 172 |
} |