-
Notifications
You must be signed in to change notification settings - Fork 12
/
BDSParameterization.java
80 lines (64 loc) · 2.32 KB
/
BDSParameterization.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package bdsky;
import beast.core.CalculationNode;
import beast.core.Input;
import beast.core.parameter.RealParameter;
import java.util.ArrayList;
import java.util.List;
/**
* A parameterization of the birth-death skyline model
*/
public abstract class BDSParameterization extends CalculationNode {
MultiSkyline multiSkyline;
public Input<RealParameter> origin =
new Input<RealParameter>("origin", "The time from origin to last sample (must be larger than tree height)", Input.Validate.REQUIRED);
public final void setMultiSkyline(MultiSkyline multiSkyline) {
this.multiSkyline = multiSkyline;
}
/**
* @return the canonical segments for this skyline model.
*/
public final List<BDSSkylineSegment> canonicalSegments(){
List<BDSSkylineSegment> canonical = new ArrayList<>();
for (SkylineSegment seg : multiSkyline.getSegments()) {
canonical.add(toCanonicalSegment(seg));
}
return canonical;
}
/**
* @return the number of segments in this parameterization.
*/
public final int size() {
return multiSkyline.getSegments().size();
}
public final void populateCanonical(Double[] birth, Double[] death, Double[] psi, Double[] r, Double[] times) {
int size = size();
if (birth.length != size || death.length != size || psi.length != size || r.length != size) {
throw new RuntimeException("array size unexpected!");
}
List<BDSSkylineSegment> canonicalSegments = canonicalSegments();
for (int i = 0; i < size; i++) {
BDSSkylineSegment seg = canonicalSegments.get(i);
birth[i] = seg.lambda();
death[i] = seg.mu();
psi[i] = seg.psi();
r[i] = seg.r();
times[i] = seg.start();
}
}
/**
* @return the time of the origin of the process before the present.
*/
public double origin() {
return origin.get().getValue();
}
/**
* @return true if any segments have a removalProbability < 1
*/
public final boolean isSampledAncestorModel() {
for (BDSSkylineSegment seg : canonicalSegments()) {
if (seg.r() < 1.0) return true;
}
return false;
}
public abstract BDSSkylineSegment toCanonicalSegment(SkylineSegment segment);
}