Base Model¶
Abstract base class and shared training configuration for all ALF models.
BaseTrainConfig is the shared dataclass that every concrete training config
(e.g. GPTrainConfig, CNNTrainConfig) inherits from. It exposes the
normalise_inputs_strategy and standardise_outputs fields that control data
transformation at training time.
- class alf_core.model.base_model.BaseModel[source]¶
Bases:
ABCBase class for all models. Several components of the framework can be treated as models, such as the surrogate, oracle, and the generator defined as model based search.
- cleanup()[source]¶
Clean up temporary files and resources.
Deletes any temporary files, checkpoints, or other resources that aren’t being persisted. Subclasses should override to implement cleanup logic.
- Return type:
None
- abstractmethod featurise(inputs)[source]¶
Convert inputs into feature representations.
- Parameters:
inputs (
list[Candidate]) – List of Candidate objects to featurize.- Return type:
Any- Returns:
Feature representation of the inputs (format depends on implementation).
- get_epoch_metrics()[source]¶
Return per-epoch training metrics from the most recent train() call.
- Return type:
list[SurrogateEpochMetrics]- Returns:
List of SurrogateEpochMetrics, one per epoch trained. Returns an empty list by default; subclasses that record per-epoch metrics should override.
- get_training_summary_metrics()[source]¶
Get summary metrics from the most recent training run.
- Return type:
dict[str,float|int|number]- Returns:
Dictionary of metric names to values. Returns empty dict by default; subclasses should override to provide metrics.
- output_dim: int¶
- abstractmethod predict(candidate_points)[source]¶
Predict scores for the given candidate points.
- Parameters:
candidate_points (
list[Candidate]) – List of Candidate objects to make predictions for.- Return type:
- Returns:
Predictions object containing means and optionally variances and empirical distributions.
- problem_type: ProblemType¶
- abstractmethod sample(condition=None)[source]¶
Sample candidate points from the model.
- Parameters:
condition (
Any|None) – Optional conditioning information for sampling.- Return type:
list[Candidate]- Returns:
List of sampled candidate points.
- setup(dataset)[source]¶
Configure the model for the given dataset. Called once before training begins.
For BINARY this is 1 (single logit, sigmoid-activated); see dataset.num_classes for the number of distinct classes.
- Parameters:
dataset (
BaseDataset) – The dataset this model will be trained on.- Return type:
None
- abstractmethod train(train_data, val_data=None)[source]¶
Train the model on the provided training and validation data.
- Parameters:
train_data (
LabelledCandidates) – Labeled candidates for training.val_data (
LabelledCandidates|None) – Labeled candidates for validation. When None, the model should skip validation metrics or handle the absence gracefully.
- Return type:
None
- class alf_core.model.base_model.BaseTrainConfig(learning_rate=0.001, log_frequency=10, normalise_inputs_strategy=None, standardise_outputs=False, label_dtype=None)[source]¶
Bases:
objectBase configuration shared by all model training configs.
- Parameters:
learning_rate (
float) – Learning rate for the optimizer.log_frequency (
int) – How often (in epochs/iterations) to log training metrics.normalise_inputs_strategy (
Optional[Literal['minmax','zscore']]) – Which input normalisation to apply before training:minmax(scale features to [0, 1]) orzscore(zero mean, unit variance). None disables input normalisation. Defaults to None.standardise_outputs (
bool) – Whether to apply Z-score standardisation to outputs before training. Defaults to False.label_dtype (
dtype|None) – dtype for label tensors during training. None means each model uses its own default (e.g. float32 for regression, long for classification). Override to force a specific dtype.
- label_dtype: dtype | None = None¶
- learning_rate: float = 0.001¶
- log_frequency: int = 10¶
- normalise_inputs_strategy: Literal['minmax', 'zscore'] | None = None¶
- standardise_outputs: bool = False¶