qp.math.marginal_prob¶
- marginal_prob(prob, axis)[source]¶
Compute the marginal probability given a joint probability distribution expressed as a tensor. Each random variable corresponds to a dimension.
If the distribution arises from a quantum circuit measured in computational basis, each dimension corresponds to a wire. For example, for a 2-qubit quantum circuit prob[0, 1] is the probability of measuring the first qubit in state 0 and the second in state 1.
- Parameters:
prob (tensor_like) – 1D tensor of probabilities. This tensor should of size
(2**N,)for some integer valueN.axis (list[int]) – the axis for which to calculate the marginal probability distribution
- Returns:
the marginal probabilities, of size
(2**len(axis),)- Return type:
tensor_like
Example
>>> x = torch.tensor([1, 0, 0, 1.], dtype=torch.float64) / np.sqrt(2) >>> marginal_prob(x, axis=[0, 1]) tensor([0.7071, 0.0000, 0.0000, 0.7071], dtype=torch.float64) >>> marginal_prob(x, axis=[0]) tensor([0.7071, 0.7071], dtype=torch.float64)