Search in sources :

Example 1 with BranchSpecificGradient

use of dr.evomodel.treedatalikelihood.continuous.BranchSpecificGradient in project beast-mcmc by beast-dev.

the class AttenuationGradientParser method parseXMLObject.

@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    String traitName = xo.getAttribute(TRAIT_NAME, DEFAULT_TRAIT_NAME);
    MatrixParameterInterface parameter = (MatrixParameterInterface) xo.getChild(MatrixParameterInterface.class);
    TreeDataLikelihood treeDataLikelihood = (TreeDataLikelihood) xo.getChild(TreeDataLikelihood.class);
    DataLikelihoodDelegate delegate = treeDataLikelihood.getDataLikelihoodDelegate();
    int dim = treeDataLikelihood.getDataLikelihoodDelegate().getTraitDim();
    Tree tree = treeDataLikelihood.getTree();
    ContinuousDataLikelihoodDelegate continuousData = (ContinuousDataLikelihoodDelegate) delegate;
    ContinuousTraitGradientForBranch.ContinuousProcessParameterGradient traitGradient = new ContinuousTraitGradientForBranch.ContinuousProcessParameterGradient(dim, tree, continuousData, new ArrayList<ContinuousTraitGradientForBranch.ContinuousProcessParameterGradient.DerivationParameter>(Arrays.asList(ContinuousTraitGradientForBranch.ContinuousProcessParameterGradient.DerivationParameter.WRT_DIAGONAL_SELECTION_STRENGTH)));
    BranchSpecificGradient branchSpecificGradient = new BranchSpecificGradient(traitName, treeDataLikelihood, continuousData, traitGradient, parameter);
    ParameterMode parameterMode = parseParameterMode(xo);
    return parameterMode.factory(branchSpecificGradient, treeDataLikelihood, parameter);
}
Also used : BranchSpecificGradient(dr.evomodel.treedatalikelihood.continuous.BranchSpecificGradient) MatrixParameterInterface(dr.inference.model.MatrixParameterInterface) TreeDataLikelihood(dr.evomodel.treedatalikelihood.TreeDataLikelihood) ContinuousDataLikelihoodDelegate(dr.evomodel.treedatalikelihood.continuous.ContinuousDataLikelihoodDelegate) DataLikelihoodDelegate(dr.evomodel.treedatalikelihood.DataLikelihoodDelegate) Tree(dr.evolution.tree.Tree) ContinuousDataLikelihoodDelegate(dr.evomodel.treedatalikelihood.continuous.ContinuousDataLikelihoodDelegate) ContinuousTraitGradientForBranch(dr.evomodel.treedatalikelihood.continuous.ContinuousTraitGradientForBranch)

Example 2 with BranchSpecificGradient

use of dr.evomodel.treedatalikelihood.continuous.BranchSpecificGradient in project beast-mcmc by beast-dev.

the class DiffusionGradientParser method parseXMLObject.

@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    String traitName = xo.getAttribute(TRAIT_NAME, DEFAULT_TRAIT_NAME);
    List<ContinuousTraitGradientForBranch.ContinuousProcessParameterGradient.DerivationParameter> derivationParametersList = new ArrayList<ContinuousTraitGradientForBranch.ContinuousProcessParameterGradient.DerivationParameter>();
    CompoundParameter compoundParameter = new CompoundParameter(null);
    List<GradientWrtParameterProvider> derivativeList = new ArrayList<GradientWrtParameterProvider>();
    List<AbstractDiffusionGradient> diffGradients = xo.getAllChildren(AbstractDiffusionGradient.class);
    if (diffGradients != null) {
        for (AbstractDiffusionGradient grad : diffGradients) {
            derivationParametersList.add(grad.getDerivationParameter());
            compoundParameter.addParameter(grad.getRawParameter());
            derivativeList.add(grad);
        }
    }
    CompoundGradient parametersGradients = new CompoundDerivative(derivativeList);
    // testSameModel(precisionGradient, attenuationGradient);
    TreeDataLikelihood treeDataLikelihood = ((TreeDataLikelihood) diffGradients.get(0).getLikelihood());
    DataLikelihoodDelegate delegate = treeDataLikelihood.getDataLikelihoodDelegate();
    int dim = treeDataLikelihood.getDataLikelihoodDelegate().getTraitDim();
    Tree tree = treeDataLikelihood.getTree();
    ContinuousDataLikelihoodDelegate continuousData = (ContinuousDataLikelihoodDelegate) delegate;
    ContinuousTraitGradientForBranch.ContinuousProcessParameterGradient traitGradient = new ContinuousTraitGradientForBranch.ContinuousProcessParameterGradient(dim, tree, continuousData, derivationParametersList);
    BranchSpecificGradient branchSpecificGradient = new BranchSpecificGradient(traitName, treeDataLikelihood, continuousData, traitGradient, compoundParameter);
    return new DiffusionParametersGradient(branchSpecificGradient, parametersGradients);
}
Also used : CompoundGradient(dr.inference.hmc.CompoundGradient) BranchSpecificGradient(dr.evomodel.treedatalikelihood.continuous.BranchSpecificGradient) AbstractDiffusionGradient(dr.evomodel.treedatalikelihood.hmc.AbstractDiffusionGradient) ArrayList(java.util.ArrayList) CompoundParameter(dr.inference.model.CompoundParameter) DiffusionParametersGradient(dr.evomodel.treedatalikelihood.hmc.DiffusionParametersGradient) TreeDataLikelihood(dr.evomodel.treedatalikelihood.TreeDataLikelihood) ContinuousDataLikelihoodDelegate(dr.evomodel.treedatalikelihood.continuous.ContinuousDataLikelihoodDelegate) DataLikelihoodDelegate(dr.evomodel.treedatalikelihood.DataLikelihoodDelegate) CompoundDerivative(dr.inference.hmc.CompoundDerivative) GradientWrtParameterProvider(dr.inference.hmc.GradientWrtParameterProvider) Tree(dr.evolution.tree.Tree) ContinuousTraitGradientForBranch(dr.evomodel.treedatalikelihood.continuous.ContinuousTraitGradientForBranch) ContinuousDataLikelihoodDelegate(dr.evomodel.treedatalikelihood.continuous.ContinuousDataLikelihoodDelegate)

Aggregations

Tree (dr.evolution.tree.Tree)2 DataLikelihoodDelegate (dr.evomodel.treedatalikelihood.DataLikelihoodDelegate)2 TreeDataLikelihood (dr.evomodel.treedatalikelihood.TreeDataLikelihood)2 BranchSpecificGradient (dr.evomodel.treedatalikelihood.continuous.BranchSpecificGradient)2 ContinuousDataLikelihoodDelegate (dr.evomodel.treedatalikelihood.continuous.ContinuousDataLikelihoodDelegate)2 ContinuousTraitGradientForBranch (dr.evomodel.treedatalikelihood.continuous.ContinuousTraitGradientForBranch)2 AbstractDiffusionGradient (dr.evomodel.treedatalikelihood.hmc.AbstractDiffusionGradient)1 DiffusionParametersGradient (dr.evomodel.treedatalikelihood.hmc.DiffusionParametersGradient)1 CompoundDerivative (dr.inference.hmc.CompoundDerivative)1 CompoundGradient (dr.inference.hmc.CompoundGradient)1 GradientWrtParameterProvider (dr.inference.hmc.GradientWrtParameterProvider)1 CompoundParameter (dr.inference.model.CompoundParameter)1 MatrixParameterInterface (dr.inference.model.MatrixParameterInterface)1 ArrayList (java.util.ArrayList)1