Search in sources :

Example 1 with BranchRateGradient

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

the class BranchRateGradientParser method parseTreeDataLikelihood.

private GradientWrtParameterProvider parseTreeDataLikelihood(TreeDataLikelihood treeDataLikelihood, String traitName, boolean useHessian) throws XMLParseException {
    BranchRateModel branchRateModel = treeDataLikelihood.getBranchRateModel();
    if (branchRateModel instanceof DefaultBranchRateModel || branchRateModel instanceof ArbitraryBranchRates) {
        Parameter branchRates = null;
        if (branchRateModel instanceof ArbitraryBranchRates) {
            branchRates = ((ArbitraryBranchRates) branchRateModel).getRateParameter();
        }
        DataLikelihoodDelegate delegate = treeDataLikelihood.getDataLikelihoodDelegate();
        if (delegate instanceof ContinuousDataLikelihoodDelegate) {
            ContinuousDataLikelihoodDelegate continuousData = (ContinuousDataLikelihoodDelegate) delegate;
            return new BranchRateGradient(traitName, treeDataLikelihood, continuousData, branchRates);
        } else if (delegate instanceof BeagleDataLikelihoodDelegate) {
            BeagleDataLikelihoodDelegate beagleData = (BeagleDataLikelihoodDelegate) delegate;
            if (branchRateModel instanceof LocalBranchRates) {
                return new LocalBranchRateGradientForDiscreteTrait(traitName, treeDataLikelihood, beagleData, branchRates, useHessian);
            } else {
                return new BranchRateGradientForDiscreteTrait(traitName, treeDataLikelihood, beagleData, branchRates, useHessian);
            }
        } else {
            throw new XMLParseException("Unknown likelihood delegate type");
        }
    } else {
        throw new XMLParseException("Only implemented for an arbitrary rates model");
    }
}
Also used : ArbitraryBranchRates(dr.evomodel.branchratemodel.ArbitraryBranchRates) 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) BranchRateGradient(dr.evomodel.treedatalikelihood.continuous.BranchRateGradient) BranchRateGradientForDiscreteTrait(dr.evomodel.treedatalikelihood.discrete.BranchRateGradientForDiscreteTrait) LocalBranchRateGradientForDiscreteTrait(dr.evomodel.treedatalikelihood.discrete.LocalBranchRateGradientForDiscreteTrait) LocalBranchRateGradientForDiscreteTrait(dr.evomodel.treedatalikelihood.discrete.LocalBranchRateGradientForDiscreteTrait) Parameter(dr.inference.model.Parameter) BeagleDataLikelihoodDelegate(dr.evomodel.treedatalikelihood.BeagleDataLikelihoodDelegate) ContinuousDataLikelihoodDelegate(dr.evomodel.treedatalikelihood.continuous.ContinuousDataLikelihoodDelegate) DefaultBranchRateModel(dr.evomodel.branchratemodel.DefaultBranchRateModel) LocalBranchRates(dr.evomodel.branchratemodel.LocalBranchRates)

Example 2 with BranchRateGradient

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

the class BranchRateGradientWrtIncrementsParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    AutoCorrelatedGradientWrtIncrements priorProvider = (AutoCorrelatedGradientWrtIncrements) xo.getChild(AutoCorrelatedGradientWrtIncrements.class);
    GradientWrtParameterProvider rateProvider = (GradientWrtParameterProvider) xo.getChild(GradientWrtParameterProvider.class);
    if (!(rateProvider instanceof BranchRateGradient) && !(rateProvider instanceof BranchRateGradientForDiscreteTrait)) {
        throw new XMLParseException("Must provide a branch rate gradient");
    }
    return new BranchRateGradientWrtIncrements(rateProvider, priorProvider);
}
Also used : BranchRateGradient(dr.evomodel.treedatalikelihood.continuous.BranchRateGradient) BranchRateGradientForDiscreteTrait(dr.evomodel.treedatalikelihood.discrete.BranchRateGradientForDiscreteTrait) GradientWrtParameterProvider(dr.inference.hmc.GradientWrtParameterProvider) AutoCorrelatedGradientWrtIncrements(dr.evomodel.branchratemodel.AutoCorrelatedGradientWrtIncrements) BranchRateGradientWrtIncrements(dr.evomodel.branchratemodel.BranchRateGradientWrtIncrements)

Aggregations

BranchRateGradient (dr.evomodel.treedatalikelihood.continuous.BranchRateGradient)2 BranchRateGradientForDiscreteTrait (dr.evomodel.treedatalikelihood.discrete.BranchRateGradientForDiscreteTrait)2 ArbitraryBranchRates (dr.evomodel.branchratemodel.ArbitraryBranchRates)1 AutoCorrelatedGradientWrtIncrements (dr.evomodel.branchratemodel.AutoCorrelatedGradientWrtIncrements)1 BranchRateGradientWrtIncrements (dr.evomodel.branchratemodel.BranchRateGradientWrtIncrements)1 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)1 DefaultBranchRateModel (dr.evomodel.branchratemodel.DefaultBranchRateModel)1 LocalBranchRates (dr.evomodel.branchratemodel.LocalBranchRates)1 BeagleDataLikelihoodDelegate (dr.evomodel.treedatalikelihood.BeagleDataLikelihoodDelegate)1 DataLikelihoodDelegate (dr.evomodel.treedatalikelihood.DataLikelihoodDelegate)1 ContinuousDataLikelihoodDelegate (dr.evomodel.treedatalikelihood.continuous.ContinuousDataLikelihoodDelegate)1 LocalBranchRateGradientForDiscreteTrait (dr.evomodel.treedatalikelihood.discrete.LocalBranchRateGradientForDiscreteTrait)1 GradientWrtParameterProvider (dr.inference.hmc.GradientWrtParameterProvider)1 Parameter (dr.inference.model.Parameter)1