| 1 | /* |
| 2 | * ExponentialBranchLengthTreePrior.java |
| 3 | * |
| 4 | * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard |
| 5 | * |
| 6 | * This file is part of BEAST. |
| 7 | * See the NOTICE file distributed with this work for additional |
| 8 | * information regarding copyright ownership and licensing. |
| 9 | * |
| 10 | * BEAST is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU Lesser General Public License as |
| 12 | * published by the Free Software Foundation; either version 2 |
| 13 | * of the License, or (at your option) any later version. |
| 14 | * |
| 15 | * BEAST is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU Lesser General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU Lesser General Public |
| 21 | * License along with BEAST; if not, write to the |
| 22 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, |
| 23 | * Boston, MA 02110-1301 USA |
| 24 | */ |
| 25 | |
| 26 | package dr.oldevomodel.MSSD; |
| 27 | |
| 28 | import dr.evolution.tree.TreeUtils; |
| 29 | import dr.evomodel.tree.TreeModel; |
| 30 | import dr.inference.model.AbstractModelLikelihood; |
| 31 | import dr.inference.model.Model; |
| 32 | import dr.inference.model.Parameter; |
| 33 | import dr.inference.model.Variable; |
| 34 | import dr.math.GammaFunction; |
| 35 | |
| 36 | /** |
| 37 | * Package: alsDefaultPrior |
| 38 | * Description: |
| 39 | * <p/> |
| 40 | * <p/> |
| 41 | * Created by |
| 42 | * Alexander V. Alekseyenko ([email protected]) |
| 43 | * Date: Mar 14, 2008 |
| 44 | * Time: 12:47:07 PM |
| 45 | */ |
| 46 | public class ExponentialBranchLengthTreePrior extends AbstractModelLikelihood { |
| 47 | |
| 48 | TreeModel treeModel; |
| 49 | |
| 50 | public ExponentialBranchLengthTreePrior(TreeModel treeModel) { |
| 51 | super(null); |
| 52 | this.treeModel = treeModel; |
| 53 | } |
| 54 | |
| 55 | protected void handleModelChangedEvent(Model model, Object object, int index) { |
| 56 | //AUTOGENERATED METHOD IMPLEMENTATION |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * This method is called whenever a parameter is changed. |
| 61 | * <p/> |
| 62 | * It is strongly recommended that the model component sets a "dirty" flag and does no |
| 63 | * further calculations. Recalculation is typically done when the model component is asked for |
| 64 | * some information that requires them. This mechanism is 'lazy' so that this method |
| 65 | * can be safely called multiple times with minimal computational cost. |
| 66 | */ |
| 67 | protected final void handleVariableChangedEvent(Variable variable, int index, Parameter.ChangeType type) { |
| 68 | //AUTOGENERATED METHOD IMPLEMENTATION |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Additional state information, outside of the sub-model is stored by this call. |
| 73 | */ |
| 74 | protected void storeState() { |
| 75 | //AUTOGENERATED METHOD IMPLEMENTATION |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * After this call the model is guaranteed to have returned its extra state information to |
| 80 | * the values coinciding with the last storeState call. |
| 81 | * Sub-models are handled automatically and do not need to be considered in this method. |
| 82 | */ |
| 83 | protected void restoreState() { |
| 84 | //AUTOGENERATED METHOD IMPLEMENTATION |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * This call specifies that the current state is accept. Most models will not need to do anything. |
| 89 | * Sub-models are handled automatically and do not need to be considered in this method. |
| 90 | */ |
| 91 | protected void acceptState() { |
| 92 | //AUTOGENERATED METHOD IMPLEMENTATION |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Get the model. |
| 97 | * |
| 98 | * @return the model. |
| 99 | */ |
| 100 | public Model getModel() { |
| 101 | return this; //AUTOGENERATED METHOD IMPLEMENTATION |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Get the log likelihood. |
| 106 | * |
| 107 | * @return the log likelihood. |
| 108 | */ |
| 109 | public double getLogLikelihood() { |
| 110 | return calculateLogLikelihood(); |
| 111 | } |
| 112 | |
| 113 | public double calculateLogLikelihood() { |
| 114 | int L = treeModel.getNodeCount(); |
| 115 | |
| 116 | double totalTreeTime = TreeUtils.getTreeLength(treeModel, treeModel.getRoot()); |
| 117 | |
| 118 | // if(ctmcScale != null){ // |
| 119 | // double ab=ctmcScale.getParameterValue(0); |
| 120 | // return GammaFunction.lnGamma(L)-Math.log(mu*lam)-(L-1)*Math.log(totalTreeTime)-0.5*Math.log(ab)-ab*totalTreeTime; |
| 121 | // }else{ // No Markov Chain for this model |
| 122 | return GammaFunction.lnGamma(L) - (L - 1) * Math.log(totalTreeTime); |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Forces a complete recalculation of the likelihood next time getLikelihood is called |
| 127 | */ |
| 128 | public void makeDirty() { |
| 129 | //AUTOGENERATED METHOD IMPLEMENTATION |
| 130 | } |
| 131 | } |