mbi.CliqueVector
- class mbi.CliqueVector(domain: Domain, cliques: list[tuple[str, ...]], arrays: dict[tuple[str, ...], Factor])[source]
Bases:
objectManages a collection of factors, each associated with a clique.
This class provides a structure for holding and operating on multiple Factor objects, where each factor corresponds to a clique (a subset of attributes) within a larger domain. It’s particularly useful in the context of graphical models for representing sets of potentials or marginals.
- cliques
A list of cliques (tuples of attribute names) for which factors are stored.
- Type:
list[Clique]
- arrays
A dictionary mapping each clique in cliques to its corresponding Factor object.
- Type:
dict[Clique, Factor]
Method generated by attrs for class CliqueVector.
Methods
__init__Method generated by attrs for class CliqueVector.
Apply sharding constraint to each factor in the CliqueVector.
Computes a new CliqueVector by projecting this one onto a smaller set of cliques.
Computes the dot product between this CliqueVector and another.
Applies elementwise exponentiation (jnp.exp) to each factor.
Re-expresses this CliqueVector over an expanded set of cliques.
Creates a CliqueVector by projecting a data source onto the specified cliques.
Applies elementwise logarithm (jnp.log) to each factor.
Normalizes each factor within the CliqueVector.
Creates a CliqueVector initialized with one factors for each clique.
Finds a clique in this vector that is a superset of the given clique.
Creates a CliqueVector initialized with random factors for each clique.
Calculates the total number of parameters across all factors in the vector.
Checks if the given clique is supported (is a subset of any clique in the vector).
Creates a CliqueVector initialized with zero factors for each clique.
Attributes
Returns the merged domain encompassing all attributes across all cliques.
- cliques: list[tuple[str, ...]]
- classmethod zeros(domain: Domain, cliques: list[tuple[str, ...]]) CliqueVector[source]
Creates a CliqueVector initialized with zero factors for each clique.
- classmethod ones(domain: Domain, cliques: list[tuple[str, ...]]) CliqueVector[source]
Creates a CliqueVector initialized with one factors for each clique.
- classmethod random(domain: Domain, cliques: list[tuple[str, ...]]) CliqueVector[source]
Creates a CliqueVector initialized with random factors for each clique.
- classmethod abstract(domain: Domain, cliques: list[tuple[str, ...]]) CliqueVector[source]
- classmethod from_projectable(data: Projectable, cliques: list[tuple[str, ...]]) CliqueVector[source]
Creates a CliqueVector by projecting a data source onto the specified cliques.
- property active_domain: Domain
Returns the merged domain encompassing all attributes across all cliques.
- parent(clique: tuple[str, ...]) tuple[str, ...] | None[source]
Finds a clique in this vector that is a superset of the given clique.
- supports(clique: tuple[str, ...]) bool[source]
Checks if the given clique is supported (is a subset of any clique in the vector).
- expand(cliques: list[tuple[str, ...]]) CliqueVector[source]
Re-expresses this CliqueVector over an expanded set of cliques.
If the original CliqueVector represents the potentials of a Graphical Model, the given cliques support the cliques in the original CliqueVector, then the distribution represented by the new CliqueVector will be identical.
- Parameters:
cliques – The new cliques the clique vector will be defined over.
- Returns:
An expanded CliqueVector defined over the given set of cliques.
- contract(cliques: list[tuple[str, ...]], log: bool = False) CliqueVector[source]
Computes a new CliqueVector by projecting this one onto a smaller set of cliques.
- normalize(total: float = 1, log: bool = True) CliqueVector[source]
Normalizes each factor within the CliqueVector.
- exp() CliqueVector[source]
Applies elementwise exponentiation (jnp.exp) to each factor.
- log() CliqueVector[source]
Applies elementwise logarithm (jnp.log) to each factor.
- dot(other: CliqueVector) Array | ndarray | bool | number | float | int[source]
Computes the dot product between this CliqueVector and another.
- apply_sharding(mesh: Mesh | None) CliqueVector[source]
Apply sharding constraint to each factor in the CliqueVector.
The sharding strategy is automatically determined based on the provided mesh and the factor domains.
- Parameters:
mesh – The mesh over which the factors should be sharded.
- Returns:
A new CliqueVector identical to self with sharding constraints applied to the underlying factors.