mbi.Domain

class mbi.Domain(attributes, shape, labels=None)[source]

Bases: object

Represents a discrete domain defined by attributes and their sizes.

This class encapsulates a set of named attributes and their corresponding discrete sizes (shapes). It provides methods for common domain operations.

attributes

A tuple containing the names of the attributes in the domain.

Type:

tuple[str, …]

shape

A tuple containing the integer sizes (number of discrete values) for each corresponding attribute in the attributes tuple.

Type:

tuple[int, …]

labels

An optional tuple of tuples containing semantic information (labels) for each attribute’s values. Must be the same length as attributes, and each inner tuple must have length corresponding to the attribute’s size.

Type:

tuple[tuple[Any, …], …] | None

Supported Operations:
  • Projection (project): Creates a new domain with a subset of attributes.

  • Marginalization (marginalize): Creates a new domain excluding specified attributes.

  • Intersection (intersect): Creates a new domain containing only common attributes.

  • Merging (merge): Combines two domains into a larger one.

  • Size Calculation (size): Computes the total number of configurations in the domain or a subset.

Example Usage (using fromdict):
>>> domain = Domain.fromdict({'a': 2, 'b': 3})
>>> print(domain)
Domain(a: 2, b: 3)

Method generated by attrs for class Domain.

Methods

__init__

Method generated by attrs for class Domain.

axes

Return the axes tuple for the given attributes.

canonical

Returns attributes common to the domain and input, maintaining the domain's order.

contains

Checks if this domain contains all attributes present in another domain.

fromdict

Construct a Domain object from a dictionary of { attr : size } values.

intersect

Intersect this Domain object with another.

invert

Returns attributes present in the domain but not in the provided list.

marginalize

Marginalize out some attributes from the domain (opposite of project).

merge

Merge this Domain object with another.

project

Project the domain onto a subset of attributes.

size

Return the total size of the domain.

supports

Attributes

attrs

Alias for the attributes tuple.

config

size } values.

labels_config

labels } values.

attributes

shape

labels

attributes: tuple[str, ...]
shape: tuple[int, ...]
labels: tuple[tuple[Any, ...], ...] | None
property config: dict[str, int]

size } values.

Type:

Returns a dictionary of { attr

property labels_config: dict[str, tuple[Any, ...]] | None

labels } values.

Type:

Returns a dictionary of { attr

static fromdict(config: dict[str, int]) Domain[source]

Construct a Domain object from a dictionary of { attr : size } values.

Example Usage:
>>> print(Domain.fromdict({'a': 10, 'b': 20}))
Domain(a: 10, b: 20)
Parameters:

config – a dictionary of { attr : size } values

Returns:

the Domain object

project(attributes: str | Sequence[str]) Domain[source]

Project the domain onto a subset of attributes.

Parameters:

attributes – the attributes to project onto

Returns:

the projected Domain object

marginalize(attrs: Sequence[str]) Domain[source]

Marginalize out some attributes from the domain (opposite of project).

Example Usage:
>>> D1 = Domain(['a','b'], [10,20])
>>> print(D1.marginalize(['a']))
Domain(b: 20)
Parameters:

attrs – the attributes to marginalize out.

Returns:

the marginalized Domain object

contains(other: Domain) bool[source]

Checks if this domain contains all attributes present in another domain.

canonical(attrs)[source]

Returns attributes common to the domain and input, maintaining the domain’s order.

invert(attrs)[source]

Returns attributes present in the domain but not in the provided list.

intersect(other: Domain) Domain[source]

Intersect this Domain object with another.

Example Usage:
>>> D1 = Domain(['a','b'], [10,20])
>>> D2 = Domain(['b','c'], [20,30])
>>> print(D1.intersect(D2))
Domain(b: 20)
Parameters:

other – another Domain object

Returns:

the intersection of the two domains

axes(attrs: Sequence[str]) tuple[int, ...][source]

Return the axes tuple for the given attributes.

Parameters:

attrs – the attributes

Returns:

a tuple with the corresponding axes

merge(other: Domain) Domain[source]

Merge this Domain object with another.

Parameters:

other – another Domain object

Returns:

a new domain object covering the full domain

Example

>>> D1 = Domain(['a','b'], [10,20])
>>> D2 = Domain(['b','c'], [20,30])
>>> print(D1.merge(D2))
Domain(a: 10, b: 20, c: 30)
Parameters:

other – another Domain object

Returns:

a new domain object covering the combined domain.

size(attributes: Sequence[str] | None = None) int[source]

Return the total size of the domain.

Example

>>> D1 = Domain(['a','b'], [10,20])
>>> D1.size()
200
>>> D1.size(['a'])
10
Parameters:

attributes – A subset of attributes whose total size should be returned.

Returns:

the total size of the domain

property attrs

Alias for the attributes tuple.

supports(attrs: str | Sequence[str]) bool[source]