Debian Codegraph @

src/dr/inference/model/CompoundMatrixParameter.java

raw symbols SCIP
1 /*
2 * CompoundMatrixParameter.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 dr.xml.*;
29
30 import java.util.ArrayList;
31 import java.util.List;
32
33 /**
34 * @author Marc A. Suchard
35 */
36 public class CompoundMatrixParameter extends MatrixParameter {
37
38 public CompoundMatrixParameter(String name, List<MatrixParameterInterface> matrices) {
39 super(name, compoundMatrices(matrices));
40 }
41
42 private static Parameter[] compoundMatrices(List<MatrixParameterInterface> matrices) {
43 int length = 0;
44 for (MatrixParameterInterface matrix : matrices) {
45 length += matrix.getColumnDimension();
46 }
47
48 Parameter[] parameters = new Parameter[length];
49 int index = 0;
50 for (MatrixParameterInterface matrix : matrices) {
51 for (int i = 0; i < matrix.getColumnDimension(); ++i) {
52 parameters[index] = matrix.getParameter(i);
53 ++index;
54 }
55 }
56 return parameters;
57 }
58
59 public final static String COMPOUND_MATRIX_PARAMETER = "compoundMatrixParameter";
60
61 public static XMLObjectParser PARSER = new AbstractXMLObjectParser() {
62
63 public String getParserName() {
64 return COMPOUND_MATRIX_PARAMETER;
65 }
66
67 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
68
69 List<MatrixParameterInterface> matrices = new ArrayList<MatrixParameterInterface>();
70
71 for (int i = 0; i < xo.getChildCount(); ++i) {
72 matrices.add((MatrixParameterInterface) xo.getChild(i));
73 }
74
75 final String name = xo.hasId() ? xo.getId() : null;
76
77 return new CompoundMatrixParameter(name, matrices);
78 }
79
80 //************************************************************************
81 // AbstractXMLObjectParser implementation
82 //************************************************************************
83
84 public String getParserDescription() {
85 return "A compound matrix parameter constructed from its component parameters.";
86 }
87
88 public XMLSyntaxRule[] getSyntaxRules() {
89 return rules;
90 }
91
92 private final XMLSyntaxRule[] rules = {
93 new ElementRule(MatrixParameter.class, 1, Integer.MAX_VALUE),
94 };
95
96 public Class getReturnType() {
97 return CompoundMatrixParameter.class;
98 }
99 };
100 }