anypinn.core.validation
Validation registry for ground truth comparison during training and prediction.
ResolvedValidation: TypeAlias = dict[str, Callable[[Tensor], Tensor]]
module-attribute
Validation registry after ColumnRef entries have been resolved to callables.
ValidationRegistry: TypeAlias = dict[str, ValidationSource]
module-attribute
Registry mapping parameter names to their validation sources.
Example
validation: ValidationRegistry = { ... "beta": lambda x: torch.sin(x), # Pure function ... "gamma": ColumnRef(column="gamma_true"), # From data ... "delta": None, # No validation ... }
ValidationSource: TypeAlias = Callable[[Tensor], Tensor] | ColumnRef | None
module-attribute
A source for ground truth values. Can be: - A callable that takes x coordinates and returns true values - A ColumnRef that references a column in loaded data - None if no validation is needed for this parameter
ColumnRef
dataclass
Reference to a column in loaded data for ground truth comparison.
This allows practitioners to specify validation data by column name without writing custom functions. The column is resolved lazily when data is loaded.
Attributes:
| Name | Type | Description |
|---|---|---|
column |
str
|
Name of the column in the loaded DataFrame. |
transform |
Callable[[Tensor], Tensor] | None
|
Optional transformation to apply to the column values. |
Example
validation = { ... "beta": ColumnRef(column="Rt", transform=lambda rt: rt * delta), ... }
Source code in src/anypinn/core/validation.py
column: str
instance-attribute
transform: Callable[[Tensor], Tensor] | None = None
class-attribute
instance-attribute
__init__(column: str, transform: Callable[[Tensor], Tensor] | None = None) -> None
resolve_validation(registry: ValidationRegistry, df_path: Path | None = None) -> ResolvedValidation
Resolve a ValidationRegistry by converting ColumnRef entries to callables.
Pure function entries are passed through unchanged. ColumnRef entries are resolved using the provided data file path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
registry
|
ValidationRegistry
|
The validation registry to resolve. |
required |
df_path
|
Path | None
|
Path to the CSV file for ColumnRef resolution. |
None
|
Returns:
| Type | Description |
|---|---|
ResolvedValidation
|
A dictionary mapping parameter names to callable validation functions. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a ColumnRef cannot be resolved (missing column or no df_path). |