ProbTable
Implementation of probability table using Torch tensor
ProbTable:__init(P, names)
Constructor.
Arguments:
P
(torch.tensor
): probability Tensor, thei
th dimension corresponds to thei
th variable.names
(table[string]
): A table of names for the variables. By default theses will be assigned using indices.
Example:. Optional.
local t = ProbTable(torch.Tensor{{0.2, 0.8}, {0.4, 0.6}, {0.1, 0.9}}, {'a', 'b'})
t:query{a=1, b=2} 0.8
t:query{a=2} Tensor{0.4, 0.6}
ProbTable:size()
Returns:
- (
int
) number of variables in the table
ProbTable:query(dict)
Arguments:
dict
(table[string
): an assignment to consider
Example:. Optional, Default: int]
.
Returns:
- (
torch.Tensor
) probabilities for the assignments indict
.
local t = ProbTable(torch.Tensor{{0.2, 0.8}, {0.4, 0.6}, {0.1, 0.9}}, {'a', 'b'})
t:query{a=1, b=2}
t:query{a=2}
The first query is 0.8
. The second query is Tensor{0.4, 0.6}
ProbTable:clone()
Returns:
- (
ProbTable
) a copy
ProbTable:__tostring__()
Returns:
- (
string
) string representation
ProbTable:mul(B)
Returns a new table that is the product of two tables.
Arguments:
B
(ProbTable
): another table.
Returns:
- (
ProbTable
) product of this and another table
ProbTable:marginalize(name)
Marginalizes this probability table in place.
Arguments:
name
(string
): the variable to marginalize.
Returns:
- (
ProbTable
) this probability table with the variablename
marginalized out
ProbTable:marginal(name)
Marginalizes this probability table in place to calculate a marginal.
Arguments:
name
(string
): the variable to calculate.
Returns:
- (
ProbTable
) this probability table marginalizing all variables exceptname
ProbTable:normalize()
Normalizes this table by dividing by the sum of all probabilities.
Returns:
- (
ProbTable
) normalized table