Debian Codegraph @

src/dr/inferencexml/model/BlockUpperTriangularMatrixParameterParser.java

raw symbols SCIP
1 /*
2 * BlockUpperTriangularMatrixParameterParser.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.inferencexml.model;
27
28 import dr.inference.model.BlockUpperTriangularMatrixParameter;
29 import dr.inference.model.Parameter;
30 import dr.xml.*;
31
32 /**
33 @author Max Tolkoff
34 */
35 public class BlockUpperTriangularMatrixParameterParser extends AbstractXMLObjectParser {
36 private static final String BLOCK_UPPER_TRIANGULAR_MATRIX="blockUpperTriangularMatrixParameter";
37 private static final String COLUMN_DIMENSION="columnDimension";
38 private static final String TRANSPOSE="transpose";
39 private static final String DIAGONAL_RESTRICTION="diagonalRestriction";
40
41 @Override
42 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
43
44 final String name = xo.hasId() ? xo.getId() : null;
45 final boolean transpose= xo.getAttribute(TRANSPOSE, false);
46 // int rowDim=xo.getChildCount();
47 // int colDim;
48 final boolean diagonalRestriction=xo.getAttribute(DIAGONAL_RESTRICTION, false);
49 Parameter temp=null;
50 // if(xo.hasAttribute(COLUMN_DIMENSION)) {
51 // colDim = xo.getAttribute(COLUMN_DIMENSION, 1);
52 // }
53 // else
54 // {
55 // temp=(Parameter) xo.getChild(xo.getChildCount()-1);
56 // colDim=temp.getDimension();
57 // }
58
59 Parameter[] params=new Parameter[xo.getChildCount()];
60
61
62
63 for (int i = 0; i < xo.getChildCount(); i++) {
64 temp = (Parameter) xo.getChild(i);
65 params[i]=temp;}
66
67 BlockUpperTriangularMatrixParameter ltmp=new BlockUpperTriangularMatrixParameter(name, params, diagonalRestriction);
68 if(transpose){
69 return ltmp.transposeBlock();
70 }
71 else {
72 return ltmp; //To change body of implemented methods use File | Settings | File Templates.
73 }
74 }
75
76 @Override
77 public XMLSyntaxRule[] getSyntaxRules() {
78 return rules;
79 }
80
81 private final XMLSyntaxRule[] rules = {
82 new ElementRule(Parameter.class, 0, Integer.MAX_VALUE),
83 AttributeRule.newBooleanRule(TRANSPOSE, true),
84 AttributeRule.newIntegerRule(COLUMN_DIMENSION, true),
85 AttributeRule.newBooleanRule(DIAGONAL_RESTRICTION, true),
86 };
87
88
89 @Override
90 public String getParserDescription() {
91 return "Returns a blockUpperTriangularMatrixParameter which is a compoundParameter which forces the last element to be of full length, the second to last element to be of full length-1, etc."; //To change body of implemented methods use File | Settings | File Templates.
92 }
93
94 @Override
95 public Class getReturnType() {
96 return BlockUpperTriangularMatrixParameter.class; //To change body of implemented methods use File | Settings | File Templates.
97 }
98
99 @Override
100 public String getParserName() {
101 return BLOCK_UPPER_TRIANGULAR_MATRIX; //To change body of implemented methods use File | Settings | File Templates.
102 }
103 }