Tensor.randomCPT
- Tensor.randomCPT(*args)
Fill the tensor as a random conditional probability table.
For each configuration of the other variables, the distribution of the conditioned variable is drawn uniformly on the probability simplex, i.e. from a Dirichlet distribution of parameter 1.
- Parameters:
varId (
int) – the position of the conditioned variable in the tensor (default: 0, the first variable)- Returns:
self (in-place modification)
- Return type:
- Raises:
pyagrum.OutOfBounds – if varId is not a position of a variable of the tensor
Example
import pyagrum as gum
gum.initRandom(42)
a, b = gum.LabelizedVariable("a", "a", 2), gum.LabelizedVariable("b", "b", 3)
p = gum.Tensor().add(a).add(b).randomCPT() # a distribution over a for each value of b
[round(x, 4) for x in p.sumOut(["a"]).tolist()]
# [1.0, 1.0, 1.0]
Class