Debian Codegraph @

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