| 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 MatrixVectorProductParameter extends Parameter.Abstract implements VariableListener { |
| 32 |
|
| 33 |
public MatrixVectorProductParameter(MatrixParameter matrix, Parameter vector) { |
| 34 |
|
| 35 |
this.matrix = matrix; |
| 36 |
this.vector = vector; |
| 37 |
|
| 38 |
matrix.addVariableListener(this); |
| 39 |
vector.addVariableListener(this); |
| 40 |
} |
| 41 |
|
| 42 |
public int getDimension() { |
| 43 |
return matrix.getRowDimension(); |
| 44 |
} |
| 45 |
|
| 46 |
public void setDimension(int dim) { |
| 47 |
throwError("setDimension()"); |
| 48 |
} |
| 49 |
|
| 50 |
protected void storeValues() { |
| 51 |
matrix.storeParameterValues(); |
| 52 |
vector.storeParameterValues(); |
| 53 |
} |
| 54 |
|
| 55 |
protected void restoreValues() { |
| 56 |
matrix.restoreParameterValues(); |
| 57 |
vector.restoreVariableValues(); |
| 58 |
} |
| 59 |
|
| 60 |
protected void acceptValues() { |
| 61 |
matrix.acceptParameterValues(); |
| 62 |
vector.acceptParameterValues(); |
| 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.0; |
| 71 |
for (int k = 0; k < matrix.getColumnDimension(); ++k) { |
| 72 |
value += matrix.getParameterValue(dim, k) * vector.getParameterValue(k); |
| 73 |
} |
| 74 |
return value; |
| 75 |
} |
| 76 |
|
| 77 |
public void setParameterValue(int dim, double value) { |
| 78 |
throwError("setParameterValue()"); |
| 79 |
} |
| 80 |
|
| 81 |
public void setParameterValueQuietly(int dim, double value) { |
| 82 |
throwError("setParameterValueQuietly()"); |
| 83 |
} |
| 84 |
|
| 85 |
public void setParameterValueNotifyChangedAll(int dim, double value) { |
| 86 |
throwError("setParameterValueNotifyChangedAll()"); |
| 87 |
} |
| 88 |
|
| 89 |
private void throwError(String functionName) throws RuntimeException { |
| 90 |
throw new RuntimeException("Object " + getId() + " is a deterministic function. Calling " |
| 91 |
+ functionName + " is not allowed"); |
| 92 |
} |
| 93 |
|
| 94 |
public String getParameterName() { |
| 95 |
if (getId() == null) { |
| 96 |
StringBuilder sb = new StringBuilder("product"); |
| 97 |
sb.append(".").append(matrix.getId()); |
| 98 |
sb.append(".").append(vector.getId()); |
| 99 |
setId(sb.toString()); |
| 100 |
} |
| 101 |
return getId(); |
| 102 |
} |
| 103 |
|
| 104 |
public void addBounds(Bounds bounds) { |
| 105 |
this.bounds = bounds; |
| 106 |
} |
| 107 |
|
| 108 |
public Bounds<Double> getBounds() { |
| 109 |
throwError("getBounds()"); |
| 110 |
return null; |
| 111 |
} |
| 112 |
|
| 113 |
public void addDimension(int index, double value) { |
| 114 |
throw new RuntimeException("Not yet implemented."); |
| 115 |
} |
| 116 |
|
| 117 |
public double removeDimension(int index) { |
| 118 |
throw new RuntimeException("Not yet implemented."); |
| 119 |
} |
| 120 |
|
| 121 |
public void variableChangedEvent(Variable variable, int index, ChangeType type) { |
| 122 |
fireParameterChangedEvent(); |
| 123 |
} |
| 124 |
|
| 125 |
private final MatrixParameter matrix; |
| 126 |
private final Parameter vector; |
| 127 |
|
| 128 |
private Bounds bounds = null; |
| 129 |
} |