Debian Codegraph @

src/dr/evomodel/tree/TrialTreeParameterModel.java

raw symbols SCIP
1 /*
2 * TrialTreeParameterModel.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.tree;
27
28 import dr.evolution.tree.MutableTreeModel;
29 import dr.evolution.tree.NodeRef;
30 import dr.evolution.tree.Tree;
31 import dr.inference.model.Parameter;
32
33 /**
34 * This class maintains a parameter of length equal to the number of nodes in the tree.
35 * It can optionally include the root node. If the root node is not included then this
36 * class will track tree changes that change the root node number and swap the parameter
37 * values so that the parameter values stay with their node when changes to the tree
38 * topology occur.
39 *
40 * @author Alexei Drummond
41 * @author Marc A. Suchard
42 */
43 public class TrialTreeParameterModel extends TreeParameterModel {
44
45 // public TrialTreeParameterModel(TreeModel tree, Parameter parameter, boolean includeRoot, boolean includeTips) {
46 // this(tree, parameter, includeRoot, includeTips, Intent.NODE);
47 // }
48
49 public TrialTreeParameterModel(MutableTreeModel tree, Parameter parameter, boolean includeRoot, boolean includeTips,
50 Intent intent) {
51 super(tree, parameter, includeRoot, intent);
52 this.includeTips = includeTips;
53 }
54
55 public int getParameterSize() {
56 int treeSize = super.getParameterSize();
57 if (!includeTips) {
58 treeSize -= tree.getExternalNodeCount();
59 }
60 return treeSize;
61 }
62
63 public int getNodeNumberFromParameterIndex(int parameterIndex) {
64 int number = super.getNodeNumberFromParameterIndex(parameterIndex);
65 if (!includeTips) {
66 number += tree.getExternalNodeCount();
67 }
68 return number;
69 }
70
71 public int getParameterIndexFromNodeNumber(int nodeNumber) {
72 int number = super.getParameterIndexFromNodeNumber(nodeNumber);
73 if (!includeTips) {
74 number -= tree.getExternalNodeCount();
75 }
76 return number;
77 }
78
79 public double getNodeValue(Tree tree, NodeRef node) {
80 assert (!tree.isExternal(node) && !includeTips) : "tip nodes do not have parameter values!";
81 return super.getNodeValue(tree, node);
82 }
83
84 public void setNodeValue(Tree tree, NodeRef node, double value) {
85 assert (!tree.isExternal(node) && !includeTips) : "tip nodes do not have parameter values!";
86 super.setNodeValue(tree, node, value);
87 }
88
89 private boolean includeTips = true;
90 // protected final Tree tree;
91
92 }