Skip to content

Commit 4bc8a3a

Browse files
committed
Respect normal invariance for point mass gaussians + patch logic for 0 variances diff means
1 parent 68dc8b1 commit 4bc8a3a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/models/continuous_models/gaussian_partition.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ end
2424
function merge_two_gaussians(g1::GaussianPartition, g2::GaussianPartition)
2525
#Handling some edge cases. These aren't mathematically sensible. A gaussian with "Inf" variance will behave like a 1,1,1,1 vector in discrete felsenstein.
2626
#To-do: update some of these so that the norm constant is properly handled, even if the variance is Inf (so it isn't exactly well-defined anyway)
27-
if g1.var == 0 && g2.var == 0 && g1.var != g2.var
27+
if g1.var == 0 && g2.var == 0 && g1.mean != g2.mean
2828
error("both gaussians have 0 variance but different means")
2929
elseif g1.var == 0
30-
return copy_partition(g1)
30+
return _merge_point_mass(g1, g2)
3131
elseif g2.var == 0
32-
return copy_partition(g2)
32+
return _merge_point_mass(g2, g1)
3333
end
3434
if g1.var == Inf && g2.var == Inf
3535
return GaussianPartition((g1.mean + g2.mean) / 2, Inf, 0.0)
@@ -52,6 +52,12 @@ function merge_two_gaussians(g1::GaussianPartition, g2::GaussianPartition)
5252
return res_gaussian
5353
end
5454

55+
function _merge_point_mass(point::GaussianPartition, regular::GaussianPartition)
56+
r = copy_partition(point)
57+
r.norm_const += log(gaussian_pdf(regular, point.mean)) + regular.norm_const
58+
return r
59+
end
60+
5561
function identity!(dest::GaussianPartition)
5662
dest.var = Inf
5763
dest.norm_const = 0.0

0 commit comments

Comments
 (0)