Training Statistics

qucumber.utils.training_statistics.KL(nn_state, target, space=None, bases=None, **kwargs)[source]

A function for calculating the KL divergence averaged over every given basis.

KL(P_{target} \vert P_{RBM}) = -\sum_{x \in \mathcal{H}} P_{target}(x)\log(\frac{P_{RBM}(x)}{P_{target}(x)})

Parameters
  • nn_state (qucumber.nn_states.NeuralStateBase) – The neural network state.

  • target (torch.Tensor or dict(str, torch.Tensor)) – The true state (wavefunction or density matrix) of the system. Can be a dictionary with each value being the state represented in a different basis, and the key identifying the basis.

  • space (torch.Tensor) – The basis elements of the Hilbert space of the system \mathcal{H}. The ordering of the basis elements must match with the ordering of the coefficients given in target. If None, will generate them using the provided nn_state.

  • bases (numpy.ndarray) – An array of unique bases. If given, the KL divergence will be computed for each basis and the average will be returned.

  • **kwargs – Extra keyword arguments that may be passed. Will be ignored.

Returns

The KL divergence.

Return type

float

qucumber.utils.training_statistics.NLL(nn_state, samples, space=None, sample_bases=None, **kwargs)[source]

A function for calculating the negative log-likelihood (NLL).

Parameters
  • nn_state (qucumber.nn_states.NeuralStateBase) – The neural network state.

  • samples (torch.Tensor) – Samples to compute the NLL on.

  • space (torch.Tensor) – The basis elements of the Hilbert space of the system \mathcal{H}. If None, will generate them using the provided nn_state.

  • sample_bases (numpy.ndarray) – An array of bases where measurements were taken.

  • **kwargs – Extra keyword arguments that may be passed. Will be ignored.

Returns

The Negative Log-Likelihood.

Return type

float

qucumber.utils.training_statistics.fidelity(nn_state, target, space=None, **kwargs)[source]

Calculates the square of the overlap (fidelity) between the reconstructed state and the true state (both in the computational basis).

F = \vert \langle \psi_{RBM} \vert \psi_{target} \rangle \vert ^2
  = \left( \tr \lbrack \sqrt{ \sqrt{\rho_{RBM}} \rho_{target} \sqrt{\rho_{RBM}} } \rbrack \right) ^ 2

Parameters
  • nn_state (qucumber.nn_states.NeuralStateBase) – The neural network state.

  • target (torch.Tensor) – The true state of the system.

  • space (torch.Tensor) – The basis elements of the Hilbert space of the system \mathcal{H}. The ordering of the basis elements must match with the ordering of the coefficients given in target. If None, will generate them using the provided nn_state.

  • **kwargs – Extra keyword arguments that may be passed. Will be ignored.

Returns

The fidelity.

Return type

float