Debian Codegraph @

src/dr/oldevomodel/MSSD/ALSTreeLikelihood.java

raw symbols SCIP
1 /*
2 * ALSTreeLikelihood.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.alignment.PatternList;
29 import dr.evomodel.branchratemodel.BranchRateModel;
30 import dr.oldevomodel.sitemodel.SiteModel;
31 import dr.evomodel.tree.TreeModel;
32 import dr.evomodel.treelikelihood.LikelihoodScalingProvider;
33 import dr.oldevomodel.treelikelihood.ScaleFactorsHelper;
34 import dr.oldevomodel.treelikelihood.TreeLikelihood;
35 import dr.inference.model.Model;
36
37 /**
38 * Package: ALSTreeLikelihood
39 * Description:
40 * <p/>
41 * <p/>
42 * Created by
43 * Alexander V. Alekseyenko ([email protected])
44 * Date: Feb 13, 2008
45 * Time: 10:13:07 AM
46 */
47 public class ALSTreeLikelihood extends TreeLikelihood {
48
49 protected AbstractObservationProcess observationProcess;
50
51 public ALSTreeLikelihood(AbstractObservationProcess observationProcess, PatternList patternList, TreeModel treeModel,
52 SiteModel siteModel, BranchRateModel branchRateModel, boolean useAmbiguities,
53 boolean storePartials, boolean forceRescaling) {
54 super(patternList, treeModel, siteModel, branchRateModel, null, useAmbiguities, false, storePartials, false, forceRescaling);
55
56 this.observationProcess = observationProcess;
57 addModel(observationProcess);
58
59 // TreeLikelihood does not initialize the partials for tips, we'll do it ourselves
60 int extNodeCount = treeModel.getExternalNodeCount();
61 for (int i = 0; i < extNodeCount; i++) {
62 String id = treeModel.getTaxonId(i);
63 int index = patternList.getTaxonIndex(id);
64 setPartials(likelihoodCore, patternList, categoryCount, index, i);
65 }
66
67 /* //Examine the tree
68 double totalTime=0.0;
69 double realTime = 0.0;
70 for(int i=0; i<treeModel.getNodeCount();++i){
71 NodeRef node = treeModel.getNode(i);
72 double branchRate = branchRateModel.getBranchRate(treeModel,node);
73 double branchTime = treeModel.getBranchLength(node);
74 totalTime+=branchRate*branchTime;
75 realTime += branchTime;
76 System.err.println("Node "+node.toString()+ " time: "+branchTime+ " rate "+branchRate+" together "+branchTime*branchRate);
77 }
78 System.err.println("TotalTime: "+totalTime);
79 System.err.println("RealTime: "+realTime);*/
80
81 scaleFactorsHelper = new ScaleFactorsHelper((LikelihoodScalingProvider) likelihoodCore, this,
82 treeModel, stateCount, patternCount, categoryCount);
83 }
84
85 protected double calculateLogLikelihood() {
86 // Calculate the partial likelihoods
87 super.calculateLogLikelihood();
88 // get the frequency model
89 double[] freqs = frequencyModel.getFrequencies();
90 // let the observationProcess handle the rest
91 scaleFactorsHelper.resetScaleFactors();
92 return observationProcess.nodePatternLikelihood(freqs, likelihoodCore, scaleFactorsHelper);
93 }
94
95 protected void handleModelChangedEvent(Model model, Object object, int index) {
96 if (model == observationProcess) {
97 likelihoodKnown = false;
98 } else {
99 super.handleModelChangedEvent(model, object, index);
100 }
101 }
102
103 final private ScaleFactorsHelper scaleFactorsHelper;
104 }