Debian Codegraph @

src/dr/evomodelxml/continuous/BuildCompoundSymmetricMatrix.java

raw symbols SCIP
1 /*
2 * BuildCompoundSymmetricMatrix.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.evomodelxml.continuous;
27
28 import dr.inference.model.MatrixParameter;
29 import dr.xml.AbstractXMLObjectParser;
30 import dr.xml.XMLObject;
31 import dr.xml.XMLParseException;
32 import dr.inference.model.Parameter;
33 import dr.xml.XMLSyntaxRule;
34
35 /**
36 @author Max Tolkoff
37 */
38
39 //the existing compound symmetric matrix function creates a matrix that is structurally compound symmetric. This builds
40 //a compound symmetric matrix that can be non compound symmetric when exposed to a transition kernel
41 public class BuildCompoundSymmetricMatrix extends AbstractXMLObjectParser {
42 public final static String BUILD_DIAGONAL_MATRIX="buildCompoundSymmetricMatrix";
43 public final static String DIMENSION="dimension";
44 public final static String DIAGONAL="diagonal";
45 public final static String OFF_DIAGONAL="offDiagonal";
46
47
48 @Override
49 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
50 int dim=xo.getAttribute(DIMENSION,1);
51 int diag=xo.getAttribute(DIAGONAL,1);
52 int offDiag=xo.getAttribute(OFF_DIAGONAL, 0);
53 final String name = xo.hasId() ? xo.getId() : null;
54 Parameter[] answer = new Parameter[dim];
55
56
57
58 for (int i=0;i<dim; i++){
59 answer[i] = new Parameter.Default(dim);
60 for(int j=0; j<dim; j++)
61 {if(i==j) {
62 answer[i].setParameterValue(j, diag);
63 }
64 else
65 {answer[i].setParameterValue(j,offDiag);}
66 }}
67 return new MatrixParameter(name, answer);
68 }
69
70 @Override
71 public String getParserName() {
72 return BUILD_DIAGONAL_MATRIX;
73 }
74
75 @Override
76 public Class getReturnType() {
77 return MatrixParameter.class;
78 }
79
80 @Override
81 public XMLSyntaxRule[] getSyntaxRules() {
82 return new XMLSyntaxRule[0]; //To change body of implemented methods use File | Settings | File Templates.
83 }
84
85 @Override
86 public String getParserDescription() {
87 return "Returns a compound symmetric Matrix Parameter that is flexible, i.e. when exposed to a transition kernel can yield a result that is not compound symmetric"; //To change body of implemented methods use File | Settings | File Templates.
88 }
89 }