gpytorchwrapper.src.models.model_train
Functions
Helper function to print the model parameters generated by model_parameters() |
|
|
Define the likelihood used for training the model |
|
|
|
Define the optimizer used for training the model |
|
Plot the change of loss during training |
|
Helper function to get the current model parameters and parameter values. |
|
Train the model using the training data |
|
The training loop for the model |
- gpytorchwrapper.src.models.model_train.create_model_parameters_string(parameter_names: list[str], parameters: list[Tensor | None]) str [source]
Helper function to print the model parameters generated by model_parameters()
- Parameters:
parameter_names (list of string) – The parameter name strings
parameters (list of Tensor and/or None) – The parameter values
- Returns:
return – The string to print
- Return type:
str
- gpytorchwrapper.src.models.model_train.define_likelihood(likelihood_conf: LikelihoodConf, likelihood_class: Likelihood, train_x: Tensor)[source]
Define the likelihood used for training the model
- Parameters:
likelihood_conf (OptimizerConf) – Configuration dataclass that specifies the options for the likelihood
likelihood_class (Likelihood) – Likelihood class to instantiate
train_x (Tensor) – The training input tensor
- Returns:
optimizer – The optimizer for the model
- Return type:
object
- Raises:
KeyError – If a fixed noise likelihood is selected but the noise level is not specified
- gpytorchwrapper.src.models.model_train.define_model(model_conf: ModelConf, model_class: ExactGP, train_x: Tensor, train_y: Tensor, likelihood: Likelihood) ExactGP [source]
- Parameters:
model_conf (ModelConf) – Model configuration dataclass
model_class (ExactGP) – Model class
train_x (Tensor) – The training input tensor
train_y (Tensor) – The training output tensor
likelihood (Likelihood) – Likelihood object
- Returns:
Instantiated model
- Return type:
Tensor or Distribution or LinearOperator
- gpytorchwrapper.src.models.model_train.define_optimizer(model: ExactGP, optimizer_conf: OptimizerConf) Optimizer [source]
Define the optimizer used for training the model
- Parameters:
model (object) – The model to be optimized
optimizer_conf (OptimizerConf) – Configuration dataclass that specifies the options for the optimizer
- Returns:
optimizer – The optimizer for the model
- Return type:
object
- gpytorchwrapper.src.models.model_train.loss_figure(train_loss: list[float], iteration: list[int], val_loss: list[float] = None) None [source]
Plot the change of loss during training
- Parameters:
loss (list) – List containing the loss values
iteration (list) – List containing the iteration values
- Return type:
None
- gpytorchwrapper.src.models.model_train.model_parameters(model: ExactGP, transformed: bool = True) tuple[list[str], list[Tensor | None]] [source]
Helper function to get the current model parameters and parameter values.
- Parameters:
model (ExactGP) – The model object
transformed (bool, default True) – If the parameters must be transformed from the raw parameters used by the model to human-readable ones.
- Returns:
parameter_names, parameters – A tuple containing the parameter names and their values
- Return type:
tuple of list of str and list of (Tensor or None)
- gpytorchwrapper.src.models.model_train.train_model(train_x: Tensor, train_y: Tensor, training_conf: TrainingConf, test_x: Tensor = None, test_y: Tensor = None) tuple[ExactGP, GaussianLikelihood | MultitaskGaussianLikelihood, dict[str, list[float]]] [source]
Train the model using the training data
- Parameters:
train_x (torch.Tensor) – The input training data
train_y (torch.Tensor) – The output training data
training_conf (TrainingConf) – Dictionary containing the training specifications
test_x (Tensor) – The input test data
test_y (Tensor) – The output test data
- Returns:
model (ExactGP) – The trained model
likelihood (Likelihood) – The likelihood of the trained model
parameter_dict (dict) – Dictionary containing the parameter values after training
- gpytorchwrapper.src.models.model_train.training_loop(train_x: Tensor, train_y: Tensor, model: ExactGP, mll: MarginalLogLikelihood, optimizer: Optimizer, learning_iterations: int, debug: bool, test_x: Tensor = None, test_y: Tensor = None) None [source]
The training loop for the model
- Parameters:
train_x (torch.Tensor) – The input training data
train_y (torch.Tensor) – The output training data
model (object) – The model to be trained
mll (MarginalLogLikelihood) – The marginal likelihood of the model
optimizer (object) – The optimizer for the model
learning_iterations (int) – The number of iterations to train the model
debug (bool) – Whether to use the debug mode in GPyTorch. Turn off if unwanted debug exceptions interfere with training.
test_x
test_y
- Return type:
None