Debian Codegraph @

src/dr/inference/model/SumParameter.java

raw symbols SCIP
1 /*
2 * ProductParameter.java
3 *
4 * Copyright (c) 2002-2012 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 import java.util.List;
29
30 /**
31 * @author Marc Suchard
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(); // TODO
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 }