@@ -960,7 +960,7 @@ def fill_priors(
960
960
Ne ,
961
961
* ,
962
962
prior_distr ,
963
- node_var_override = None ,
963
+ nonfixed_sample_var = None ,
964
964
progress = False ,
965
965
):
966
966
"""
@@ -969,7 +969,7 @@ def fill_priors(
969
969
are ignored for these nodes) and fill out a NodeGridValues object with the prior
970
970
values from the gamma or lognormal distribution with those parameters.
971
971
972
- For a description of `node_var_override `, see the parameter description in
972
+ For a description of `nonfixed_sample_var `, see the parameter description in
973
973
the `build_grid` function.
974
974
975
975
TODO - what if there is an internal fixed node? Should we truncate
@@ -994,12 +994,16 @@ def shape_scale_from_mean_var(mean, var):
994
994
995
995
else :
996
996
raise ValueError ("prior distribution must be lognorm or gamma" )
997
- if node_var_override is None :
998
- node_var_override = {}
997
+ samples = ts .samples ()
998
+ if nonfixed_sample_var is None :
999
+ nonfixed_sample_var = {}
1000
+ for u in nonfixed_sample_var .keys ():
1001
+ if u not in samples :
1002
+ raise ValueError (f"Node { u } in 'nonfixed_sample_var' is not a sample" )
999
1003
datable_nodes = np .ones (ts .num_nodes , dtype = bool )
1000
- datable_nodes [ts . samples () ] = False
1001
- # Mark all nodes in node_var_override as datable
1002
- datable_nodes [list (node_var_override .keys ())] = True
1004
+ datable_nodes [samples ] = False
1005
+ # Mark all nodes in nonfixed_sample_var as datable
1006
+ datable_nodes [list (nonfixed_sample_var .keys ())] = True
1003
1007
datable_nodes = np .where (datable_nodes )[0 ]
1004
1008
1005
1009
prior_times = base .NodeGridValues (
@@ -1012,10 +1016,10 @@ def shape_scale_from_mean_var(mean, var):
1012
1016
for node in tqdm (
1013
1017
datable_nodes , desc = "Assign Prior to Each Node" , disable = not progress
1014
1018
):
1015
- if node in node_var_override :
1019
+ if node in nonfixed_sample_var :
1016
1020
shape , scale = shape_scale_from_mean_var (
1017
1021
mean = ts .node (node ).time ,
1018
- var = node_var_override [node ],
1022
+ var = nonfixed_sample_var [node ],
1019
1023
)
1020
1024
else :
1021
1025
shape = shape_param [node ]
@@ -1098,7 +1102,7 @@ def build_grid(
1098
1102
prior_distribution = "lognorm" ,
1099
1103
allow_historical_samples = None ,
1100
1104
truncate_priors = None ,
1101
- node_var_override = None ,
1105
+ nonfixed_sample_var = None ,
1102
1106
eps = 1e-6 ,
1103
1107
# Parameters below undocumented
1104
1108
progress = False ,
@@ -1127,20 +1131,21 @@ def build_grid(
1127
1131
gamma distribution (slightly faster, but a poorer fit for recent nodes).
1128
1132
Default: "lognorm"
1129
1133
:param bool allow_historical_samples: should we allow historical samples (i.e. at
1130
- times > 0. This invalidates the assumptions of the conditional coalescent, but
1134
+ times > 0) . This invalidates the assumptions of the conditional coalescent, but
1131
1135
may be acceptable if the historical samples are recent or if there are many
1132
- contemporaneous samples. Default: `False`
1136
+ contemporaneous samples. Default: `` False` `
1133
1137
:param bool truncate_priors: If there are historical samples, should we truncate the
1134
- priors of their direct ancestor nodes so that the probability of being younger
1135
- than the oldest descendant sample is zero. If the tree sequence is trustworthy
1136
- this should give better restults. Default: `True`
1137
- :param dict node_var_override: is a dict mapping node IDs to a variance value.
1138
- Any nodes listed here will be treated as non-fixed nodes whose prior is not
1139
- calculated from the conditional coalescent but instead are allocated a prior
1138
+ priors of all nodes which are their ancestors so that the probability of being
1139
+ younger than the oldest descendant sample is zero. As long as historical
1140
+ samples do not have ancestors that have been misassigned in the tree sequence
1141
+ topology, this should give better results. Default: ``True``
1142
+ :param dict nonfixed_sample_var: is a dict mapping sample node IDs to a variance
1143
+ value. Any nodes listed here will be treated as non-fixed nodes whose prior is
1144
+ not calculated from the conditional coalescent but instead are allocated a prior
1140
1145
whose mean is the node time in the tree sequence and whose variance is the
1141
1146
value in this dictionary. This allows sample nodes to be treated as nonfixed
1142
1147
nodes, and therefore dated. If ``None`` (default) then all sample nodes are
1143
- treated as occurring ata fixed time (as if this were an empty dict).
1148
+ treated as occurring at a fixed time (as if this were an empty dict).
1144
1149
:param float eps: Specify minimum distance separating points in the time grid. Also
1145
1150
specifies the error factor in time difference calculations. Default: 1e-6
1146
1151
:return: A prior object to pass to tsdate.date() containing prior values for
@@ -1201,7 +1206,7 @@ def build_grid(
1201
1206
tree_sequence ,
1202
1207
Ne ,
1203
1208
prior_distr = prior_distribution ,
1204
- node_var_override = node_var_override ,
1209
+ nonfixed_sample_var = nonfixed_sample_var ,
1205
1210
progress = progress ,
1206
1211
)
1207
1212
if np .any (tree_sequence .nodes_time [tree_sequence .samples ()] > 0 ):
0 commit comments