Factor
Factors are used to represent the CPDs in the Bayesian network. As such, the core functionality, which are implemented, are the factor product, factor marginalization and factor reduction operations.
Attributes : |
|
---|
Factor Product Computes the product of two factors.
C.FactorProduct(A,B) computes the product between two factors, A and B, where each factor is defined over a set of variables with given dimension. The factor data structure has the following fields:
- .var Vector of variables in the factor, e.g. [1 2 3]
- .card Vector of cardinalities corresponding to .var, e.g. [2 2 2]
- .val Value table of size prod(.card)
Args : |
|
---|---|
Returns : |
|
Factor Marginalization Sums given variables out of a factor.
B = FactorMarginalization(A,V) computes the factor with the variables in V summed out. The factor data structure has the following fields:
- .var Vector of variables in the factor, e.g. [1 2 3]
- .card Vector of cardinalities corresponding to .var, e.g. [2 2 2]
- .val Value table of size prod(.card)
The resultant factor should have at least one variable remaining or this function will throw an error.
Args : |
|
---|---|
Returns : |
|
Observe Evidence Modify a vector of factors given some evidence.
F = ObserveEvidence(F, E) sets all entries in the vector of factors, F, that are not consistent with the evidence, E, to zero. F is a vector of factors, each a data structure with the following fields:
- .var Vector of variables in the factor, e.g. [1 2 3]
- .card Vector of cardinalities corresponding to .var, e.g. [2 2 2]
- .val Value table of size prod(.card)
Args : |
|
---|
Variables are in the first column and values are in the second column.
Returns : |
|
---|
Compute Joint Distribution computes the joint distribution defined by a set of given factors
Joint = ComputeJointDistribution(F) computes the joint distribution defined by a set of given factors
Joint is a factor that encapsulates the joint distribution given by F F is a vector of factors (struct array) containing the factors defining the distribution
Compute Marginal Computes the marginal over a set of given variables.
M = ComputeMarginal(V, F, E) computes the marginal over variables V in the distribution induced by the set of factors F, given evidence E
Args : |
Variables are in the first column and values are in the second column. If there is no evidence, pass in the empty matrix [] for E. |
---|---|
Returns : |
|
AssignmentToIndex Convert assignment to index.
I = AssignmentToIndex(A, D) converts an assignment, A, over variables with cardinality D to an index into the .val vector for a factor. If A is a matrix then the function converts each row of A to an index.
Args : |
|
---|---|
Returns : |
|
IndexToAssignment Convert index to variable assignment.
A = IndexToAssignment(I, D) converts an index, I, into the .val vector into an assignment over variables with cardinality D. If I is a vector, then the function produces a matrix of assignments, one assignment per row.
Args : |
|
---|---|
Returns : |
|