Search in sources :

Example 1 with ParameterReplaceableSubstitutionModel

use of dr.evomodel.substmodel.ParameterReplaceableSubstitutionModel in project beast-mcmc by beast-dev.

the class ArbitrarySubstitutionParameterBranchModelParser method parseXMLObject.

@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    Logger.getLogger("dr.evomodel").info("\nUsing branch-specific substitution parameter branch model.");
    TreeModel tree = (TreeModel) xo.getChild(TreeModel.class);
    SubstitutionModel substitutionModel = (SubstitutionModel) xo.getChild(SubstitutionModel.class);
    if (!(substitutionModel instanceof ParameterReplaceableSubstitutionModel)) {
        throw new RuntimeException("The substitution model is not parameter replaceable!");
    }
    XMLObject cxo = xo.getChild(BRANCH_SPECIFIC_PARAMETER);
    // XMLObject dxo = xo.getChild(SINGLE_RATE);
    BranchSpecificSubstitutionModelProvider substitutionModelProvider;
    ArbitrarySubstitutionParameterBranchModel branchParameterModel;
    // assert (dxo.getChildCount() == cxo.getChildCount());
    List<Parameter> oldParameters = new ArrayList<Parameter>();
    List<BranchParameter> parameterList = new ArrayList<BranchParameter>();
    for (int i = 0; i < cxo.getChildCount(); i++) {
        // Parameter rootParameter = (Parameter) dxo.getChild(i);
        // ArbitraryBranchRates branchRateModel = (ArbitraryBranchRates) cxo.getChild(i);
        // BranchParameter branchParameter = new BranchParameter("branchSpecific.substitution.parameter",
        // tree,
        // branchRateModel,
        // rootParameter);
        // branchParameter.setId("branchSpecific." + rootParameter.getId());
        // parameterList.add(branchParameter);
        // xo.setNativeObject(branchParameter);
        BranchParameter branchParameter = (BranchParameter) cxo.getChild(i);
        parameterList.add(branchParameter);
        oldParameters.add(branchParameter.getRootParameter());
    }
    List<SubstitutionModel> substitutionModelList = new ArrayList<SubstitutionModel>();
    ParameterReplaceableSubstitutionModel rootSubstitutionModel = (ParameterReplaceableSubstitutionModel) substitutionModel;
    // List<Parameter> oldParameters = parseParameters(dxo);
    // List<Parameter> branchParameters = parseParameters(cxo);
    final int parameterCount = parameterList.size();
    int v = 0;
    for (int nodeNum = 0; nodeNum < tree.getNodeCount(); ++nodeNum) {
        NodeRef node = tree.getNode(nodeNum);
        ParameterReplaceableSubstitutionModel branchSubstitutionModel = (ParameterReplaceableSubstitutionModel) substitutionModel;
        List<Parameter> newParameters = new ArrayList<Parameter>();
        if (tree.isRoot(node)) {
            for (int i = 0; i < parameterCount; i++) {
                BranchParameter branchParameter = parameterList.get(i);
                newParameters.add(branchParameter.getRootParameter());
            }
        } else {
            for (int i = 0; i < parameterCount; i++) {
                BranchParameter branchParameter = parameterList.get(i);
                newParameters.add(branchParameter.getParameter(v));
            }
            v++;
        }
        branchSubstitutionModel = branchSubstitutionModel.factory(oldParameters, newParameters);
        substitutionModelList.add(branchSubstitutionModel);
    }
    substitutionModelProvider = new BranchSpecificSubstitutionModelProvider.Default(substitutionModelList, tree);
    branchParameterModel = new ArbitrarySubstitutionParameterBranchModel(ARBITRARY_SUBSTITUTION_PARAMETER_BRANCH_MODEL, substitutionModelProvider, parameterList, tree);
    return branchParameterModel;
}
Also used : BranchParameter(dr.inference.model.BranchParameter) ParameterReplaceableSubstitutionModel(dr.evomodel.substmodel.ParameterReplaceableSubstitutionModel) ArrayList(java.util.ArrayList) BranchSpecificSubstitutionModelProvider(dr.evomodel.substmodel.BranchSpecificSubstitutionModelProvider) ParameterReplaceableSubstitutionModel(dr.evomodel.substmodel.ParameterReplaceableSubstitutionModel) SubstitutionModel(dr.evomodel.substmodel.SubstitutionModel) TreeModel(dr.evomodel.tree.TreeModel) NodeRef(dr.evolution.tree.NodeRef) ArbitrarySubstitutionParameterBranchModel(dr.evomodel.branchmodel.ArbitrarySubstitutionParameterBranchModel) Parameter(dr.inference.model.Parameter) BranchParameter(dr.inference.model.BranchParameter)

Example 2 with ParameterReplaceableSubstitutionModel

use of dr.evomodel.substmodel.ParameterReplaceableSubstitutionModel in project beast-mcmc by beast-dev.

the class BranchSpecificSubstitutionParameterBranchModelParser method parseXMLObject.

@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    List<Parameter> parameters = new ArrayList<>();
    for (XMLObject xoc : xo.getAllChildren(OLD_PARAMETER)) {
        Parameter parameter = (Parameter) xoc.getChild(Parameter.class);
        parameters.add(parameter);
    }
    List<BranchRateModel> branchRateModels = new ArrayList<>();
    for (XMLObject xoc : xo.getAllChildren(NEW_PARAMETER)) {
        BranchRateModel branchRateModel = (BranchRateModel) xoc.getChild(BranchRateModel.class);
        branchRateModels.add(branchRateModel);
    }
    ParameterReplaceableSubstitutionModel substitutionModel = (ParameterReplaceableSubstitutionModel) xo.getChild(ParameterReplaceableSubstitutionModel.class);
    TreeModel tree = (TreeModel) xo.getChild(TreeModel.class);
    return new BranchSpecificSubstitutionParameterBranchModel(BRANCH_SPECIFIC_SUBSTITUTION_PARAMETER_BRANCH_MODEL, parameters, branchRateModels, substitutionModel, tree);
}
Also used : TreeModel(dr.evomodel.tree.TreeModel) BranchRateModel(dr.evomodel.branchratemodel.BranchRateModel) ArrayList(java.util.ArrayList) ParameterReplaceableSubstitutionModel(dr.evomodel.substmodel.ParameterReplaceableSubstitutionModel) Parameter(dr.inference.model.Parameter) BranchSpecificSubstitutionParameterBranchModel(dr.evomodel.branchmodel.BranchSpecificSubstitutionParameterBranchModel)

Aggregations

ParameterReplaceableSubstitutionModel (dr.evomodel.substmodel.ParameterReplaceableSubstitutionModel)2 TreeModel (dr.evomodel.tree.TreeModel)2 Parameter (dr.inference.model.Parameter)2 ArrayList (java.util.ArrayList)2 NodeRef (dr.evolution.tree.NodeRef)1 ArbitrarySubstitutionParameterBranchModel (dr.evomodel.branchmodel.ArbitrarySubstitutionParameterBranchModel)1 BranchSpecificSubstitutionParameterBranchModel (dr.evomodel.branchmodel.BranchSpecificSubstitutionParameterBranchModel)1 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)1 BranchSpecificSubstitutionModelProvider (dr.evomodel.substmodel.BranchSpecificSubstitutionModelProvider)1 SubstitutionModel (dr.evomodel.substmodel.SubstitutionModel)1 BranchParameter (dr.inference.model.BranchParameter)1