Use Newton's method for polishing

This commit is contained in:
Aaron Fenyes 2024-07-11 13:43:52 -07:00
parent d538cbf716
commit 3910b9f740
4 changed files with 103 additions and 18 deletions

View file

@ -55,7 +55,6 @@ gram = sparse(J, K, values)
## guess = Engine.rand_on_shell(fill(BigFloat(-1), 8))
# set initial guess
#=
guess = hcat(
Engine.plane(BigFloat[0, 0, 1], BigFloat(0)),
Engine.sphere(BigFloat[0, 0, 0], BigFloat(1//2)),
@ -67,7 +66,7 @@ guess = hcat(
Engine.sphere(BigFloat[cos(pi/3), sin(pi/3), 0], BigFloat(1//5)),
BigFloat[0, 0, 0, 1, 1]
)
=#
#=
guess = hcat(
Engine.plane(BigFloat[0, 0, 1], BigFloat(0)),
Engine.sphere(BigFloat[0, 0, 0], BigFloat(0.9)),
@ -79,11 +78,19 @@ guess = hcat(
Engine.sphere(4//3*BigFloat[cos(pi/3), sin(pi/3), 0], BigFloat(1//3)),
BigFloat[0, 0, 0, 1, 1]
)
=#
# complete the gram matrix using gradient descent
L, history = Engine.realize_gram(gram, guess, max_descent_steps = 200)
# complete the gram matrix using gradient descent followed by Newton's method
L, history = Engine.realize_gram_gradient(gram, guess, scaled_tol = 0.01)
L_pol, history_pol = Engine.realize_gram_newton(gram, L, rate = 0.3, scaled_tol = 1e-9)
L_pol2, history_pol2 = Engine.realize_gram_newton(gram, L_pol)
completed_gram = L'*Engine.Q*L
println("Completed Gram matrix:\n")
display(completed_gram)
println("\nSteps: ", size(history.stepsize, 1))
println("Loss: ", history.scaled_loss[end], "\n")
println(
"\nSteps: ",
size(history.scaled_loss, 1),
" + ", size(history_pol.scaled_loss, 1),
" + ", size(history_pol2.scaled_loss, 1)
)
println("Loss: ", history_pol2.scaled_loss[end], "\n")