Debian Codegraph @

src/dr/inference/model/FastBlockUpperTriangularMatrixParameter.java

raw symbols SCIP
1 /*
2 * BlockUpperTriangularMatrixParameter.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 Max Tolkoff
30 */
31
32
33
34 public class FastBlockUpperTriangularMatrixParameter extends FastMatrixParameter {
35 private int rowDim;
36 private Bounds bounds = null;
37
38 // public TransposedBlockUpperTriangularMatrixParameter transposeBlock(){
39 // return TransposedBlockUpperTriangularMatrixParameter.recast(getVariableName(), this);
40 // }
41
42 public FastBlockUpperTriangularMatrixParameter(String name, int rows, int cols) {
43 super(name, cols, rows, 1);
44
45
46 boolean diagonalRestriction=false;
47 if(diagonalRestriction) {
48 for (int i = 0; i < getColumnDimension(); i++) {
49 if (i < getRowDimension()) {
50 double[] uppers = new double[i + 1];
51 double[] lowers = new double[i + 1];
52
53 for (int j = 0; j < uppers.length; j++) {
54 uppers[j] = Double.POSITIVE_INFINITY;
55 lowers[j] = Double.NEGATIVE_INFINITY;
56
57 }
58 lowers[i] = 0;
59 getParameter(i).addBounds(new DefaultBounds(uppers, lowers));
60 }
61 }
62 }
63
64 }
65
66 // @Override
67 // public int getRowDimension() {
68 // return rowDim;
69 // }
70
71 // public void setRowDimension(int rowDim){
72 // this.rowDim=rowDim;
73 // }
74
75 // public double[][] getParameterAsMatrix(){
76 // double[][] answer=new double[getRowDimension()][getColumnDimension()];
77 // for(int i=0; i<getRowDimension(); i++){
78 // for(int j=0; j<getColumnDimension(); j++){
79 // if(i<=j){
80 //// System.err.print(parameters[i].getSize());
81 //// System.err.print("we get here\n");
82 // answer[i][j]=getParameter(j).getParameterValue(i);
83 // }
84 // else{
85 //// System.err.print(i);
86 //// System.err.print(" ");
87 //// System.err.print(j);
88 //// System.err.print("\n");
89 // answer[i][j]=0;
90 //// System.err.print("getting here?\n");
91 // }
92 // }
93 // }
94 //
95 // return answer;
96 // }
97
98 public double getParameterValue(int row, int col) {
99 if (!matrixCondition(row, col)) {
100 return 0.0;
101 } else {
102 return super.getParameterValue(row,col);
103 }
104 }
105
106 protected int getRow(int PID){
107 return PID%getRowDimension();
108 }
109
110 protected int getColumn(int PID){
111 return PID/getRowDimension();
112 }
113
114 public void setParameterValueQuietly(int row, int col, double value){
115 if(matrixCondition(row, col)){
116 super.setParameterValueQuietly(row, col, value);
117 }
118 }
119
120 public void setParameterValue(int row, int col,double value){
121 if(matrixCondition(row, col)){
122 super.setParameterValue(row, col, value);}
123 }
124
125 public void setParameterValue(int PID, double value){
126
127 int row=getRow(PID);
128 int col=getColumn(PID);
129 // System.out.println(row+" "+col);
130 // System.out.println(matrixCondition(row, col));
131
132
133 if(matrixCondition(row, col)){
134 setParameterValue(row, col, value);
135 }
136 }
137
138
139 //test if violates matrix condition
140 boolean matrixCondition(int row, int col){
141 return row>=getColumnDimension()-row;
142 }
143
144 public double getParameterValue(int id){
145 int row=getRow(id);
146 int col=getColumn(id);
147
148 if(matrixCondition(row, col)){
149 return getParameterValue(row, col);
150 }
151 else
152 {
153 return 0;
154 }
155 }
156
157 public void addBounds(Bounds<Double> boundary) {
158
159 if (bounds == null) {
160 bounds = new BUTMPBounds();
161 // return;
162 } //else {
163 IntersectionBounds newBounds = new IntersectionBounds(getDimension());
164 newBounds.addBounds(bounds);
165
166 // }
167 ((IntersectionBounds) bounds).addBounds(boundary);
168 }
169
170 public Bounds<Double> getBounds() {
171
172 if (bounds == null) {
173 bounds = new BUTMPBounds();
174 }
175 return bounds;
176 }
177
178 protected int getInnerDimension(int row, int col){
179 return row;
180 }
181
182
183 private class BUTMPBounds implements Bounds<Double>{
184 //TODO test!
185
186 public Double getUpperLimit(int dim) {
187 int row=getRow(dim);
188 int col=getColumn(dim);
189
190 if(matrixCondition(row, col)){
191
192 return getParameter(col).getBounds().getUpperLimit(getInnerDimension(row, col)); }
193 else
194 return 0.0;
195 }
196
197 public Double getLowerLimit(int dim) {
198 int row=getRow(dim);
199 int col=getColumn(dim);
200
201 if(matrixCondition(row, col)){
202 return getParameter(col).getBounds().getLowerLimit(getInnerDimension(row, col));
203 // System.out.println(getParameters().get(dim-row).getBounds().getLowerLimit(getPindex().get(dim-row)));
204 // return getParameters().get(dim-row).getBounds().getLowerLimit(getPindex().get(dim-row));
205 }
206 else
207 return 0.0;
208 }
209
210 public int getBoundsDimension() {
211 // int nBlanks = 0;
212 // for (int i = 0; i <getColumnDimension() ; i++) {
213 // nBlanks+=1;
214 // }
215 //
216 // return getDimension()-nBlanks;
217 return getDimension();
218 }
219 }
220
221 public int getDimension(){
222 return getRowDimension()*getColumnDimension();
223 }
224
225
226 }