forked from glen/dyna3
90 lines
No EOL
2 KiB
Julia
90 lines
No EOL
2 KiB
Julia
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[]
|
|
for j in 1:11
|
|
for k in 1:11
|
|
filled = false
|
|
if j == 11
|
|
if k <= 4
|
|
push!(values, 0)
|
|
filled = true
|
|
end
|
|
elseif k == 11
|
|
if j <= 4
|
|
push!(values, 0)
|
|
filled = true
|
|
end
|
|
elseif j == k
|
|
push!(values, j <= 6 ? 1 : 0)
|
|
filled = true
|
|
elseif j <= 4
|
|
if k <= 4
|
|
push!(values, -1/BigFloat(3))
|
|
filled = true
|
|
elseif k == 5
|
|
push!(values, -1)
|
|
filled = true
|
|
elseif 7 <= k <= 10 && k - j != 6
|
|
push!(values, 0)
|
|
filled = true
|
|
end
|
|
elseif k <= 4
|
|
if j == 5
|
|
push!(values, -1)
|
|
filled = true
|
|
elseif 7 <= j <= 10 && j - k != 6
|
|
push!(values, 0)
|
|
filled = true
|
|
end
|
|
elseif j == 6 && 7 <= k <= 10 || k == 6 && 7 <= j <= 10
|
|
push!(values, 0)
|
|
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(
|
|
sqrt(1/BigFloat(3)) * BigFloat[
|
|
1 1 -1 -1 0 0
|
|
1 -1 1 -1 0 0
|
|
1 -1 -1 1 0 0
|
|
0 0 0 0 -1.5 -3
|
|
1 1 1 1 -0.5 -1
|
|
] + 0.2*Engine.rand_on_shell(fill(BigFloat(-1), 6)),
|
|
Engine.point([-1, -1, -1]),
|
|
Engine.point([-1, 1, 1]),
|
|
Engine.point([ 1, -1, 1]),
|
|
Engine.point([ 1, 1, -1]),
|
|
BigFloat[0, 0, 0, 0, 1]
|
|
)
|
|
frozen = vcat(
|
|
[CartesianIndex(4, k) for k in 7:10],
|
|
[CartesianIndex(j, 11) for j in 1:5]
|
|
)
|
|
|
|
# complete the gram matrix
|
|
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") |