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:
objectScopes 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
Tuple of non-negative integers representing query RVs.
- evidence
Tuple of non-negative integers representing evidence variables.
- static all_equal(scopes)[source]
Checks if a sequence of scopes are all equal.
- static all_pairwise_disjoint(scopes)[source]
Checks if a sequence of scopes are pairwise disjoint.
- static as_scope(scope)[source]
Normalize a scope-like argument to a Scope.
- 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|Iterable[int] |None) – Non-negative integers representing query RVs. Can be a single integer, a list, tuple, numpy array, or torch tensor. May not contain duplicates. If None, initialized to an empty list.evidence (
int|Iterable[int] |None) – Optional non-negative integers representing evidence variables. Can be a single integer, a list, tuple, numpy array, or torch tensor. May not contain duplicates or RVs that are in the query. If None, 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:
- 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:
- 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:
- 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:
- 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:
- 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.