Debian Codegraph @

src/dr/evomodel/tree/randomlocalmodel/RLTVLogger.java

raw symbols SCIP
1 /*
2 * RLTVLogger.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.randomlocalmodel;
27
28 import dr.evolution.tree.NodeRef;
29 import dr.evomodel.tree.TreeModel;
30 import dr.inference.loggers.LogFormatter;
31 import dr.inference.loggers.MCLogger;
32
33 /**
34 * A logger for a random local tree variable.
35 * It logs only the selected parameters in pairs of node number, variable value
36 *
37 * @author Andrew Rambaut
38 * @author Alexei Drummond
39 * @version $Id: TreeLogger.java,v 1.25 2006/09/05 13:29:34 rambaut Exp $
40 */
41 public class RLTVLogger extends MCLogger {
42
43 private TreeModel treeModel;
44 private RandomLocalTreeVariable randomLocal;
45
46 public RLTVLogger(LogFormatter formatter,
47 int logEvery, TreeModel treeModel,
48 RandomLocalTreeVariable randomLocal) {
49
50 super(formatter, logEvery, false);
51 this.treeModel = treeModel;
52 this.randomLocal = randomLocal;
53 }
54
55 public void startLogging() {
56 logLine("State\tRate changes");
57 }
58
59 public void log(long state) {
60
61 if (logEvery <= 0 || ((state % logEvery) == 0)) {
62
63 int nodeCount = treeModel.getNodeCount();
64
65 StringBuilder builder = new StringBuilder();
66 builder.append(state);
67 for (int i = 0; i < nodeCount; i++) {
68
69 NodeRef node = treeModel.getNode(i);
70
71 if (randomLocal.isVariableSelected(treeModel, node)) {
72 builder.append("\t");
73 builder.append(node.getNumber());
74 builder.append("\t");
75 builder.append(randomLocal.getVariable(treeModel, node));
76 }
77 }
78
79 logLine(builder.toString());
80 }
81 }
82
83 public void stopLogging() {
84
85 super.stopLogging();
86 }
87
88 }