ProbTable

Implementation of probability table using Torch tensor

ProbTable:__init(P, names)

View source

Constructor.

Arguments:

  • P (torch.tensor): probability Tensor, the ith dimension corresponds to the ith 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()

View source

Returns:

  • (int) number of variables in the table

ProbTable:query(dict)

View source

Arguments:

  • dict (table[string): an assignment to consider

Example:. Optional, Default: int].

Returns:

  • (torch.Tensor) probabilities for the assignments in dict.
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()

View source

Returns:

  • (ProbTable) a copy

ProbTable:__tostring__()

View source

Returns:

  • (string) string representation

ProbTable:mul(B)

View source

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)

View source

Marginalizes this probability table in place.

Arguments:

  • name (string): the variable to marginalize.

Returns:

  • (ProbTable) this probability table with the variable name marginalized out

ProbTable:marginal(name)

View source

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 except name

ProbTable:normalize()

View source

Normalizes this table by dividing by the sum of all probabilities.

Returns:

  • (ProbTable) normalized table