Debian Codegraph @

src/dr/evomodel/branchratemodel/CompoundBranchRateModel.java

raw symbols SCIP
1 /*
2 * CompoundBranchRateModel.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.branchratemodel;
27
28 import dr.evolution.tree.NodeRef;
29 import dr.evolution.tree.Tree;
30 import dr.evomodelxml.branchratemodel.CompoundBranchRateModelParser;
31 import dr.inference.model.AbstractModel;
32 import dr.inference.model.Model;
33 import dr.inference.model.Parameter;
34 import dr.inference.model.Variable;
35
36 import java.util.ArrayList;
37 import java.util.Collection;
38 import java.util.List;
39
40 /**
41 * Takes a collection of BranchRateModels and returns the product of the respective rates. In order for this to
42 * work, one model should drive the actual rate of evolution and the others should be set up to provide
43 * relative rates.
44 * @author Andrew Rambaut
45 * @version $Id:=$
46 */
47 public class CompoundBranchRateModel extends AbstractBranchRateModel {
48
49 private final List<BranchRateModel> branchRateModels = new ArrayList<BranchRateModel>();
50
51 public CompoundBranchRateModel(Collection<BranchRateModel> branchRateModels) {
52 super(CompoundBranchRateModelParser.COMPOUND_BRANCH_RATE_MODEL);
53 for (BranchRateModel branchRateModel : branchRateModels) {
54 addModel(branchRateModel);
55 this.branchRateModels.add(branchRateModel);
56 }
57 }
58
59 public void handleModelChangedEvent(Model model, Object object, int index) {
60 if (index != -1) {
61 fireModelChanged(null, index);
62 } else {
63 fireModelChanged();
64 }
65 }
66
67 protected final void handleVariableChangedEvent(Variable variable, int index, Parameter.ChangeType type) {
68 }
69
70 protected void storeState() {
71 // nothing to do
72 }
73
74 protected void restoreState() {
75 // nothing to do
76 }
77
78 protected void acceptState() {
79 // nothing to do
80 }
81
82 public double getBranchRate(final Tree tree, final NodeRef node) {
83 double rate = 1.0;
84 for (BranchRateModel branchRateModel : branchRateModels) {
85 rate *= branchRateModel.getBranchRate(tree, node);
86 }
87 return rate;
88 }
89
90 }