Debian Codegraph @

src/dr/evomodel/branchmodel/lineagespecific/CountableRealizationsParameter.java

raw symbols SCIP
1 /*
2 * CountableRealizationsParameter.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.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 * @author Marc Suchard
38 * @author Filip Bielejec
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 // TODO Make sure all parameters have same dimension
65
66 realizationCount = categoriesParameter.getDimension();
67
68 paramList = new LinkedList<Parameter>();
69 paramList.add(categoriesParameter);
70 paramList.add(uniquelyRealizedParameters);
71
72 // this.paramList = parameter;
73 // for (Parameter p : paramList) {
74 // p.addVariableListener(this);
75 // }
76
77 uniqueRealizationCount = uniquelyRealizedParameters.getDimension();
78
79 }//END: Constructor
80
81 public int getDimension() {
82 return dim * realizationCount; // paramList.get(0).getDimension(); // Unwritten contract
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 // int whichCategoryIndex = index % dim; // TODO Maybe?
110 // int whichDimIndex = index - whichCategoryIndex * dim; // TODO Maybe?
111 // Parameter param = uniquelyRealizedParameters.getParameter((int) categoriesParameter.getParameterValue(whichCategoryIndex));
112 // return param.getParameterValue(whichDimIndex);
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 }//END: getParameterValue
121
122 public void setParameterValue(int dim, double value) {
123
124 int whichCategoryIndex = (int) categoriesParameter.getParameterValue(dim);
125 uniquelyRealizedParameters.setParameterValue(whichCategoryIndex, value);
126
127 }//END: setParameterValue
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(); // TODO
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 }//END: class