Debian Codegraph @

src/dr/evomodel/treedatalikelihood/continuous/ContinuousRateTransformation.java

raw symbols SCIP
1 /*
2 * ContinuousRateTransformation.java
3 *
4 * Copyright (c) 2002-2016 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.treedatalikelihood.continuous;
27
28 import dr.evolution.tree.NodeRef;
29 import dr.evolution.tree.Tree;
30 import dr.evomodel.treedatalikelihood.RateRescalingScheme;
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 /**
37 * @author Marc A. Suchard
38 */
39
40 public interface ContinuousRateTransformation {
41
42 double getNormalization();
43
44 RateRescalingScheme getRateRescalingScheme();
45
46 class Default extends AbstractModel implements ContinuousRateTransformation {
47 private final Tree tree;
48
49 private final RateRescalingScheme scheme;
50
51 public Default(Tree tree, boolean scaleByTime, boolean useTreeLength) {
52 super("ContinuousRateTransformation");
53 this.tree = tree;
54
55 scheme = scaleByTime ?
56 (useTreeLength ?
57 RateRescalingScheme.TREE_LENGTH :
58 RateRescalingScheme.TREE_HEIGHT) :
59 RateRescalingScheme.NONE;
60
61 }
62
63 private static final boolean DEBUG = false;
64
65 public RateRescalingScheme getRateRescalingScheme() {
66 return scheme;
67 }
68
69 @Override
70 public double getNormalization() { // TODO Cache
71
72 double norm = 1.0;
73 switch (scheme) {
74 case TREE_LENGTH:
75 norm = 1.0 / getTreeLength();
76 break;
77 case TREE_HEIGHT:
78 norm = 1.0 / tree.getNodeHeight(tree.getRoot());
79 break;
80 }
81
82 if (DEBUG) {
83 System.out.println("CRT.gN = " + norm);
84 }
85
86 return norm;
87 }
88
89 private double getTreeLength() {
90 double treeLength = 0;
91 for (int i = 0; i < tree.getNodeCount(); i++) {
92 NodeRef node = tree.getNode(i);
93 if (!tree.isRoot(node)) {
94 treeLength += tree.getBranchLength(node);
95 }
96 }
97 return treeLength;
98 }
99
100 @Override
101 protected void handleModelChangedEvent(Model model, Object object, int index) {
102
103 }
104
105 @Override
106 protected void handleVariableChangedEvent(Variable variable, int index, Parameter.ChangeType type) {
107
108 }
109
110 @Override
111 protected void storeState() {
112
113 }
114
115 @Override
116 protected void restoreState() {
117
118 }
119
120 @Override
121 protected void acceptState() {
122
123 }
124 }
125 }