Debian Codegraph @

src/dr/inferencexml/model/MatrixMatrixProductParser.java

raw symbols SCIP
1 /*
2 * MatrixMatrixProductParser.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.CompoundParameter;
29 import dr.inference.model.MatrixMatrixProduct;
30 import dr.inference.model.MatrixParameter;
31 import dr.inference.model.Parameter;
32 import dr.xml.*;
33
34 /**
35 * Created by max on 10/22/14.
36 */
37 public class MatrixMatrixProductParser extends AbstractXMLObjectParser {
38 final static String MATRIX_MATRIX_PRODUCT = "matrixMatrixProduct";
39 final static String LEFT="left";
40 final static String RIGHT="right";
41 final static String IN_PLACE="InPlace";
42 final static String COLUMN_MASK="ColumnMask";
43 private final XMLSyntaxRule[] rules = {
44 new ElementRule(LEFT, MatrixParameter.class),
45 new ElementRule(RIGHT, CompoundParameter.class),
46 new ElementRule(COLUMN_MASK, Parameter.class, "Only some columns need to be multiplied", true),
47 new ElementRule(IN_PLACE, MatrixParameter.class, "Matrix values that are returned", true)
48 };
49
50 @Override
51 public Object parseXMLObject (XMLObject xo)throws XMLParseException {
52 MatrixParameter[] temp=new MatrixParameter[3];
53 temp[0]=(MatrixParameter) xo.getChild(LEFT).getChild(MatrixParameter.class);
54 temp[1]=MatrixParameter.recast(((CompoundParameter) xo.getChild(RIGHT).getChild(CompoundParameter.class)).getVariableName(), (CompoundParameter) xo.getChild(RIGHT).getChild(CompoundParameter.class));
55 if(xo.getChild(IN_PLACE)!=null){
56 temp[2]=(MatrixParameter) xo.getChild(IN_PLACE).getChild(MatrixParameter.class);
57 }
58 else{
59 int rowDim=temp[0].getRowDimension();
60 int colDim=temp[1].getColumnDimension();
61 Parameter[] params=new Parameter[colDim];
62 for (int i = 0; i <colDim ; i++) {
63 params[i]=new Parameter.Default(rowDim);
64 }
65 temp[2]=new MatrixParameter(null, params);
66 }
67 Parameter ColumnMask;
68 if(xo.getChild(COLUMN_MASK)!=null)
69 ColumnMask=(Parameter) xo.getChild(COLUMN_MASK).getChild(MatrixParameter.class);
70 else
71 ColumnMask=new Parameter.Default(null, temp[1].getColumnDimension(), 1);
72 return new MatrixMatrixProduct(temp, ColumnMask);
73 }
74
75 @Override
76 public XMLSyntaxRule[] getSyntaxRules () {
77 return rules;
78 }
79
80 @Override
81 public String getParserDescription () {
82 return "Gets Latent Factor Model to return data with residuals computed";
83 }
84
85 @Override
86 public Class getReturnType () {
87 return MatrixMatrixProduct.class;
88 }
89
90 @Override
91 public String getParserName () {
92 return MATRIX_MATRIX_PRODUCT;
93 }
94 };