Debian Codegraph @

src/dr/inference/model/TransposedMatrixParameter.java

raw symbols SCIP
1 /*
2 * TransposedMatrixParameter.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 * @author Max Tolkoff
33 * @author Marc A. Suchard
34 */
35 public class TransposedMatrixParameter extends MatrixParameter {
36
37 public TransposedMatrixParameter(String name) {
38 super(name + ".transpose");
39 }
40
41 public TransposedMatrixParameter(String name, Parameter[] parameters) {
42 super(name + ".transpose", parameters);
43 }
44
45 public static TransposedMatrixParameter recast(String name, CompoundParameter compoundParameter) {
46 final int count = compoundParameter.getParameterCount();
47 Parameter[] parameters = new Parameter[count];
48 for (int i = 0; i < count; ++i) {
49 parameters[i] = compoundParameter.getParameter(i);
50 }
51 return new TransposedMatrixParameter(name, parameters);
52 }
53
54 // public double getParameterValue(int row, int col) {
55 // // transposed
56 // return super.getParameterValue(col, row);
57 // }
58
59 public int getColumnDimension() {
60 // transposed
61 return super.getParameter(0).getDimension();
62 }
63
64 public int getRowDimension() {
65 // transposed
66 return super.getParameterCount();
67 }
68
69 public int getParameterCount() {
70 // MatrixParameter.getParamaterCount examines unique parameters
71 // and not column dimension, as it probably should
72 return getColumnDimension();
73 }
74
75 public double[][] getParameterAsMatrix() {
76 final int I = getColumnDimension();
77 final int J = getRowDimension();
78 double[][] parameterAsMatrix = new double[J][I];
79 for (int i = 0; i < I; i++) {
80 for (int j = 0; j < J; j++)
81 parameterAsMatrix[j][i] = getParameterValue(i, j);
82
83 }
84 return parameterAsMatrix;
85 }
86
87 public double getParameterValue(int dim) {
88 // TODO Map to transposed dimension
89 int transposedDim = dim;
90 return super.getParameterValue(transposedDim);
91 }
92
93 public Parameter getParameter(int index) {
94 if (slices == null) {
95 // construct vector_slices
96 slices = new ArrayList<Parameter>();
97 for (int i = 0; i < getColumnDimension(); ++i) {
98 VectorSliceParameter thisSlice = new VectorSliceParameter(getParameterName() + "." + i, i);
99 for (int j = 0; j < getRowDimension(); ++j) {
100 thisSlice.addParameter(super.getParameter(j));
101 }
102 slices.add(thisSlice);
103 }
104 }
105 return slices.get(index);
106 }
107
108 // @Override
109 // public void setParameterValueQuietly(int row, int column, double a) {
110 // super.setParameterValueQuietly(column,row, a);
111 // }
112
113 MatrixParameter transposeBack(){
114 return MatrixParameter.recast(null, this);
115 }
116
117 private List<Parameter> slices = null;
118 }