Scope Management

Scope representation and manipulation for feature and random variable management in probabilistic circuits.

Scope

Represents scopes over random variables with query and evidence designations.

class spflow.meta.data.scope.Scope(query=None, evidence=None)[source]

Bases: object

Scopes over random variables (RVs).

Represents scope over random variables (RVs). Contains both RVs that are part of the query (i.e., RVs that are represented by the scope) as well as evidence of the scope (i.e., RVs that the scope is conditioned on).

query

List of non-negative integers representing query RVs.

evidence

List of non-negative integers representing evidence variables.

static all_equal(scopes)[source]

Checks if a sequence of scopes are all equal.

Parameters:

scopes (Iterable[Scope]) – Iterable of Scope objects to check for equality.

Return type:

bool

Returns:

Boolean indicating whether all scopes are equal (True) or not (False).

static all_pairwise_disjoint(scopes)[source]

Checks if a sequence of scopes are pairwise disjoint.

Parameters:

scopes (Iterable[Scope]) – Iterable of Scope objects to check pairwise disjointness.

Return type:

bool

Returns:

Boolean indicating whether all scopes are pairwise disjoint (True) or not (False).

static join_all(scopes)[source]

Computes the joint scope of the scope and a sequence of scopes.

The union of multiple scopes results in the union of the queries and evidences, respectively.

Parameters:

scopes (Iterable[Scope]) – Iterable of Scope objects to compute the union with.

Return type:

Scope

Returns:

Scope object representing the union of all scopes.

__init__(query=None, evidence=None)[source]

Initializes Scope object.

Parameters:
  • query (int | list[int] | tuple[int, ...] | None) – List of non-negative integers representing query RVs (may not contain duplicates). If a single integer is provided, it is converted to a list containing that integer.

  • evidence (int | list[int] | tuple[int, ...] | None) – Optional list of non-negative integers representing evidence variables (may not contain duplicates or RVs that are in the query). If a single integer is provided, it is converted to a list containing that integer. Defaults to None, in which case it is initialized to an empty list.

Raises:

ValueError – Invalid arguments.

copy()[source]

Creates a copy of the scope.

Return type:

Scope

Returns:

Scope object representing the copy of the scope.

empty()[source]

Checks if the scope is empty.

A scope is considered empty if its query is empty, i.e., the scope does not represent any RVs.

Return type:

bool

Returns:

Boolean indicating whether the scope is empty (True) or not (False).

equal_evidence(other)[source]

Checks if the evidence of the scope is identical to that of another.

The order of the evidence RVs is not important.

Parameters:

other (Scope) – Scope object to compare to.

Return type:

bool

Returns:

Boolean indicating whether both evidence scopes are identical (True) or not (False).

equal_query(other)[source]

Checks if the query of the scope is identical to that of another.

The order of the query RVs is not important.

Parameters:

other (Scope) – Scope object to compare to.

Return type:

bool

Returns:

Boolean indicating whether both query scopes are identical (True) or not (False).

is_conditional()[source]

Checks if the scope is conditional.

A scope is conditional if it contains evidence RVs.

Return type:

bool

Returns:

Boolean indicating whether the scope is conditional (True) or not (False).

isdisjoint(other)[source]

Checks if the scope is disjoint to another scope.

Two scopes are considered disjoint if their queries are disjoint, i.e., they do not represent any common RVs.

Parameters:

other (Scope) – Scope object to compare to.

Return type:

bool

Returns:

Boolean indicating whether the scopes are disjoint (True) or not (False).

join(other)[source]

Computes the joint scope of the scope and another scope.

Follows probabilistic semantics, i.e.: - p(X) * p(Z) = p(X,Z) - p(X) * p(Y|Z)= p(X,Y|Z) - p(X) * p(Y|X)= p(X,Y) - p(X|Y) * p(Z|W) = p(X,Z|Y,W) - p(X|Y) * p(Z|Y) = p(X,Z|Y) - p(X|Y) * p(Y|Z) = p(X,Y|Z)

Parameters:

other (Scope) – Scope object to compute the union with.

Return type:

Scope

Returns:

Scope object representing the union of both scopes.

remove_from_query(rv)[source]

Removes a random variable from the query of the scope.

Parameters:

rv (int) – Non-negative integer representing the random variable to remove.

Return type:

Scope

Returns:

Scope object with the variable removed, or None if query becomes empty.

evidence: tuple[int, ...]
query: tuple[int, ...]