-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
143 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
...dr/evomodel/treedatalikelihood/discrete/AffineCorrectedSubstitutionParameterDelegate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* DiscreteTraitBranchSubstitutionParameterDelegate.java | ||
* | ||
* Copyright (c) 2002-2017 Alexei Drummond, Andrew Rambaut and Marc Suchard | ||
* | ||
* This file is part of BEAST. | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership and licensing. | ||
* | ||
* BEAST is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* BEAST is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with BEAST; if not, write to the | ||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, | ||
* Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
package dr.evomodel.treedatalikelihood.discrete; | ||
|
||
import dr.evolution.tree.NodeRef; | ||
import dr.evolution.tree.Tree; | ||
import dr.evomodel.branchratemodel.BranchRateModel; | ||
import dr.evomodel.treedatalikelihood.BeagleDataLikelihoodDelegate; | ||
import dr.evomodel.treedatalikelihood.preorder.AbstractBeagleBranchGradientDelegate; | ||
|
||
/** | ||
* @author Andrew Holbrook | ||
* @author Marc A. Suchard | ||
*/ | ||
public class AffineCorrectedSubstitutionParameterDelegate extends AbstractBeagleBranchGradientDelegate { | ||
|
||
private final BranchRateModel branchRateModel; | ||
private final BranchDifferentialMassProvider branchDifferentialMassProvider; | ||
private final String name; | ||
|
||
private static final String GRADIENT_TRAIT_NAME = "affineCorrectedSubstitutionGradient"; | ||
private static final String HESSIAN_TRAIT_NAME = "affineCorrectedSubstitutionHessian"; | ||
|
||
public AffineCorrectedSubstitutionParameterDelegate(String name, | ||
Tree tree, | ||
BeagleDataLikelihoodDelegate likelihoodDelegate, | ||
BranchRateModel branchRateModel, | ||
BranchDifferentialMassProvider branchDifferentialMassProvider) { | ||
super(name, tree, likelihoodDelegate); | ||
this.name = name; | ||
this.branchRateModel = branchRateModel; | ||
this.branchDifferentialMassProvider = branchDifferentialMassProvider; | ||
} | ||
|
||
@Override | ||
protected void cacheDifferentialMassMatrix(Tree tree, boolean cacheSquaredMatrix) { | ||
for (int i = 0; i < tree.getNodeCount(); i++) { | ||
NodeRef node = tree.getNode(i); | ||
if (!tree.isRoot(node)) { | ||
|
||
final double time = tree.getBranchLength(node) * branchRateModel.getBranchRate(tree, node); | ||
double[] differentialMassMatrix = branchDifferentialMassProvider.getDifferentialMassMatrixForBranch(node, time); | ||
double[] scaledDifferentialMassMatrix = DiscreteTraitBranchRateDelegate.scaleInfinitesimalMatrixByRates(differentialMassMatrix, | ||
DiscreteTraitBranchRateDelegate.DifferentialChoice.GRADIENT, siteRateModel); | ||
evolutionaryProcessDelegate.cacheFirstOrderDifferentialMatrix(beagle, i, scaledDifferentialMassMatrix); | ||
} | ||
} | ||
if (cacheSquaredMatrix) { | ||
throw new RuntimeException("Not yet implemented!"); | ||
} | ||
} | ||
|
||
@Override | ||
protected int getFirstDerivativeMatrixBufferIndex(int nodeNum) { | ||
return evolutionaryProcessDelegate.getFirstOrderDifferentialMatrixBufferIndex(nodeNum); | ||
} | ||
|
||
@Override | ||
protected int getSecondDerivativeMatrixBufferIndex(int nodeNum) { | ||
return evolutionaryProcessDelegate.getSecondOrderDifferentialMatrixBufferIndex(nodeNum); | ||
} | ||
|
||
protected String getGradientTraitName() { | ||
return GRADIENT_TRAIT_NAME + ":" + name; | ||
} | ||
|
||
protected String getHessianTraitName() { | ||
return HESSIAN_TRAIT_NAME + ":" + name; | ||
} | ||
|
||
public static String getName(String name) { | ||
return GRADIENT_TRAIT_NAME + ":" + name; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters