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");
}
}
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;
}
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;
}
Aggregations