Symmetric matrices + fix math errors

This commit is contained in:
Nuwan Yapa 2025-04-14 13:32:08 -04:00
parent 75ebbc3247
commit 836390ec72
1 changed files with 4 additions and 4 deletions

View File

@ -16,9 +16,9 @@ N = 9
# initialize random Hamiltonians
H0 = randn(ComplexF64, N, N)
#H0 = H0 + H0' # symmetric
H0 = H0 + transpose(H0) # symmetric
H1 = randn(ComplexF64, N, N)
#H1 = H1 + H1' # symmetric
H1 = H1 + transpose(H1) # symmetric
# training
Es = ComplexF64[]
@ -46,9 +46,9 @@ for epoch in 1:epochs
function grad(c_order=0)
out = zeros(ComplexF64, N, N)
for (c, E_target, ψ, E) in zip(data_c, data_E, ψs, Es)
out .+= (c^c_order * (E - E_target)) .* (ψ * ψ')
out .+= (c^c_order * conj(E - E_target)) .* (ψ * transpose(ψ))
end
return out
return 2 .* real.(out)
end
H0 .-= lr .* grad(0) # update H0
H1 .-= lr .* grad(1) # update H1