All problems
Variable Elimination Factor Size
Problem
Each factor in a graphical model covers a scope of variables given by a list of variable indices. Eliminating var multiplies the factors that contain it and sums it out, producing a new factor whose scope is the union of their scopes minus var. Return the number of entries in that new factor, the product of the cardinalities of its scope variables, or 0 when var appears in no scope or is out of range.
Hint
The intermediate factor costs the product of the cardinalities of the remaining variables.
Test cases
case 1
in: [[[0,1],[1,2]],[2,3,4],1]
expected: 8
case 2
in: [[[0,1],[1,2]],[2,3,4],0]
expected: 3
case 3
in: [[[0,1],[1,2]],[2,3,4],2]
expected: 3
case 4
in: [[[0,1],[1,2]],[2,3,4],3]
expected: 0
case 5
in: [[[0,1],[1,2]],[2,2,2],1]
expected: 4
Starter codePython
def variable_elimination_factor_size(scopes, cardinalities, var):
# Your code here
pass5 test cases · run your code against them in the editor