mbi.CliqueVector

class mbi.CliqueVector(domain: Domain, cliques: list[tuple[str, ...]], arrays: dict[tuple[str, ...], Factor])[source]

Bases: object

Manages 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.

domain

The overall domain that encompasses all cliques.

Type:

Domain

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.

abstract

apply_sharding

Apply sharding constraint to each factor in the CliqueVector.

contract

Computes a new CliqueVector by projecting this one onto a smaller set of cliques.

dot

Computes the dot product between this CliqueVector and another.

exp

Applies elementwise exponentiation (jnp.exp) to each factor.

expand

Re-expresses this CliqueVector over an expanded set of cliques.

from_projectable

Creates a CliqueVector by projecting a data source onto the specified cliques.

log

Applies elementwise logarithm (jnp.log) to each factor.

normalize

Normalizes each factor within the CliqueVector.

ones

Creates a CliqueVector initialized with one factors for each clique.

parent

Finds a clique in this vector that is a superset of the given clique.

project

random

Creates a CliqueVector initialized with random factors for each clique.

size

Calculates the total number of parameters across all factors in the vector.

supports

Checks if the given clique is supported (is a subset of any clique in the vector).

zeros

Creates a CliqueVector initialized with zero factors for each clique.

Attributes

active_domain

Returns the merged domain encompassing all attributes across all cliques.

domain

cliques

arrays

domain: Domain
cliques: list[tuple[str, ...]]
arrays: dict[tuple[str, ...], Factor]
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).

project(clique: tuple[str, ...], log: bool = False) Factor[source]
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.

size() int[source]

Calculates the total number of parameters across all factors in the vector.

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.