mbi.CliqueVector

class mbi.CliqueVector(domain: Domain, cliques: Sequence[tuple[str | int, ...]], tables: dict[tuple[str | int, ...], 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 tuple of cliques (tuples of attribute names) for which factors are stored.

Type:

Sequence[Clique]

tables

A dictionary mapping each clique in cliques to its corresponding Factor object.

Type:

dict[Clique, Factor]

Methods

__init__

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

Returns the smallest-domain clique in this vector containing 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

tables

domain: Domain
cliques: Sequence[tuple[str | int, ...]]
tables: dict[tuple[str | int, ...], Factor]
classmethod zeros(domain: Domain, cliques: Sequence[tuple[str | int, ...]]) → CliqueVector[source]

Creates a CliqueVector initialized with zero factors for each clique.

classmethod ones(domain: Domain, cliques: Sequence[tuple[str | int, ...]]) → CliqueVector[source]

Creates a CliqueVector initialized with one factors for each clique.

classmethod random(domain: Domain, cliques: Sequence[tuple[str | int, ...]]) → CliqueVector[source]

Creates a CliqueVector initialized with random factors for each clique.

classmethod abstract(domain: Domain, cliques: Sequence[tuple[str | int, ...]]) → CliqueVector[source]
classmethod from_projectable(data: Projectable, cliques: Sequence[tuple[str | int, ...]]) → 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 | int, ...]) → tuple[str | int, ...] | None[source]

Returns the smallest-domain clique in this vector containing clique.

supports(clique: str | int | Sequence[str | int]) → bool[source]

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

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

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

normalize(total: Array | 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 | bool | int | float | complex[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.