@@ -542,14 +542,18 @@ def __init__(
542
542
self .identity_constant .flags .writeable = False
543
543
self .timepoints .flags .writeable = False
544
544
545
- def to_gamma (self , edge ):
545
+ def to_gamma (self , edge , natural = False ):
546
546
"""
547
547
Return the shape and rate parameters of the (gamma) posterior of edge
548
- length, given an improper (constant) prior.
548
+ length, given an improper (constant) prior. If ``natural`` is ``True``,
549
+ return the natural parameterization instead.
549
550
"""
550
551
y = self .mut_edges [edge .id ]
551
552
mu = edge .span * self .mut_rate
552
- return np .array ([y + 1 , mu ])
553
+ if natural :
554
+ return np .array ([y , mu ])
555
+ else :
556
+ return np .array ([y + 1 , mu ])
553
557
554
558
@staticmethod
555
559
def get_mut_edges (ts ):
@@ -973,7 +977,7 @@ def __init__(self, *args, **kwargs):
973
977
# and can be incorporated into the posterior beforehand
974
978
for edge in self .ts .edges ():
975
979
if edge .child in self .fixednodes :
976
- self .parent_message [edge .id ] = self .lik .to_gamma (edge )
980
+ self .parent_message [edge .id ] = self .lik .to_gamma (edge , natural = False )
977
981
self .posterior [edge .parent ] = self .lik .combine (
978
982
self .posterior [edge .parent ], self .parent_message [edge .id ]
979
983
)
@@ -996,8 +1000,7 @@ def propagate(self, *, edges, progress=None):
996
1000
continue
997
1001
if edge .parent in self .fixednodes :
998
1002
raise ValueError ("Internal nodes can not be fixed in EP algorithm" )
999
- edge_lik = self .lik .to_gamma (edge )
1000
- edge_lik += np .array ([- 1.0 , 0.0 ]) # to Poisson, TODO cleanup
1003
+ edge_lik = self .lik .to_gamma (edge , natural = True )
1001
1004
# Get the cavity posteriors: that is, the rest of the approximation
1002
1005
# without the factor for this edge. This only involves the variational
1003
1006
# parameters for the parent and child on the edge.
@@ -1181,13 +1184,13 @@ def date(
1181
1184
:param int num_threads: The number of threads to use. A simpler unthreaded algorithm
1182
1185
is used unless this is >= 1. Default: None
1183
1186
:param string method: What estimation method to use: can be
1184
- "EP " (variational approximation, empirically most accurate),
1187
+ "variational_gamma " (variational approximation, empirically most accurate),
1185
1188
"inside_outside" (empirically better, theoretically problematic) or
1186
1189
"maximization" (worse empirically, especially with gamma approximated priors,
1187
1190
but theoretically robust). If ``None`` (default) use "inside_outside"
1188
1191
:param string probability_space: Should the internal algorithm save probabilities in
1189
1192
"logarithmic" (slower, less liable to to overflow) or "linear" space (fast, may
1190
- overflow). Does not apply to method ``EP ``. Default: "logarithmic"
1193
+ overflow). Does not apply to method ``variational_gamma ``. Default: "logarithmic"
1191
1194
:param bool ignore_oldest_root: Should the oldest root in the tree sequence be
1192
1195
ignored in the outside algorithm (if "inside_outside" is used as the method).
1193
1196
Ignoring outside root provides greater stability when dating tree sequences
@@ -1212,7 +1215,7 @@ def date(
1212
1215
)
1213
1216
else :
1214
1217
population_size = Ne
1215
- if method == "EP " :
1218
+ if method == "variational_gamma " :
1216
1219
tree_sequence , dates , posteriors , timepoints , eps , nds = variational_dates (
1217
1220
tree_sequence ,
1218
1221
population_size = population_size ,
0 commit comments