Skip to content

Commit

Permalink
update docstrings for BEE/SEE
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuabmoore committed Dec 24, 2024
1 parent 817a684 commit 0bbd45d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
3 changes: 2 additions & 1 deletion docs/src/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ A vector is returned where each entry contains the BEE spectrum for the class-sp
For example, in the case of a two class problem, we obtain the individual BEE spectrums for the class 0 MPS and the class 1 MPS.
For an unsupervised problem with only a single class, there is only a single BEE spectrum.
#### Example
To illustrate how we might use the BEE in a typical analysis, consider an example involving real world time series from the [ItalyPowerDemand](https://www.timeseriesclassification.com/description.php?Dataset=ItalyPowerDemand) UCR dataset.
To illustrate how we might use the BEE in a typical analysis, consider an example involving real world time series from the [ItalyPowerDemand](https://www.timeseriesclassification.com/description.php?Dataset=ItalyPowerDemand) (IPD) UCR dataset.
There are two classes corresponding to the power demand during: __(i)__ the winter months; __(ii)__ the summer months.
For this example, we will train an MPS to classify between summer and winter time-series data:
```Julia
Expand Down Expand Up @@ -74,4 +74,5 @@ MPSTime.bipartite_spectrum
## Internal Methods
```@docs
MPSTime.von_neumann_entropy
MPSTime.one_site_rdm
```
37 changes: 22 additions & 15 deletions src/Analysis/analyse.jl
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
"""
```Julia
von_neumann_entropy(mps::MPS; logfn::Function=log) -> Vector{Float64}
```
Compute the [von Neumann entanglement entropy](https://en.wikipedia.org/wiki/Entropy_of_entanglement) for each site in a Matrix Product State (MPS).
single_site_spectrum(mps::TrainedMPS) -> Vector{Vector{Float64}}
Compute the single-site entanglement entropy (SEE) spectrum of a trained MPS.
The von Neumann entropy quantifies the entanglement at each bond of the MPS by computing the entropy of the singular value spectrum obtained from a singular value decomposition (SVD). The entropy is computed as:
The single-site entanglement entropy (SEE) quantifies the entanglement between each site in the MPS and all other sites. It is computed as:
[ S = -sum_{i} p_i log(p_i) ]
``\\text{SEE} = -\\text{tr}(\\rho \\log(\\rho))``
where ( p_i ) are the squared singular values normalized to sum to 1.
where ``\\rho`` is the single-site reduced density matrix (RDM).
# Arguments
- `mps::MPS`: The Matrix Product State (MPS) whose entanglement entropy is to be computed.
- `logfn::Function`: (Optional) The logarithm function to use (`log`, `log2`, or `log10`). Defaults to the natural logarithm (`log`).
- `mps::TrainedMPS`: A trained Matrix Product State (MPS) object, which includes the MPS and associated labels.
# Returns
A vector of `Float64` values where the i-th element represents the von Neumann entropy at site i of the MPS.
A vector of vectors, where the outer vector corresponds to each label in the expanded MPS, and the inner vectors contain the SEE values for the respective sites.
"""
function von_neumann_entropy(mps::MPS, logfn::Function=log)
# adapted from http://itensor.org/docs.cgi?page=formulas/entanglement_mps
Expand Down Expand Up @@ -51,8 +49,8 @@ bipartite_spectrum(mps::TrainedMPS; logfn::Function=log) -> Vector{Vector{Float6
Compute the bipartite entanglement entropy (BEE) of a trained MPS across each bond.
Given a single unlabeled MPS the BEE is defined as:
∑ α^2 log(α^2)
where α are the eigenvalues obtained from the shmidt decomposition.
``\\sum_i \\alpha_i^2 \\log(\\alpha_i^2)``
where ``\\alpha_i`` are the eigenvalues obtained from the shmidt decomposition.
Compute the bipartite entanglement entropy (BEE) of a trained MPS.
"""
Expand Down Expand Up @@ -92,6 +90,15 @@ function rho_correct(rho::Matrix, eigentol::Float64=sqrt(eps()))
return rho_corrected
end

"""
```Julia
one_site_rdm(mps::MPS, site::Int) -> Matrix
```
Compute the single-site reduced density matrix (RDM) of the
MPS at a given site.
If the RDM is not positive semidefinite, clamp the negative eigenvalues
(if within the tolerance) and reconstruct the rdm.
"""
function one_site_rdm(mps::MPS, site::Int)
s = siteinds(mps)
orthogonalize!(mps, site)
Expand Down Expand Up @@ -120,12 +127,12 @@ Compute the single-site entanglement entropy (SEE) spectrum of a trained MPS.
The single-site entanglement entropy (SEE) quantifies the entanglement at each site of the MPS. It is computed as:
[ SEE = -tr(ρ ⋅ log(ρ)) ]
``\\text{SEE} = -\\text{tr}(\\rho \\log(\\rho))``
where ρ is the single-site reduced density matrix (RDM).
where ``\\rho`` is the single-site reduced density matrix (RDM).
# Arguments
- `mps::TrainedMPS`: A trained Matrix Product State (MPS) object, which includes the MPS and associated labels.
- `mps::TrainedMPS`: A trained Matrix Product State (MPS).
# Returns
A vector of vectors, where the outer vector corresponds to each label in the expanded MPS, and the inner vectors contain the SEE values for the respective sites.
Expand Down

0 comments on commit 0bbd45d

Please sign in to comment.