Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The updated docstring
Query the marginals of the variables in a
TensorNetworkModel
.The returned value is a dictionary of variables and their marginals, where a marginal is a joint probability distribution over the associated variables.
By default, the marginals of all individual variables are returned.
The marginal variables to query can be specified when constructing
TensorNetworkModel
as its fieldmars
.It will affect the contraction order of the tensor network.
Arguments
tn
: theTensorNetworkModel
to query.usecuda
: whether to use CUDA for tensor contraction.rescale
: whether to rescale the tensors during contraction.Example
The following example is from
examples/asia/main.jl
.In this example, we first set the evidence of variable 1 to 0, then we query the marginals of all individual variables.
The returned values is a dictionary, the key are query variables, and the value are the corresponding marginals.
The marginals are vectors, with its entries corresponding to the probability of the variable taking the value 0 and 1, respectively.
For evidence variable 1, the marginal is always
[1.0]
, since it is fixed to 0.Then we set the marginal variables to query to be variable 2 and 3, and variable 3 and 4, respectively.
The joint marginals may or may not increase the contraction time and space.
Here, the contraction space complexity is increased from 2^2.0 to 2^5.0, and the contraction time complexity is increased from 2^5.977 to 2^7.781.
The output marginals are joint probabilities of the query variables represented by tensors.