Debian Codegraph @

src/dr/inference/model/AdaptableSizeFastMatrixParameter.java

raw symbols SCIP
1 package dr.inference.model;
2
3 import dr.inference.loggers.LogColumn;
4 import dr.inference.loggers.NumberColumn;
5
6 /**
7 * Created by max on 4/6/16.
8 */
9 public class AdaptableSizeFastMatrixParameter extends FastMatrixParameter {
10 public AdaptableSizeFastMatrixParameter(String id, int rowDimension, int colDimension, int maxRow, int maxCol, double startingValue, boolean lowerTriangle) {
11 super(id, maxRow, maxCol, startingValue);
12 if(maxRow < rowDimension){
13 throw new RuntimeException("Row Dimension: " + rowDimension + ", is greater than Max Row Dimension: " + maxRow + " in " + getParameterName());
14 }
15 if(maxCol < colDimension){
16 throw new RuntimeException("Column Dimension: " + colDimension + ", is greater than Max Column Dimension: " + columnDimension + " in " + getParameterName());
17 }
18 this.rowDimension = rowDimension;
19 this.columnDimension = colDimension;
20 this.maxRow = maxRow;
21 this.maxCol = maxCol;
22 this.storedColumnDimension = rowDimension;
23 this.storedColumnDimension = columnDimension;
24 this.lowerTriangle = lowerTriangle;
25
26 }
27
28 public void setRowDimension(int rowDimension){
29 int oldRowDimension = this.rowDimension;
30 this.rowDimension = rowDimension;
31 if(rowDimension > maxRow){
32 throw new RuntimeException("Row Dimension Larger Than Maximum");
33 }
34 if(rowDimension > oldRowDimension)
35 fireParameterChangedEvent(-1, ChangeType.ADDED);
36 else
37 fireParameterChangedEvent(-1, ChangeType.REMOVED);
38 }
39
40 public void setColumnDimension(int columnDimension){
41 int oldColumnDimension = this.columnDimension;
42 if(columnDimension > maxCol){
43 throw new RuntimeException("Column Dimension Larger Than Maximum");
44 }
45 this.columnDimension = columnDimension;
46 if(columnDimension > oldColumnDimension)
47 fireParameterChangedEvent(-1, ChangeType.ADDED);
48 else
49 fireParameterChangedEvent(-1, ChangeType.REMOVED);
50
51 }
52
53 @Override
54 protected void storeValues(){
55 super.storeValues();
56 storedRowDimension = rowDimension;
57 storedColumnDimension = columnDimension;
58 }
59
60 protected void restoreValues(){
61 super.restoreValues();
62 rowDimension = storedRowDimension;
63 columnDimension = storedColumnDimension;
64 }
65
66 public int getRowDimension(){
67 return rowDimension;
68 }
69
70 public int getColumnDimension(){
71 return columnDimension;
72 }
73
74 public int getDimension(){
75 return rowDimension * columnDimension;
76 }
77
78 public int getMaxRowDimension(){return maxRow;}
79
80 public int getMaxColumnDimension(){return maxCol;}
81
82 public void setParameterValue(int index, double value) {
83 int row = index % rowDimension;
84 int col = index / rowDimension;
85
86 if (row >= col || !lowerTriangle){
87 super.setParameterValueQuietly(row, col, value);
88 fireParameterChangedEvent(index, ChangeType.VALUE_CHANGED);
89 }
90 }
91
92 public void setParameterValue(int row, int column, double value){
93 if(row >= column || !lowerTriangle){
94 super.setParameterValueQuietly(row, column, value);
95 fireParameterChangedEvent(getRowDimension() * column + row, ChangeType.VALUE_CHANGED);
96 }
97
98 }
99
100 public void setParameterValueQuietly(int index, double value){
101 int row = index % rowDimension;
102 int col = index / rowDimension;
103
104 if(row >= col || !lowerTriangle) {
105 super.setParameterValueQuietly(row, col, value);
106 }
107 }
108
109 public void setParameterValueQuietly(int row, int column, double value){
110 if(row >= column || !lowerTriangle){
111 super.setParameterValueQuietly(row, column, value);
112 }
113
114 }
115
116 public double getParameterValue(int index){
117 int row = index % rowDimension;
118 int col = index / rowDimension;
119
120 if(row >= col || !lowerTriangle) {
121 return super.getParameterValue(row, col);
122 }
123 else return 0;
124 }
125
126 public double getParameterValue(int row, int col){
127 if(row >= col || !lowerTriangle) {
128 return super.getParameterValue(row, col);
129 }
130 else return 0;
131 }
132
133 public double[] getParameterValues(){
134 double[] answer = new double[getDimension()];
135 for (int i = 0; i < getDimension(); i++) {
136 answer[i]= getParameterValue(i);
137 }
138 return answer;
139 }
140
141 int rowDimension;
142 int columnDimension;
143 int storedRowDimension;
144 int storedColumnDimension;
145 int maxRow;
146 int maxCol;
147 boolean lowerTriangle;
148
149 public LogColumn[] getColumns(){
150 LogColumn[] bigMatrixColumn = new ASFMPColumn[1];
151 bigMatrixColumn[0] = new ASFMPColumn(getParameterName());
152 return bigMatrixColumn;
153 }
154
155 private class ASFMPColumn extends NumberColumn {
156
157 public ASFMPColumn(String label) {
158 super(label);
159 }
160
161 protected String getFormattedValue(){
162 String fullMatrix = "{";
163 for (int i = 0; i <getRowDimension() ; i++) {
164 fullMatrix += " { ";
165 for (int j = 0; j < getColumnDimension(); j++) {
166 fullMatrix += formatValue(getParameterValue(i,j));
167 if(j != getColumnDimension() - 1){
168 fullMatrix += ", ";
169 }
170 }
171 if(i == getRowDimension()-1)
172 fullMatrix += " } ";
173 else
174 fullMatrix += " },";
175 }
176 fullMatrix += "}";
177 return fullMatrix;
178 }
179
180 @Override
181 public double getDoubleValue() {
182 return 0;
183 }
184 }
185
186
187 }
188