dyna3/engine-proto/gram-test/sphere-in-tetrahedron.jl

70 lines
1.4 KiB
Julia
Raw Normal View History

include("Engine.jl")
using SparseArrays
using Random
# initialize the partial gram matrix for a sphere inscribed in a regular
# tetrahedron
J = Int64[]
K = Int64[]
values = BigFloat[]
2024-07-16 06:54:59 +00:00
for j in 1:6
for k in 1:6
filled = false
if j == 6
if k <= 4
push!(values, 0)
filled = true
end
elseif k == 6
if j <= 4
push!(values, 0)
filled = true
end
elseif j == k
push!(values, 1)
2024-07-16 06:54:59 +00:00
filled = true
elseif (j <= 4 && k <= 4)
push!(values, -1/BigFloat(3))
2024-07-16 06:54:59 +00:00
filled = true
else
push!(values, -1)
2024-07-16 06:54:59 +00:00
filled = true
end
if filled
push!(J, j)
push!(K, k)
end
end
end
gram = sparse(J, K, values)
# set initial guess
Random.seed!(99230)
guess = hcat(
2024-07-16 06:54:59 +00:00
sqrt(1/BigFloat(3)) * BigFloat[
1 1 -1 -1 0
1 -1 1 -1 0
1 -1 -1 1 0
0 0 0 0 -1.5
1 1 1 1 -0.5
2024-07-16 06:54:59 +00:00
] + 0.2*Engine.rand_on_shell(fill(BigFloat(-1), 5)),
BigFloat[0, 0, 0, 0, 1]
2024-07-16 06:54:59 +00:00
)
frozen = [CartesianIndex(j, 6) for j in 1:5]
# complete the gram matrix
#=
2024-07-11 20:43:52 +00:00
L, history = Engine.realize_gram_newton(gram, guess)
=#
2024-07-16 06:54:59 +00:00
L, success, history = Engine.realize_gram(gram, guess, frozen)
completed_gram = L'*Engine.Q*L
println("Completed Gram matrix:\n")
display(completed_gram)
if success
println("\nTarget accuracy achieved!")
else
println("\nFailed to reach target accuracy")
end
println("Steps: ", size(history.scaled_loss, 1))
println("Loss: ", history.scaled_loss[end], "\n")