Debian Codegraph @

src/dr/inference/model/MatrixVectorProductParameter.java

raw symbols SCIP
1 /*
2 * MatrixVectorProductParameter.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package dr.inference.model;
27
28 /**
29 * @author Marc Suchard
30 */
31 public class MatrixVectorProductParameter extends Parameter.Abstract implements VariableListener {
32
33 public MatrixVectorProductParameter(MatrixParameter matrix, Parameter vector) {
34 // TODO Check dimensions
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(); // All dimensions may have changed
123 }
124
125 private final MatrixParameter matrix;
126 private final Parameter vector;
127
128 private Bounds bounds = null;
129 }