Debian Codegraph @

src/dr/evomodel/speciation/BranchingLikelihood.java

raw symbols SCIP
1 /*
2 * BranchingLikelihood.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.evomodel.speciation;
27
28 import dr.evolution.tree.Tree;
29 import dr.evomodel.tree.TreeModel;
30 import dr.evomodelxml.speciation.BranchingLikelihoodParser;
31 import dr.inference.model.AbstractModelLikelihood;
32 import dr.inference.model.Model;
33 import dr.inference.model.Parameter;
34 import dr.inference.model.Variable;
35
36
37 /**
38 * A likelihood function for branching processes. Takes a tree and a branching model.
39 *
40 * @author Alexei Drummond
41 * @author Andrew Rambaut
42 * @version $Id: BranchingLikelihood.java,v 1.4 2004/12/14 21:00:58 alexei Exp $
43 */
44 public class BranchingLikelihood extends AbstractModelLikelihood {
45
46 // PUBLIC STUFF
47
48 public BranchingLikelihood(Tree tree, BranchingModel branchingModel) {
49 this(BranchingLikelihoodParser.BRANCHING_LIKELIHOOD, tree, branchingModel);
50 }
51
52 public BranchingLikelihood(String name, Tree tree, BranchingModel branchingModel) {
53
54 super(name);
55
56 this.tree = tree;
57 this.branchingModel = branchingModel;
58 if (tree instanceof TreeModel) {
59 addModel((TreeModel) tree);
60 }
61 if (branchingModel != null) {
62 addModel(branchingModel);
63 }
64 }
65
66 // **************************************************************
67 // Model IMPLEMENTATION
68 // **************************************************************
69
70
71 protected void handleModelChangedEvent(Model model, Object object, int index) {
72 }
73
74 protected final void handleVariableChangedEvent(Variable variable, int index, Parameter.ChangeType type) {
75 }
76
77 protected void storeState() {
78 }
79
80 protected void restoreState() {
81 }
82
83 protected final void acceptState() {
84 } // nothing to do
85
86 // **************************************************************
87 // Likelihood IMPLEMENTATION
88 // **************************************************************
89
90 public final Model getModel() {
91 return this;
92 }
93
94 public final double getLogLikelihood() {
95 return calculateLogLikelihood();
96
97 }
98
99 public final void makeDirty() {
100 }
101
102 /**
103 * Calculates the log likelihood of this set of tree nodes,
104 * given a branching model.
105 */
106 public double calculateLogLikelihood() {
107
108 double logL = 0.0;
109 for (int j = 0; j < tree.getInternalNodeCount(); j++) {
110 logL += branchingModel.logNodeProbability(tree, tree.getInternalNode(j));
111 }
112 //System.err.println("logL=" + logL);
113 return logL;
114 }
115
116 // **************************************************************
117 // XMLElement IMPLEMENTATION
118 // **************************************************************
119
120 public org.w3c.dom.Element createElement(org.w3c.dom.Document d) {
121 throw new RuntimeException("createElement not implemented");
122 }
123
124 // ****************************************************************
125 // Private and protected stuff
126 // ****************************************************************
127
128 /**
129 * The speciation model.
130 */
131 BranchingModel branchingModel = null;
132
133 /**
134 * The tree.
135 */
136 Tree tree = null;
137 }