vopy.models
- class vopy.models.Model
Defines the abstract model class.
- class vopy.models.ModelList
Defines the abstract model list class.
- class vopy.models.UncertaintyPredictiveModel
Defines the abstract uncertainty predictive model class, which gives mean and variance estimates as predictions.
- class vopy.models.GPModel
Defines the abstract Gaussian process model (GP) class.
- get_kernel_type()
Get the kernel type of the GP model.
- get_lengthscale_and_var()
Get the lengthscale and variance of the GP model.
Empirical Models
EmpiricalMeanVarModel
- class vopy.models.EmpiricalMeanVarModel(input_dim: int, output_dim: int, noise_var: float, design_count: int, track_means: bool = True, track_variances: bool = True)
Implements a model that tracks empirical means and variances for each design.
This class tracks the empirical means and variances for each design in the input space, controlled by flags track_means and track_variances.
- Parameters:
input_dim (int) – The dimension of the input space.
output_dim (int) – The dimension of the output space.
noise_var (float) – The variance of the noise in the output space.
design_count (int) – The number of designs to track.
track_means (bool) – A flag to enable/disable tracking of means, defaults to True.
track_variances (bool) – A flag to enable/disable tracking of variances, defaults to True.
- add_sample(indices: Iterable[int], Y_t: numpy.ndarray)
Add new samples for specified design indices.
- Parameters:
indices (Iterable[int]) – Represents the indices of designs to which the samples belong.
Y_t (np.ndarray) – A N-by-output_dim array containing the new samples to be added.
- clear_data()
This method generates/clears the sample containers.
- predict(test_X: numpy.ndarray) tuple[numpy.ndarray, numpy.ndarray]
This method takes test inputs and returns the predicted means and variances based on the tracked data. If track_means is enabled, it returns the corresponding means for the test inputs. If track_variances is enabled, it returns the corresponding variances for the test inputs.
- Parameters:
test_X (np.ndarray) – The test inputs for which predictions are to be made. The last column of test_X should contain indices.
- Returns:
A tuple containing two numpy arrays: the predicted means and variances.
- Return type:
tuple[np.ndarray, np.ndarray]
- train()
This method is a no-op for this model.
- update()
This method calculates and updates the means and variances of the design samples based on the current data. If track_means is enabled, it updates the means attribute with the mean of each design sample. If track_variances is enabled, it updates the variances attribute with the variance of each design sample.
Gaussian Process Based Models
- class vopy.models.GPyTorchModel
Base class for Gaussian Process models using GPyTorch. Provides utility methods for data handling and kernel type identification.
- get_kernel_type() Literal['RBF', 'Other']
Identify the type of kernel used in the model iteratively.
- Returns:
Kernel type as a string. Currently only “RBF”, or “Other” are returned.
- Return type:
Literal[“RBF”, “Other”]
- to_tensor(data: numpy.typing.ArrayLike) torch.Tensor
Convert input data to a PyTorch tensor.
- Parameters:
data (ArrayLike) – Input data to convert to tensor format.
- Returns:
Converted PyTorch tensor.
- Return type:
torch.Tensor
- class vopy.models.SingleTaskGP(*args: Any, **kwargs: Any)
Exact GP model for single-task problems.
- Parameters:
train_inputs (torch.Tensor) – Training input data.
train_targets (torch.Tensor) – Training target data.
likelihood (gpytorch.likelihoods.GaussianLikelihood) – Gaussian likelihood module.
kernel (type[gpytorch.kernels.Kernel]) – Kernel function for the covariance module.
- forward(x: torch.Tensor) gpytorch.distributions.MultivariateNormal
Computes the marginalized joint distribution over the given input points.
- Parameters:
x (torch.Tensor) – Input data.
- Returns:
An instance of MultivariateNormal distribution.
- Return type:
gpytorch.distributions.MultivariateNormal
- class vopy.models.MultitaskExactGPModel(*args: Any, **kwargs: Any)
Exact GP model for multitask problems with dependent objectives, i.e., a Linear Model of Coregionalization (LMC).
- Parameters:
train_inputs (torch.Tensor) – Input training data.
train_targets (torch.Tensor) – Target training data.
likelihood (gpytorch.likelihoods.MultitaskGaussianLikelihood) – Gaussian likelihood module.
kernel (type[gpytorch.kernels.Kernel]) – Kernel type for covariance computation.
- forward(x: torch.Tensor) gpytorch.distributions.MultitaskMultivariateNormal
Computes the marginalized joint distribution over the given input points.
- Parameters:
x (torch.Tensor) – Input data.
- Returns:
An instance of MultitaskMultivariateNormal distribution.
- Return type:
gpytorch.distributions.MultitaskMultivariateNormal
- class vopy.models.BatchIndependentExactGPModel(*args: Any, **kwargs: Any)
Exact GP model for multitask problems with independent objectives.
- Parameters:
train_inputs (torch.Tensor) – Input training data.
train_targets (torch.Tensor) – Target training data.
likelihood (gpytorch.likelihoods.MultitaskGaussianLikelihood) – Gaussian likelihood module.
kernel (type[gpytorch.kernels.Kernel]) – Kernel type for covariance computation.
- forward(x: torch.Tensor) gpytorch.distributions.MultitaskMultivariateNormal
Computes the marginalized joint distribution over the given input points.
- Parameters:
x (torch.Tensor) – Input data.
- Returns:
An instance of MultitaskMultivariateNormal distribution.
- Return type:
gpytorch.distributions.MultitaskMultivariateNormal
- class vopy.models.GPyTorchMultioutputExactModel(input_dim: int, output_dim: int, noise_var: float | numpy.typing.ArrayLike, model_kind: type[BatchIndependentExactGPModel | MultitaskExactGPModel])
Multioutput GP model with exact inference, assuming known noise variance/covariance.
- Parameters:
input_dim (int) – Dimensionality of the input data.
output_dim (int) – Dimensionality of the output data.
noise_var (Union[float, ArrayLike]) – Noise variance for Gaussian likelihood.
model_kind (type[Union[BatchIndependentExactGPModel, MultitaskExactGPModel]]) – Type of Exact GP model to be used.
- add_sample(X_t: numpy.typing.ArrayLike, Y_t: numpy.typing.ArrayLike)
Add new samples to the training data.
- Parameters:
X_t (ArrayLike) – Input data sample.
Y_t (ArrayLike) – Target data sample.
- clear_data()
Clear stored training data.
- evaluate_kernel(X: numpy.typing.ArrayLike | None = None)
Evaluate the kernel matrix for given data points.
- Parameters:
X (ArrayLike) – Input data to evaluate the kernel for. Defaults to training data if None.
- Returns:
Evaluated kernel matrix.
- Return type:
np.ndarray
- get_lengthscale_and_var() tuple[numpy.ndarray, numpy.ndarray]
Return the kernel lengthscales and variances.
- Returns:
Lengthscales and variances as arrays.
- Return type:
tuple[np.ndarray, np.ndarray]
- train()
Train the hyperparameters of GP model.
- update()
Create GP model or update it with the current training data.
IndependentExactGPyTorchModel
- class vopy.models.IndependentExactGPyTorchModel(input_dim: int, output_dim: int, noise_var: float | numpy.typing.ArrayLike)
Independent multitask GP model using the multioutput exact GP framework.
- Parameters:
input_dim (int) – Dimensionality of the input data.
output_dim (int) – Dimensionality of the output data.
noise_var (Union[float, ArrayLike]) – Noise variance for Gaussian likelihood.
- predict(test_X: numpy.typing.ArrayLike) tuple[numpy.ndarray, numpy.ndarray]
Make predictions on test data.
- Parameters:
test_X (ArrayLike) – Test data.
- Returns:
Predicted means and variances corresponding to each test point.
- Return type:
tuple[np.ndarray, np.ndarray]
GPyTorchModelListExactModel
- class vopy.models.GPyTorchModelListExactModel(input_dim, output_dim, noise_var)
Multi-output GP model implemented as a list of independent single-task GP models, allowing decoupled updates.
- Parameters:
input_dim (int) – Dimensionality of the input data.
output_dim (int) – Dimensionality of the output data.
noise_var (float) – Noise variance for the Gaussian likelihood, which is assumed to be the same for each objective.
- add_sample(X_t: numpy.typing.ArrayLike, Y_t: numpy.typing.ArrayLike, dim_index: int | List[int])
Add new samples to the training data for specified output dimension(s).
- Parameters:
X_t (ArrayLike) – Input sample data.
Y_t (ArrayLike) – Target sample data.
dim_index (Union[int, List[int]]) – Index or indices of output dimensions to update. If an integer is provided, the sample is added to the corresponding model. If a list of integers is provided, the samples are added to the corresponding models.
- clear_data()
Clear stored training data.
- evaluate_kernel(X: numpy.typing.ArrayLike)
Evaluate the kernels for the input data across all output dimensions and combine.
- Parameters:
X (ArrayLike) – Input data to evaluate the kernel for.
- Returns:
Covariance matrix of shape (num_objective*num_data) x (num_objective*num_data).
- Return type:
np.ndarray
- get_lengthscale_and_var() tuple[numpy.ndarray, numpy.ndarray]
Return the kernel lengthscales and variances for each model (objective).
- Returns:
Lengthscales and variances for each objective.
- Return type:
tuple[np.ndarray, np.ndarray]
- predict(test_X: numpy.typing.ArrayLike) tuple[numpy.ndarray, numpy.ndarray]
Make predictions on test data.
- Parameters:
test_X (ArrayLike) – Test data.
- Returns:
Predicted means and variances corresponding to each test point.
- Return type:
tuple[np.ndarray, np.ndarray]
- sample_from_posterior(test_X: numpy.typing.ArrayLike, sample_count: int = 1)
Sample from the posterior distribution, considering all objectives.
- Parameters:
test_X (ArrayLike) – Test data.
sample_count (int) – Number of samples to draw.
- Returns:
Samples from the posterior distribution with shape sample_count x num_test_data x num_objective.
- Return type:
np.ndarray
- sample_from_single_posterior(test_X: numpy.typing.ArrayLike, dim_index: int, sample_count=1)
Sample from the posterior distribution, considering only one objective.
- Parameters:
test_X (ArrayLike) – Test data.
dim_index (int) – Index of the objective to take posterior samples from.
sample_count (int) – Number of samples to draw.
- Returns:
Samples from the posterior distribution of the specified objective, with shape sample_count x num_test_data.
- Return type:
np.ndarray
- train()
Train the hyperparameters of GP model.
- update()
Create GP model or update it with the current training data.