Skip to content

Commit

Permalink
fix negative values due to numerical error #24 (#25)
Browse files Browse the repository at this point in the history
* fix negative values due to numerical error #24

* add warning in case of numerical error src/bayesquads/bayesquad.jl

Co-authored-by: Théo Galy-Fajou <theo.galyfajou@gmail.com>

* add missing syntax

* Update src/bayesquads/bayesquad.jl

Co-authored-by: Théo Galy-Fajou <theo.galyfajou@gmail.com>

Co-authored-by: Johannes Giersdorf <johannes.giersdorf@gmail.com>
Co-authored-by: Théo Galy-Fajou <theo.galyfajou@gmail.com>
  • Loading branch information
3 people committed Apr 13, 2021
1 parent 34d8c9b commit d2ae2ce
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/bayesquads/bayesquad.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,15 @@ function quadrature(
K = kernelpdmat(kernel(bquad), samples)
z = calc_z(samples, prior(model), bquad)
C = calc_C(prior(model), bquad)
return Normal(evaluate_mean(z, K, y), evaluate_var(z, K, C))
var = evaluate_var(z, K, C)
if var < 0
if var > -1e-5
@warn "Variance was negative (numerical error) and set to 0"
else
error("Obtained variance was negative")
end
end
return Normal(evaluate_mean(z, K, y), max(var, zero(var)))
end

Λ(bquad::BayesQuad{<:SqExponentialKernel,<:Real}) = abs2(bquad.l) * I
Expand Down

0 comments on commit d2ae2ce

Please sign in to comment.