torch_concepts.InputVariable¶
- class InputVariable(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 a latent variable in a concept-based model.
Latent variables are high-dimensional global representations of the whole input object (e.g., raw input images, text, or sensor data). They capture the complete information about the input before it is decomposed into specific concepts. These are typically unobserved, learned representations that encode all relevant information from the raw input.
- distribution¶
PyTorch distribution class for this variable.
- Type:
Type[Distribution]
- metadata¶
Additional metadata. Automatically includes ‘variable_type’: ‘input’.
- Type:
Dict[str, Any]
Example
>>> from torch_concepts.distributions import Delta >>> from torch_concepts import InputVariable >>> # Global latent representation from input image >>> image_latent = InputVariable( ... concepts='global_image_features', ... parents=[], ... distribution=Delta, ... size=512 # 512-dimensional global latent ... ) >>> >>> # Multiple latent variables for hierarchical representation >>> low_level_features = InputVariable( ... concepts='low_level_features', ... parents=[], ... distribution=Delta, ... size=256 ... ) >>> high_level_features = InputVariable( ... concepts='high_level_features', ... parents=[low_level_features], ... distribution=Delta, ... size=512 ... )
- __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 a InputVariable instance.
- Parameters:
concepts – Single concept name or list of concept names.
parents – List of parent Variable instances (often empty for root latent variables).
distribution – Distribution type (typically Delta or Normal for continuous representations).
size – Dimensionality of the latent representation.
metadata – Optional metadata dictionary.
Methods
__init__(concepts, parents[, distribution, ...])Initialize a InputVariable instance.
Attributes
in_featuresCalculate total input features from all parent variables.
out_featuresCalculate the number of output features for this variable.