| 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.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 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 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]; |
| 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"; |
| 88 |
} |
| 89 |
} |