torch_concepts.ExogenousVariable¶
- class ExogenousVariable(concepts: List[str], parents: List[Variable | str], distribution: Type[Distribution] | List[Type[Distribution]] | None = None, size: int | List[int] = 1, metadata: Dict[str, Any] | None = None)[source]¶
Represents an exogenous variable in a concept-based model.
Exogenous variables are high-dimensional representations related to a single endogenous variable. They capture rich, detailed information about a specific concept (e.g., image patches, embeddings, or feature vectors) that can be used to predict or explain the corresponding endogenous concept.
- distribution¶
PyTorch distribution class for this variable.
- Type:
Type[Distribution]
- endogenous_var¶
The endogenous variable this exogenous variable is related to.
- Type:
Optional[EndogenousVariable]
- metadata¶
Additional metadata. Automatically includes ‘variable_type’: ‘exogenous’.
- Type:
Dict[str, Any]
Example
>>> from torch.distributions import Normal, Bernoulli >>> from torch_concepts.distributions import Delta >>> from torch_concepts import EndogenousVariable, ExogenousVariable >>> # Endogenous concept >>> has_wings = EndogenousVariable( ... concepts='has_wings', ... parents=[], ... distribution=Bernoulli, ... size=1 ... ) >>> >>> # Exogenous high-dim representation for has_wings >>> wings_features = ExogenousVariable( ... concepts='wings_exogenous', ... parents=[], ... distribution=Delta, ... size=128, # 128-dimensional exogenous ... )
- __init__(concepts: str | List[str], parents: List[Variable | str], distribution: Type[Distribution] | List[Type[Distribution]] | None = None, size: int | List[int] = 1, endogenous_var: EndogenousVariable | None = None, metadata: Dict[str, Any] | None = None)[source]¶
Initialize an ExogenousVariable instance.
- Parameters:
concepts – Single concept name or list of concept names.
parents – List of parent Variable instances.
distribution – Distribution type (typically Delta or Normal for continuous representations).
size – Dimensionality of the high-dimensional representation.
endogenous_var – Optional reference to the related endogenous variable.
metadata – Optional metadata dictionary.
Methods
__init__(concepts, parents[, distribution, ...])Initialize an ExogenousVariable instance.
Attributes
in_featuresCalculate total input features from all parent variables.
out_featuresCalculate the number of output features for this variable.