@@ -344,13 +344,10 @@ def n_breaks(self, edge):
344
344
def combine (self , lik_1 , lik_2 ):
345
345
return lik_1 * lik_2
346
346
347
- def reduce (self , lik_1 , lik_2 , div_0_null = False ):
347
+ def ratio (self , lik_1 , lik_2 , div_0_null = False ):
348
348
"""
349
- In linear space, this divides lik_1 by lik_2
349
+ Return the ratio of lik_1 to lik_2. In linear space, this divides lik_1 by lik_2
350
350
If div_0_null==True, then 0/0 is set to the null_constant
351
-
352
- NB: "reduce" is not a very good name for the function: can we think of
353
- something better that will also be meaningful in log space?
354
351
"""
355
352
with np .errstate (divide = "ignore" , invalid = "ignore" ):
356
353
ret = lik_1 / lik_2
@@ -487,9 +484,9 @@ def _recombination_loglik(self, edge, fixed=True):
487
484
def combine (self , loglik_1 , loglik_2 ):
488
485
return loglik_1 + loglik_2
489
486
490
- def reduce (self , loglik_1 , loglik_2 , div_0_null = False ):
487
+ def ratio (self , loglik_1 , loglik_2 , div_0_null = False ):
491
488
"""
492
- In log space, loglik_1 - loglik_2
489
+ In log space, likelihood ratio is loglik_1 - loglik_2
493
490
If div_0_null==True, then if either is -inf it returns -inf (the null_constant)
494
491
"""
495
492
with np .errstate (divide = "ignore" , invalid = "ignore" ):
@@ -686,9 +683,9 @@ def inside_pass(self, *, standardize=True, cache_inside=False, progress=None):
686
683
denominator [parent ] = (
687
684
np .max (val ) if standardize else self .lik .identity_constant
688
685
)
689
- inside [parent ] = self .lik .reduce (val , denominator [parent ])
686
+ inside [parent ] = self .lik .ratio (val , denominator [parent ])
690
687
if cache_inside :
691
- self .g_i = self .lik .reduce (
688
+ self .g_i = self .lik .ratio (
692
689
g_i , denominator [self .ts .tables .edges .child , None ]
693
690
)
694
691
# Keep the results in this object
@@ -749,16 +746,16 @@ def outside_pass(
749
746
# but is an approximation when times are unknown.
750
747
spanfrac = edge .span / self .spans [child ]
751
748
try :
752
- inside_div_gi = self .lik .reduce (
749
+ inside_div_gi = self .lik .ratio (
753
750
self .inside [edge .parent ], self .g_i [edge .id ], div_0_null = True
754
751
)
755
752
except AttributeError : # we haven't cached g_i so we recalculate
756
753
daughter_val = self .lik .scale_geometric (
757
754
spanfrac , self .lik .make_lower_tri (self .inside [edge .child ])
758
755
)
759
756
edge_lik = self .lik .get_inside (daughter_val , edge )
760
- cur_g_i = self .lik .reduce (edge_lik , self .denominator [child ])
761
- inside_div_gi = self .lik .reduce (
757
+ cur_g_i = self .lik .ratio (edge_lik , self .denominator [child ])
758
+ inside_div_gi = self .lik .ratio (
762
759
self .inside [edge .parent ], cur_g_i , div_0_null = True
763
760
)
764
761
parent_val = self .lik .scale_geometric (
@@ -768,15 +765,15 @@ def outside_pass(
768
765
),
769
766
)
770
767
if standardize :
771
- parent_val = self .lik .reduce (parent_val , np .max (parent_val ))
768
+ parent_val = self .lik .ratio (parent_val , np .max (parent_val ))
772
769
edge_lik = self .lik .get_outside (parent_val , edge )
773
770
val = self .lik .combine (val , edge_lik )
774
771
775
772
# vv[0] = 0 # Seems a hack: internal nodes should be allowed at time 0
776
773
assert self .denominator [edge .child ] > self .lik .null_constant
777
- outside [child ] = self .lik .reduce (val , self .denominator [child ])
774
+ outside [child ] = self .lik .ratio (val , self .denominator [child ])
778
775
if standardize :
779
- outside [child ] = self .lik .reduce (val , np .max (val ))
776
+ outside [child ] = self .lik .ratio (val , np .max (val ))
780
777
self .outside = outside
781
778
posterior = outside .clone_with_new_data (
782
779
grid_data = self .lik .combine (self .inside .grid_data , outside .grid_data ),
@@ -829,7 +826,7 @@ def outside_maximization(self, *, eps, progress=None):
829
826
* self .lik .mut_rate
830
827
* edge .span ,
831
828
)
832
- result = self .lik .reduce (ll_mut , np .max (ll_mut ))
829
+ result = self .lik .ratio (ll_mut , np .max (ll_mut ))
833
830
else :
834
831
cur_parent_index = maximized_node_times [edge .parent ]
835
832
if cur_parent_index < youngest_par_index :
@@ -846,7 +843,7 @@ def outside_maximization(self, *, eps, progress=None):
846
843
* edge .span ,
847
844
)
848
845
result [: youngest_par_index + 1 ] = self .lik .combine (
849
- self .lik .reduce (
846
+ self .lik .ratio (
850
847
ll_mut [: youngest_par_index + 1 ],
851
848
np .max (ll_mut [: youngest_par_index + 1 ]),
852
849
),
0 commit comments