Symmetric matrices + fix math errors
This commit is contained in:
parent
75ebbc3247
commit
836390ec72
|
|
@ -16,9 +16,9 @@ N = 9
|
||||||
|
|
||||||
# initialize random Hamiltonians
|
# initialize random Hamiltonians
|
||||||
H0 = randn(ComplexF64, N, N)
|
H0 = randn(ComplexF64, N, N)
|
||||||
#H0 = H0 + H0' # symmetric
|
H0 = H0 + transpose(H0) # symmetric
|
||||||
H1 = randn(ComplexF64, N, N)
|
H1 = randn(ComplexF64, N, N)
|
||||||
#H1 = H1 + H1' # symmetric
|
H1 = H1 + transpose(H1) # symmetric
|
||||||
|
|
||||||
# training
|
# training
|
||||||
Es = ComplexF64[]
|
Es = ComplexF64[]
|
||||||
|
|
@ -46,9 +46,9 @@ for epoch in 1:epochs
|
||||||
function grad(c_order=0)
|
function grad(c_order=0)
|
||||||
out = zeros(ComplexF64, N, N)
|
out = zeros(ComplexF64, N, N)
|
||||||
for (c, E_target, ψ, E) in zip(data_c, data_E, ψs, Es)
|
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
|
end
|
||||||
return out
|
return 2 .* real.(out)
|
||||||
end
|
end
|
||||||
H0 .-= lr .* grad(0) # update H0
|
H0 .-= lr .* grad(0) # update H0
|
||||||
H1 .-= lr .* grad(1) # update H1
|
H1 .-= lr .* grad(1) # update H1
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue