Debian Codegraph @

src/dr/inference/model/CompoundSymmetricMatrix.java

raw symbols SCIP
1 /*
2 * CompoundSymmetricMatrix.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 Marc Suchard
30 */
31 public class CompoundSymmetricMatrix extends MatrixParameter {
32
33 private Parameter diagonalParameter;
34 private Parameter offDiagonalParameter;
35
36 private boolean asCorrelation = false;
37
38 private int dim;
39
40 public CompoundSymmetricMatrix(Parameter diagonals, Parameter offDiagonal, boolean asCorrelation) {
41 super(MATRIX_PARAMETER);
42 diagonalParameter = diagonals;
43 offDiagonalParameter = offDiagonal;
44 addParameter(diagonalParameter);
45 addParameter(offDiagonal);
46 dim = diagonalParameter.getDimension();
47 this.asCorrelation = asCorrelation;
48 }
49
50 public double[] getAttributeValue() {
51 double[] stats = new double[dim * dim];
52 int index = 0;
53 for (int i = 0; i < dim; i++) {
54 for (int j = 0; j < dim; j++) {
55 stats[index] = getParameterValue(i, j);
56 index++;
57 }
58 }
59 return stats;
60 }
61
62 public double[] getDiagonals() {
63 return diagonalParameter.getParameterValues();
64 }
65
66 public double getOffDiagonal() {
67 return offDiagonalParameter.getParameterValue(0);
68 }
69
70 public double getParameterValue(int row, int col) {
71 if (row != col) {
72 if (asCorrelation) {
73 return offDiagonalParameter.getParameterValue(0) *
74 Math.sqrt(diagonalParameter.getParameterValue(row) * diagonalParameter.getParameterValue(col));
75 }
76 return offDiagonalParameter.getParameterValue(0);
77 }
78 return diagonalParameter.getParameterValue(row);
79 }
80
81 public double[][] getParameterAsMatrix() {
82 final int I = dim;
83 double[][] parameterAsMatrix = new double[I][I];
84 for (int i = 0; i < I; i++) {
85 parameterAsMatrix[i][i] = getParameterValue(i, i);
86 for (int j = i + 1; j < I; j++) {
87 parameterAsMatrix[j][i] = parameterAsMatrix[i][j] = getParameterValue(i, j);
88 }
89 }
90 return parameterAsMatrix;
91 }
92
93 public int getColumnDimension() {
94 return diagonalParameter.getDimension();
95 }
96
97 public int getRowDimension() {
98 return diagonalParameter.getDimension();
99 }
100
101 }