tablecpdfactor

This module provides tools for creating and using an individual factorized representation of a node. See description of factorized representations in tablecpdfactorization.

class libpgm.tablecpdfactor.TableCPDFactor(vertex, bn)[source]

This class represents a factorized representation of a conditional probability distribution table. It contains the attributes inputvertex, inputbn, vals, scope, stride, and card, and the methods multiplyfactor, sumout, reducefactor, and copy.

This class is constructed with a DiscreteBayesianNetwork instance and a vertex name as arguments. First it stores these inputs in inputvertex and inputbn. Then, it creates a factorized representation of vertex, storing the values in vals, the names of the variables involved in scope the cardinality of each of these variables in card and the stride of each of these variables in stride.

inputvertex = None

The name of the vertex.

inputbn = None

The DiscreteBayesianNetwork instance that the vertex lives in.

vals = None

A flat array of all the values from the CPD.

scope = None

An array of vertices that affect the vals found in vals. Normally, this is the node itself and its parents.

card = None

A list of the cardinalities of each vertex in scope, where cardinality is the number of values that the vertex may take. The cardinalities are indexed according to the vertex’s index in scope.

stride = None

A dict of {vertex: value} pairs for each vertex in scope, where vertex is the name of the vertex and value is the stride of that vertex in the vals array.

multiplyfactor(other)[source]

Multiply the factor by another TableCPDFactor. Multiplying factors means taking the union of the scopes, and for each combination of variables in the scope, multiplying together the probabilities from each factor that that combination will be found.

Arguments:
  1. other – An instance of the TableCPDFactor class representing the factor to multiply by.
Attributes modified:
vals, scope, stride, card – Modified to reflect the data of the new product factor.

For more information cf. Koller et al. 359.

sumout(vertex)[source]

Sum out the variable specified by vertex from the factor. Summing out means summing all sets of entries together where vertex is the only variable changing in the set. Then vertex is removed from the scope of the factor.

Arguments:
  1. vertex – The name of the variable to be summed out.
Attributes modified:
vals, scope, stride, card – Modified to reflect the data of the summed-out product factor.

For more information see Koller et al. 297.

reducefactor(vertex, value)[source]

Reduce the factor knowing that vertex equals value. Reducing the factor means erasing all possibilities for vertex other than value from the distribution, and removing vertex from the scope.

Arguments:
  1. vertex – The UUID of the variable whose outcome is known.
  2. value – The known outcome of that variable.
Attributes modified:
vals, scope, stride, card – Modified to reflect the data of the reduced factor.
copy()[source]

Return a copy of the factor.

Previous topic

tablecpdfactorization

Next topic

sampleaggregator

This Page