Debian Codegraph @

src/dr/inference/model/TransposedBlockUpperTriangularMatrixParameter.java

raw symbols SCIP
1 /*
2 * TransposedBlockUpperTriangularMatrixParameter.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 import java.util.ArrayList;
29 import java.util.List;
30
31 /**
32 * Created by max on 11/4/14.
33 */
34 public class TransposedBlockUpperTriangularMatrixParameter extends BlockUpperTriangularMatrixParameter{
35 public TransposedBlockUpperTriangularMatrixParameter(String name, Parameter[] params) {
36 super(name, params, false);
37
38
39
40 int colDim=params[params.length-1].getSize();
41 // int rowDim=params.length;
42
43 // for(int i=0; i<colDim; i++){
44 // if(i<rowDim)
45 // {params[i].setDimension(i+1);
46 // this.addParameter(params[i]);}
47 // else
48 // {params[i].setDimension(rowDim);
49 // this.addParameter(params[i]);
50 //// System.err.print(colDim-rowDim+i+1);
51 //// System.err.print("\n");
52 // }
53 // }
54 this.colDim=colDim;
55 }
56
57
58 public static TransposedBlockUpperTriangularMatrixParameter recast(String name, CompoundParameter compoundParameter) {
59 final int count = compoundParameter.getParameterCount();
60 Parameter[] parameters = new Parameter[count];
61 for (int i = 0; i < count; ++i) {
62 parameters[i] = compoundParameter.getParameter(i);
63 }
64 return new TransposedBlockUpperTriangularMatrixParameter(name, parameters);
65 }
66
67 // public double getParameterValue(int row, int col){
68 // if(col>row){
69 // return 0;
70 // }
71 // else{
72 // return getParameter(col).getParameterValue(row-col);
73 // }
74 // }
75
76 protected int getRow(int PID){
77 return PID%getRowDimension();
78 }
79
80 protected int getColumn(int PID){
81 return PID/getRowDimension();
82 }
83
84 @Override
85 boolean matrixCondition(int row, int col) {
86 return row>=col;
87 }
88
89 public void setParameterValue(int row, int col, double value){
90 if(matrixCondition(row, col)){
91 getParameter(col).setParameterValueQuietly(row - col, value);
92 fireParameterChangedEvent(col*getRowDimension()+row, ChangeType.VALUE_CHANGED);
93 }
94 }
95
96 public Parameter getParameter(int index) {
97 if (slices == null) {
98 // construct vector_slices
99 slices = new ArrayList<Parameter>();
100 for (int i = 0; i < getColumnDimension(); ++i) {
101 VectorSliceParameter thisSlice = new VectorSliceParameter(getParameterName() + "." + i, i);
102 for (int j = i; j < getRowDimension(); ++j) {
103 thisSlice.addParameter(super.getParameter(j));
104 }
105 slices.add(thisSlice);
106 }
107 }
108 return slices.get(index);
109 }
110
111 protected int getInnerDimension(int row, int col){
112 return row-col;
113 }
114
115 public int getRowDimension(){
116 return getParameterCount();
117 }
118
119 public int getColumnDimension(){
120 return colDim;
121 }
122
123 int colDim;
124 private List<Parameter> slices = null;
125 }