Search in sources :

Example 1 with BranchParameter

use of dr.inference.model.BranchParameter in project beast-mcmc by beast-dev.

the class LocationScaleGradientParser method parseTreeDataLikelihood.

private GradientWrtParameterProvider parseTreeDataLikelihood(XMLObject xo, TreeDataLikelihood treeDataLikelihood, String traitName, boolean useHessian) throws XMLParseException {
    BranchRateModel branchRateModel = treeDataLikelihood.getBranchRateModel();
    DataLikelihoodDelegate delegate = treeDataLikelihood.getDataLikelihoodDelegate();
    if (delegate instanceof ContinuousDataLikelihoodDelegate) {
        throw new XMLParseException("Not yet implemented! ");
    } else if (delegate instanceof BeagleDataLikelihoodDelegate) {
        BeagleDataLikelihoodDelegate beagleData = (BeagleDataLikelihoodDelegate) delegate;
        BranchModel branchModel = beagleData.getBranchModel();
        if (branchRateModel instanceof DefaultBranchRateModel || branchRateModel instanceof ArbitraryBranchRates) {
            if (xo.hasChildNamed(LOCATION)) {
                BranchSpecificFixedEffects location = parseLocation(xo);
                return new LocationGradient(traitName, treeDataLikelihood, beagleData, location, useHessian);
            } else if (xo.hasChildNamed(SCALE)) {
                Parameter scale = (Parameter) xo.getElementFirstChild(SCALE);
                return new ScaleGradient(traitName, treeDataLikelihood, beagleData, scale, useHessian);
            } else {
                throw new XMLParseException("Poorly formed");
            }
        } else if (branchModel instanceof ArbitrarySubstitutionParameterBranchModel) {
            BranchParameter branchParameter = (BranchParameter) xo.getChild(BranchParameter.class);
            if (xo.hasChildNamed(LOCATION)) {
                BranchSpecificFixedEffects location = parseLocation(xo);
                return new BranchSubstitutionParameterLocationGradient(traitName, treeDataLikelihood, beagleData, branchParameter, useHessian, location);
            } else if (xo.hasChildNamed(SCALE)) {
                Parameter scale = (Parameter) xo.getElementFirstChild(SCALE);
                return new BranchSubstitutionParameterScaleGradient(traitName, treeDataLikelihood, beagleData, branchParameter, scale, useHessian);
            } else {
                throw new XMLParseException("Not yet implemented.");
            }
        } else {
            throw new XMLParseException("Only implemented for an arbitrary rates model");
        }
    } else {
        throw new XMLParseException("Unknown likelihood delegate type");
    }
}
Also used : BranchParameter(dr.inference.model.BranchParameter) BeagleDataLikelihoodDelegate(dr.evomodel.treedatalikelihood.BeagleDataLikelihoodDelegate) ArbitrarySubstitutionParameterBranchModel(dr.evomodel.branchmodel.ArbitrarySubstitutionParameterBranchModel) BranchModel(dr.evomodel.branchmodel.BranchModel) DefaultBranchRateModel(dr.evomodel.branchratemodel.DefaultBranchRateModel) ArbitraryBranchRates(dr.evomodel.branchratemodel.ArbitraryBranchRates) ArbitrarySubstitutionParameterBranchModel(dr.evomodel.branchmodel.ArbitrarySubstitutionParameterBranchModel) BranchRateModel(dr.evomodel.branchratemodel.BranchRateModel) DefaultBranchRateModel(dr.evomodel.branchratemodel.DefaultBranchRateModel) ContinuousDataLikelihoodDelegate(dr.evomodel.treedatalikelihood.continuous.ContinuousDataLikelihoodDelegate) BeagleDataLikelihoodDelegate(dr.evomodel.treedatalikelihood.BeagleDataLikelihoodDelegate) DataLikelihoodDelegate(dr.evomodel.treedatalikelihood.DataLikelihoodDelegate) Parameter(dr.inference.model.Parameter) BranchParameter(dr.inference.model.BranchParameter) ContinuousDataLikelihoodDelegate(dr.evomodel.treedatalikelihood.continuous.ContinuousDataLikelihoodDelegate) BranchSpecificFixedEffects(dr.evomodel.branchratemodel.BranchSpecificFixedEffects)

Example 2 with BranchParameter

use of dr.inference.model.BranchParameter 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 3 with BranchParameter

use of dr.inference.model.BranchParameter in project beast-mcmc by beast-dev.

the class BranchParameterParser method parseXMLObject.

@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    Parameter rootParameter = (Parameter) xo.getChild(Parameter.class);
    BranchRateModel branchRates = (BranchRateModel) xo.getChild(BranchRateModel.class);
    TreeModel tree = (TreeModel) xo.getChild(TreeModel.class);
    BranchParameter branchParameter = new BranchParameter(xo.getName(), tree, branchRates, rootParameter);
    return branchParameter;
}
Also used : BranchParameter(dr.inference.model.BranchParameter) TreeModel(dr.evomodel.tree.TreeModel) BranchRateModel(dr.evomodel.branchratemodel.BranchRateModel) Parameter(dr.inference.model.Parameter) BranchParameter(dr.inference.model.BranchParameter)

Aggregations

BranchParameter (dr.inference.model.BranchParameter)3 Parameter (dr.inference.model.Parameter)3 ArbitrarySubstitutionParameterBranchModel (dr.evomodel.branchmodel.ArbitrarySubstitutionParameterBranchModel)2 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)2 TreeModel (dr.evomodel.tree.TreeModel)2 NodeRef (dr.evolution.tree.NodeRef)1 BranchModel (dr.evomodel.branchmodel.BranchModel)1 ArbitraryBranchRates (dr.evomodel.branchratemodel.ArbitraryBranchRates)1 BranchSpecificFixedEffects (dr.evomodel.branchratemodel.BranchSpecificFixedEffects)1 DefaultBranchRateModel (dr.evomodel.branchratemodel.DefaultBranchRateModel)1 BranchSpecificSubstitutionModelProvider (dr.evomodel.substmodel.BranchSpecificSubstitutionModelProvider)1 ParameterReplaceableSubstitutionModel (dr.evomodel.substmodel.ParameterReplaceableSubstitutionModel)1 SubstitutionModel (dr.evomodel.substmodel.SubstitutionModel)1 BeagleDataLikelihoodDelegate (dr.evomodel.treedatalikelihood.BeagleDataLikelihoodDelegate)1 DataLikelihoodDelegate (dr.evomodel.treedatalikelihood.DataLikelihoodDelegate)1 ContinuousDataLikelihoodDelegate (dr.evomodel.treedatalikelihood.continuous.ContinuousDataLikelihoodDelegate)1 ArrayList (java.util.ArrayList)1