fix gauss tests

This commit is contained in:
Gaspard Jankowiak 2025-02-11 13:42:14 +01:00
commit 0b1a5ad3af
3 changed files with 40 additions and 33 deletions

View file

@ -62,12 +62,12 @@ function compute_H_f2(p::Vector{Float64}; x::Float64=0.0)
return H_f2
end
@testset "Erf aux functions" begin
@testset "Erf auxiliary functions" begin
L = 10 * (rand() - 0.5)
μ = 10 * (rand() - 0.5)
σ = 10rand()
x = σ * (2 * rand() - 0.5) + μ
x = σ * (2 * rand() - 1) + μ
p = [L, μ, σ]
@test TaylorTest.check(compute_f1, compute_J_f1, p; x=x)
@ -98,7 +98,8 @@ end
J_f1 = compute_J_f1(p; x=x)
J_f2 = compute_J_f2(p; x=x)
return J_f1 .* gauss([sqrt(2), 0, 1]; x=f1) - J_f2 .* gauss([sqrt(2), 0, 1]; x=f2)
return J_f1 .* gauss([1, 0, 1 / sqrt(2)]; x=f1) - J_f2 .* gauss([1, 0, 1 / sqrt(2)]; x=f2)
end
function H_diff_of_erf(p::Vector{Float64}; x::Float64=0.0)
@ -106,7 +107,7 @@ end
L, μ, σ = p
sq2σ = sqrt(2) * σ
# d²/dξ² ( erf( f1(x) ) - erf( f2(x) ) )/2 = d²/dξ² f1(x) gauss([sqrt(2), 0, 1]; x=f1(x)) - d²/dξ² f2(x) gauss([sqrt(2), 0, 1]; x=f2(x))
# d²/dξ² ( erf( f1(x) ) - erf( f2(x) ) )/2 = d²/dξ² f1(x) gauss([1, 0, 1/sqrt(2)]; x=f1(x)) - d²/dξ² f2(x) gauss([1, 0, 1/sqrt(2)]; x=f2(x))
# + (d/dξ f1(x))^2 gauss([sqrt(2), 0, 1]; x=f1(x)) - d²/dξ² f2(x) gauss([sqrt(2), 0, 1]; x=f2(x))
f1 = compute_f1(p; x=x)
@ -118,9 +119,10 @@ end
H_f1 = compute_H_f1(p; x=x)
H_f2 = compute_H_f2(p; x=x)
return (H_f1 .* gauss([sqrt(2), 0, 1]; x=f1) - H_f2 .* gauss([sqrt(2), 0, 1]; x=f2)
-
J_f1' * J_f1 .* f1 .* gauss([2 * sqrt(2), 0, 1]; x=f1) + J_f2' * J_f2 .* f2 .* gauss([2 * sqrt(2), 0, 1]; x=f2))
g_f1 = gauss([1, 0, 1 / sqrt(2)]; x=f1)
g_f2 = gauss([1, 0, 1 / sqrt(2)]; x=f2)
return H_f1 .* g_f1 - H_f2 .* g_f2 - 2J_f1' * J_f1 .* f1 .* g_f1 + 2J_f2' * J_f2 .* f2 .* g_f2
end
L = 10 * (rand() - 0.5)
@ -130,6 +132,8 @@ end
x = σ * (2 * rand() - 0.5) + μ
p = [L, μ, σ]
@show diff_of_erf(p; x=x)
@test TaylorTest.check(diff_of_erf, J_diff_of_erf, p; x=x)
@test TaylorTest.check(J_diff_of_erf, H_diff_of_erf, p, [2, 3]; x=x)
end