Debian Codegraph @

src/dr/evomodel/coalescent/CoalescentTreeIntervalStatistic.java

raw symbols SCIP
1 /*
2 * CoalescentTreeIntervalStatistic.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 /**
27 * @author Guy Baele
28 */
29
30 package dr.evomodel.coalescent;
31
32 import dr.evolution.coalescent.TreeIntervals;
33 import dr.evolution.tree.Tree;
34 import dr.inference.model.Statistic;
35
36 /**
37 * @author Guy Baele
38 */
39 public class CoalescentTreeIntervalStatistic extends Statistic.Abstract {
40
41 private Tree tree;
42 private TreeIntervals intervals;
43 private int dimension;
44 private double[] nonZeroIntervals;
45 private int[] lineageCounts;
46
47 public CoalescentTreeIntervalStatistic(Tree tree) {
48 this.tree = tree;
49 this.intervals = new TreeIntervals(tree);
50 //detect here if there are zero-length intervals and set the dimension accordingly
51 setDimension(intervals);
52 this.lineageCounts = new int[this.dimension];
53 this.nonZeroIntervals = new double[this.dimension];
54 removeZeroLengthIntervals(intervals);
55 }
56
57 public int getDimension() {
58 return this.dimension;
59 }
60
61 public double getStatisticValue(int i) {
62 //need more elegant way to trigger recalculation of intervals
63 if (i == 0) {
64 intervals.setIntervalsUnknown();
65 removeZeroLengthIntervals(intervals);
66 }
67
68 //double interval = intervals.getInterval(i);
69 //return interval;
70
71 return this.nonZeroIntervals[i];
72 }
73
74 public double getLineageCount(int i) {
75 //need more elegant way to trigger recalculation of intervals
76 if (i == 0) {
77 intervals.setIntervalsUnknown();
78 removeZeroLengthIntervals(intervals);
79 }
80
81 return this.lineageCounts[i];
82 }
83
84 public String getStatisticName() {
85 return "coalescentTreeIntervalStatistic";
86 }
87
88 private void setDimension(TreeIntervals intervals) {
89 int dim = intervals.getIntervalCount();
90 for (int i = 0; i < intervals.getIntervalCount(); i++) {
91 if (intervals.getInterval(i) == 0.0) {
92 dim--;
93 }
94 }
95 this.dimension = dim;
96 }
97
98 private void removeZeroLengthIntervals(TreeIntervals intervals) {
99 int dim = 0;
100 for (int i = 0; i < intervals.getIntervalCount(); i++) {
101 double intervalLength = intervals.getInterval(i);
102 if (intervalLength != 0.0) {
103 this.nonZeroIntervals[dim] = intervalLength;
104 this.lineageCounts[dim] = intervals.getLineageCount(i);
105 dim++;
106 }
107 }
108 }
109 }