| 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.inference.model; |
| 27 |
|
| 28 |
import dr.xml.*; |
| 29 |
|
| 30 |
import java.util.ArrayList; |
| 31 |
import java.util.List; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
public class CompoundMatrixParameter extends MatrixParameter { |
| 37 |
|
| 38 |
public CompoundMatrixParameter(String name, List<MatrixParameterInterface> matrices) { |
| 39 |
super(name, compoundMatrices(matrices)); |
| 40 |
} |
| 41 |
|
| 42 |
private static Parameter[] compoundMatrices(List<MatrixParameterInterface> matrices) { |
| 43 |
int length = 0; |
| 44 |
for (MatrixParameterInterface matrix : matrices) { |
| 45 |
length += matrix.getColumnDimension(); |
| 46 |
} |
| 47 |
|
| 48 |
Parameter[] parameters = new Parameter[length]; |
| 49 |
int index = 0; |
| 50 |
for (MatrixParameterInterface matrix : matrices) { |
| 51 |
for (int i = 0; i < matrix.getColumnDimension(); ++i) { |
| 52 |
parameters[index] = matrix.getParameter(i); |
| 53 |
++index; |
| 54 |
} |
| 55 |
} |
| 56 |
return parameters; |
| 57 |
} |
| 58 |
|
| 59 |
public final static String COMPOUND_MATRIX_PARAMETER = "compoundMatrixParameter"; |
| 60 |
|
| 61 |
public static XMLObjectParser PARSER = new AbstractXMLObjectParser() { |
| 62 |
|
| 63 |
public String getParserName() { |
| 64 |
return COMPOUND_MATRIX_PARAMETER; |
| 65 |
} |
| 66 |
|
| 67 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 68 |
|
| 69 |
List<MatrixParameterInterface> matrices = new ArrayList<MatrixParameterInterface>(); |
| 70 |
|
| 71 |
for (int i = 0; i < xo.getChildCount(); ++i) { |
| 72 |
matrices.add((MatrixParameterInterface) xo.getChild(i)); |
| 73 |
} |
| 74 |
|
| 75 |
final String name = xo.hasId() ? xo.getId() : null; |
| 76 |
|
| 77 |
return new CompoundMatrixParameter(name, matrices); |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
public String getParserDescription() { |
| 85 |
return "A compound matrix parameter constructed from its component parameters."; |
| 86 |
} |
| 87 |
|
| 88 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 89 |
return rules; |
| 90 |
} |
| 91 |
|
| 92 |
private final XMLSyntaxRule[] rules = { |
| 93 |
new ElementRule(MatrixParameter.class, 1, Integer.MAX_VALUE), |
| 94 |
}; |
| 95 |
|
| 96 |
public Class getReturnType() { |
| 97 |
return CompoundMatrixParameter.class; |
| 98 |
} |
| 99 |
}; |
| 100 |
} |