2024-07-18 00:33:32 +00:00
|
|
|
include("Engine.jl")
|
|
|
|
|
2024-07-18 05:45:17 +00:00
|
|
|
using LinearAlgebra
|
2024-07-18 00:33:32 +00:00
|
|
|
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-18 01:55:36 +00:00
|
|
|
for j in 1:11
|
|
|
|
for k in 1:11
|
2024-07-18 00:33:32 +00:00
|
|
|
filled = false
|
2024-07-18 01:55:36 +00:00
|
|
|
if j == 11
|
2024-07-18 00:33:32 +00:00
|
|
|
if k <= 4
|
|
|
|
push!(values, 0)
|
|
|
|
filled = true
|
|
|
|
end
|
2024-07-18 01:55:36 +00:00
|
|
|
elseif k == 11
|
2024-07-18 00:33:32 +00:00
|
|
|
if j <= 4
|
|
|
|
push!(values, 0)
|
|
|
|
filled = true
|
|
|
|
end
|
|
|
|
elseif j == k
|
2024-07-18 01:55:36 +00:00
|
|
|
push!(values, j <= 6 ? 1 : 0)
|
2024-07-18 00:33:32 +00:00
|
|
|
filled = true
|
|
|
|
elseif j <= 4
|
|
|
|
if k <= 4
|
|
|
|
push!(values, -1/BigFloat(3))
|
|
|
|
filled = true
|
|
|
|
elseif k == 5
|
2024-07-18 01:08:36 +00:00
|
|
|
push!(values, -1)
|
2024-07-18 00:33:32 +00:00
|
|
|
filled = true
|
2024-07-18 01:55:36 +00:00
|
|
|
elseif 7 <= k <= 10 && k - j != 6
|
2024-07-18 00:33:32 +00:00
|
|
|
push!(values, 0)
|
|
|
|
filled = true
|
|
|
|
end
|
|
|
|
elseif k <= 4
|
|
|
|
if j == 5
|
2024-07-18 01:08:36 +00:00
|
|
|
push!(values, -1)
|
2024-07-18 00:33:32 +00:00
|
|
|
filled = true
|
2024-07-18 01:55:36 +00:00
|
|
|
elseif 7 <= j <= 10 && j - k != 6
|
2024-07-18 00:33:32 +00:00
|
|
|
push!(values, 0)
|
|
|
|
filled = true
|
|
|
|
end
|
2024-07-18 01:55:36 +00:00
|
|
|
elseif j == 6 && 7 <= k <= 10 || k == 6 && 7 <= j <= 10
|
|
|
|
push!(values, 0)
|
|
|
|
filled = true
|
2024-07-18 00:33:32 +00:00
|
|
|
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(
|
|
|
|
sqrt(1/BigFloat(3)) * BigFloat[
|
2024-07-18 01:55:36 +00:00
|
|
|
1 1 -1 -1 0 0
|
|
|
|
1 -1 1 -1 0 0
|
|
|
|
1 -1 -1 1 0 0
|
2024-07-18 06:07:34 +00:00
|
|
|
0 0 0 0 1.5 0.5
|
2024-07-18 02:01:34 +00:00
|
|
|
1 1 1 1 -0.5 -1.5
|
2024-07-18 06:37:28 +00:00
|
|
|
] + 0.0*Engine.rand_on_shell(fill(BigFloat(-1), 6)),
|
|
|
|
Engine.point([-0.5, -0.5, -0.5] + 0.3*randn(3)),
|
|
|
|
Engine.point([-0.5, 0.5, 0.5] + 0.3*randn(3)),
|
|
|
|
Engine.point([ 0.5, -0.5, 0.5] + 0.3*randn(3)),
|
|
|
|
Engine.point([ 0.5, 0.5, -0.5] + 0.3*randn(3)),
|
2024-07-18 00:33:32 +00:00
|
|
|
BigFloat[0, 0, 0, 0, 1]
|
|
|
|
)
|
|
|
|
frozen = vcat(
|
2024-07-18 01:55:36 +00:00
|
|
|
[CartesianIndex(4, k) for k in 7:10],
|
|
|
|
[CartesianIndex(j, 11) for j in 1:5]
|
2024-07-18 00:33:32 +00:00
|
|
|
)
|
|
|
|
|
2024-07-18 07:50:48 +00:00
|
|
|
# complete the gram matrix using Newton's method with backtracking
|
2024-07-18 00:33:32 +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))
|
2024-07-18 05:45:17 +00:00
|
|
|
println("Loss: ", history.scaled_loss[end])
|
|
|
|
if success
|
|
|
|
infty = BigFloat[0, 0, 0, 0, 1]
|
|
|
|
radius_ratio = dot(infty, Engine.Q * L[:,5]) / dot(infty, Engine.Q * L[:,6])
|
|
|
|
println("\nCircumradius / inradius: ", radius_ratio)
|
|
|
|
end
|