MPSKit.jl
MPSKit.jl copied to clipboard
entropy may sometimes return NaN
The current entropy function sometimes fails by returning NaN. This occurs for example after using changebonds to increase the bond dimension of a state. Perhaps it is better to use something like this?
function entropy(state::Union{FiniteMPS,MPSComoving,InfiniteMPS},n::Int=0)
pv = entanglement_spectrum(state,n).^2 .+ 1e-20
-sum(log.(pv) .* pv)
end
I guess the error comes only from entanglement values which are exactly zero.
Maybe it's better to define a more robust function to compute x*log(x)
that deals with x=0
properly, and use this in the definition.
I have pushed a potential fix, but I'm not yet completely happy (I want entropy(finitemps) to just work, but currently it complains about the non-existence of similar(CRView)).
I'm against using entanglement_spectrum, as it turns the tensormap into an array, which is not always defined (anyonic symmetries) while the entanglement entropy still is defined in those cases.