MPSKit.jl icon indicating copy to clipboard operation
MPSKit.jl copied to clipboard

entropy may sometimes return NaN

Open HumpyBlumpy opened this issue 2 years ago • 2 comments

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

HumpyBlumpy avatar Sep 03 '22 18:09 HumpyBlumpy

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.

Jutho avatar Sep 03 '22 20:09 Jutho

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.

maartenvd avatar Sep 07 '22 10:09 maartenvd