torch_concepts.EndogenousVariable

class EndogenousVariable(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 endogenous variable in a concept-based model.

Endogenous variables are observable and supervisable concepts that can be directly measured or annotated in the data. These are typically the concepts that we want to learn and predict, such as object attributes, semantic features, or intermediate representations that have ground truth labels.

concepts

List of concept names represented by this variable.

Type:

List[str]

parents

List of parent variables in the graphical model.

Type:

List[Variable]

distribution

PyTorch distribution class for this variable.

Type:

Type[Distribution]

size

Size/cardinality of the variable.

Type:

int

metadata

Additional metadata. Automatically includes ‘variable_type’: ‘endogenous’.

Type:

Dict[str, Any]

Example

>>> from torch.distributions import Bernoulli, Categorical
>>> from torch_concepts import EndogenousVariable
>>> # Observable binary concept
>>> has_wings = EndogenousVariable(
...     concepts='has_wings',
...     parents=[],
...     distribution=Bernoulli,
...     size=1
... )
>>>
>>> # Observable categorical concept (e.g., color)
>>> color = EndogenousVariable(
...     concepts=['color'],
...     parents=[],
...     distribution=Categorical,
...     size=3  # red, green, blue
... )
__init__(concepts: str | 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]

Initialize an EndogenousVariable instance.

Parameters:
  • concepts – Single concept name or list of concept names.

  • parents – List of parent Variable instances.

  • distribution – Distribution type (Delta, Bernoulli, Categorical, or Normal).

  • size – Size parameter for the distribution.

  • metadata – Optional metadata dictionary.

Methods

__init__(concepts, parents[, distribution, ...])

Initialize an EndogenousVariable instance.

Attributes

in_features

Calculate total input features from all parent variables.

out_features

Calculate the number of output features for this variable.