Debian Codegraph @

src/dr/evomodel/coalescent/CoalescentLikelihood.java

raw symbols SCIP
1 /*
2 * CoalescentLikelihood.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.coalescent;
27
28 import dr.evolution.coalescent.Coalescent;
29 import dr.evolution.coalescent.DemographicFunction;
30 import dr.evolution.tree.Tree;
31 import dr.evolution.tree.TreeUtils;
32 import dr.evolution.util.TaxonList;
33 import dr.evolution.util.Units;
34 import dr.evomodelxml.coalescent.CoalescentLikelihoodParser;
35
36 import java.util.List;
37 import java.util.logging.Logger;
38
39
40 /**
41 * A likelihood function for the coalescent. Takes a tree and a demographic model.
42 *
43 * Parts of this class were derived from C++ code provided by Oliver Pybus.
44 *
45 * @version $Id: NewCoalescentLikelihood.java,v 1.6 2005/05/24 20:25:57 rambaut Exp $
46 *
47 * @author Andrew Rambaut
48 * @author Alexei Drummond
49 */
50 public final class CoalescentLikelihood extends AbstractCoalescentLikelihood implements Units {
51
52 // PUBLIC STUFF
53 public CoalescentLikelihood(Tree tree,
54 TaxonList includeSubtree,
55 List<TaxonList> excludeSubtrees,
56 DemographicModel demoModel) throws TreeUtils.MissingTaxonException {
57
58 super(CoalescentLikelihoodParser.COALESCENT_LIKELIHOOD, tree, includeSubtree, excludeSubtrees);
59
60 this.demoModel = demoModel;
61
62 addModel(demoModel);
63 }
64
65 // **************************************************************
66 // Likelihood IMPLEMENTATION
67 // **************************************************************
68
69 /**
70 * Calculates the log likelihood of this set of coalescent intervals,
71 * given a demographic model.
72 */
73 public double calculateLogLikelihood() {
74
75 DemographicFunction demoFunction = demoModel.getDemographicFunction();
76
77 //double lnL = Coalescent.calculateLogLikelihood(getIntervals(), demoFunction);
78 double lnL = Coalescent.calculateLogLikelihood(getIntervals(), demoFunction, demoFunction.getThreshold());
79
80 if (Double.isNaN(lnL) || Double.isInfinite(lnL)) {
81 Logger.getLogger("warning").severe("CoalescentLikelihood for " + demoModel.getId() + " is " + Double.toString(lnL));
82 }
83
84 return lnL;
85 }
86
87 // **************************************************************
88 // Units IMPLEMENTATION
89 // **************************************************************
90
91 /**
92 * Sets the units these coalescent intervals are
93 * measured in.
94 */
95 public final void setUnits(Type u)
96 {
97 demoModel.setUnits(u);
98 }
99
100 /**
101 * Returns the units these coalescent intervals are
102 * measured in.
103 */
104 public final Type getUnits()
105 {
106 return demoModel.getUnits();
107 }
108
109 // ****************************************************************
110 // Private and protected stuff
111 // ****************************************************************
112
113 /** The demographic model. */
114 private DemographicModel demoModel = null;
115 }