| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 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 |
|
| 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 |
}; |