Hi all,
I want to calculate the entanglement entropy of a fermion chain, and I find the following code.
(Entanglement entropy (Julia) - ITensor Support Q&A).
The code is
function entropy_von_neumann(psi::MPS, b::Int)
s = siteinds(psi)
orthogonalize!(psi, b)
_,S = svd(psi[b], (linkind(psi, b-1), s[b]))
SvN = 0.0
for n in 1:dim(S, 1)
p = S[n,n]^2
SvN -= p * log(p)
end
return SvN
end
I would like to ask if the b mentioned in this program refers to the entanglement entropy of the two subsystems before and after the truncation at b position
But then I see a code that adds a “for loop”. So what does b for i in 2:N-1 mean in this code?
function entropyvonneumann(psi::MPS, N::Int)
SvN = fill(0.0, N)
for b in 2:N-1
orthogonalize!(psi, b)
_,S = svd(psi[b], (linkind(psi, b-1), s[b]))
for n in dim(S, 1)
p = S[n,n]^2
SvN[b] -= p * log(p)
end
println("$(SvN[b])")
end
return SvN
end
Please tell me if I need to add a “for loop” if I want to calculate the entanglement entropy of a subsystem that cuts off the first part and the second part at parameter b.