@@ -1008,10 +1008,19 @@ def fill_priors(
1008
1008
1009
1009
class MixturePrior :
1010
1010
"""
1011
- Maps ConditionalCoalescentPrior onto nodes in a tree sequence and creates time-discretized priors
1011
+ Maps ConditionalCoalescentPrior onto nodes in a tree sequence and creates
1012
+ time-discretized priors
1012
1013
"""
1013
1014
1014
- def __init__ (self , tree_sequence , approximate_priors = False , approx_prior_size = None , prior_distribution = "lognorm" , allow_unary = False , progress = False ):
1015
+ def __init__ (
1016
+ self ,
1017
+ tree_sequence ,
1018
+ approximate_priors = False ,
1019
+ approx_prior_size = None ,
1020
+ prior_distribution = "lognorm" ,
1021
+ allow_unary = False ,
1022
+ progress = False ,
1023
+ ):
1015
1024
1016
1025
if approximate_priors :
1017
1026
if not approx_prior_size :
@@ -1028,15 +1037,18 @@ def __init__(self, tree_sequence, approximate_priors=False, approx_prior_size=No
1028
1037
"Passed tree sequence is not simplified and/or contains "
1029
1038
"noncontemporaneous samples"
1030
1039
)
1031
- span_data = SpansBySamples (contmpr_ts , progress = progress , allow_unary = allow_unary )
1040
+ span_data = SpansBySamples (
1041
+ contmpr_ts , progress = progress , allow_unary = allow_unary
1042
+ )
1032
1043
1033
1044
base_priors = ConditionalCoalescentTimes (
1034
1045
approx_prior_size , prior_distribution , progress = progress
1035
1046
)
1036
1047
1037
1048
base_priors .add (contmpr_ts .num_samples , approximate_priors )
1038
1049
for total_fixed in span_data .total_fixed_at_0_counts :
1039
- # For missing data: trees vary in total fixed node count => have different priors
1050
+ # For missing data: trees vary in total fixed node count =>
1051
+ # have different priors
1040
1052
if total_fixed > 0 :
1041
1053
base_priors .add (total_fixed , approximate_priors )
1042
1054
prior_params_contmpr = base_priors .get_mixture_prior_params (span_data )
@@ -1047,7 +1059,6 @@ def __init__(self, tree_sequence, approximate_priors=False, approx_prior_size=No
1047
1059
self .tree_sequence = tree_sequence
1048
1060
self .prior_distribution = prior_distribution
1049
1061
1050
-
1051
1062
def make_discretized_prior (self , population_size , timepoints = 20 , progress = False ):
1052
1063
"""
1053
1064
Calculate prior grid for a set of timepoints and a population size history
@@ -1080,7 +1091,9 @@ def make_discretized_prior(self, population_size, timepoints=20, progress=False)
1080
1091
timepoints = create_timepoints (self .base_priors , timepoints + 1 )
1081
1092
elif isinstance (timepoints , np .ndarray ):
1082
1093
try :
1083
- timepoints = np .sort (timepoints .astype (base .FLOAT_DTYPE , casting = "safe" ))
1094
+ timepoints = np .sort (
1095
+ timepoints .astype (base .FLOAT_DTYPE , casting = "safe" )
1096
+ )
1084
1097
except TypeError :
1085
1098
raise TypeError ("Timepoints array cannot be converted to float dtype" )
1086
1099
if len (timepoints ) < 2 :
@@ -1090,7 +1103,9 @@ def make_discretized_prior(self, population_size, timepoints=20, progress=False)
1090
1103
elif np .any (np .unique (timepoints , return_counts = True )[1 ] > 1 ):
1091
1104
raise ValueError ("Timepoints cannot have duplicate values" )
1092
1105
else :
1093
- raise ValueError ("time_slices must be an integer or a numpy array of floats" )
1106
+ raise ValueError (
1107
+ "time_slices must be an integer or a numpy array of floats"
1108
+ )
1094
1109
1095
1110
# Set all fixed nodes (i.e. samples) to have 0 variance
1096
1111
priors = fill_priors (
@@ -1113,6 +1128,7 @@ def build_grid(
1113
1128
approx_prior_size = None ,
1114
1129
prior_distribution = "lognorm" ,
1115
1130
# Parameters below undocumented
1131
+ eps = 1e-6 , # placeholder
1116
1132
progress = False ,
1117
1133
allow_unary = False ,
1118
1134
):
@@ -1147,7 +1163,11 @@ def build_grid(
1147
1163
"""
1148
1164
1149
1165
mixture_prior = MixturePrior (
1150
- tree_sequence , approximate_priors , approx_prior_size , prior_distribution , allow_unary , progress
1166
+ tree_sequence ,
1167
+ approximate_priors ,
1168
+ approx_prior_size ,
1169
+ prior_distribution ,
1170
+ allow_unary ,
1171
+ progress ,
1151
1172
)
1152
1173
return mixture_prior .make_discretized_prior (population_size , timepoints )
1153
-
0 commit comments