pytspl.hogde_gp
Subpackages
Submodules
Classes
The base class for any Gaussian process latent function to be used in conjunction |
|
Package Contents
- class pytspl.hogde_gp.ExactGPModel(train_x: torch.tensor, train_y: torch.tensor, likelihood: gpytorch.likelihoods, kernel: gpytorch.kernels.Kernel, mean_function=None)[source]
Bases:
gpytorch.models.ExactGPThe base class for any Gaussian process latent function to be used in conjunction with exact inference.
- Parameters:
train_inputs (torch.Tensor) – (size n x d) The training features \(\mathbf X\).
train_targets (torch.Tensor) – (size n) The training targets \(\mathbf y\).
likelihood (GaussianLikelihood) – The Gaussian likelihood that defines the observational distribution. Since we’re using exact inference, the likelihood must be Gaussian.
The
forward()function should describe how to compute the prior latent distribution on a given input. Typically, this will involve a mean and kernel function. The result must be aMultivariateNormal.Calling this model will return the posterior of the latent Gaussian process when conditioned on the training data. The output will be a
MultivariateNormal.- Example:
>>> class MyGP(gpytorch.models.ExactGP): >>> def __init__(self, train_x, train_y, likelihood): >>> super().__init__(train_x, train_y, likelihood) >>> self.mean_module = gpytorch.means.ZeroMean() >>> self.covar_module = gpytorch.kernels.ScaleKernel(gpytorch.kernels.RBFKernel()) >>> >>> def forward(self, x): >>> mean = self.mean_module(x) >>> covar = self.covar_module(x) >>> return gpytorch.distributions.MultivariateNormal(mean, covar) >>> >>> # train_x = ...; train_y = ... >>> likelihood = gpytorch.likelihoods.GaussianLikelihood() >>> model = MyGP(train_x, train_y, likelihood) >>> >>> # test_x = ...; >>> model(test_x) # Returns the GP latent function at test_x >>> likelihood(model(test_x)) # Returns the (approximate) predictive posterior distribution at test_x
- covar_module
- class pytspl.hogde_gp.HodgeGPTrainer(sc: pytspl.simplicial_complex.SimplicialComplex, y: numpy.ndarray, output_device: str = 'cpu')[source]
- sc
- y
- output_device
- get_laplacians() list[source]
Return the Laplacian matrices as a list of tensors.
- Returns:
list(torch.tensor): The Laplacian matrices.
- get_incidence_matrices() list[source]
Return the incidence matrices as a list of tensors.
- Returns:
list(torch.tensor): The incidence matrices.
- get_eigenpairs(tolerance: float = 0.001) list[source]
Return the eigenpairs of the Laplacian matrices.
- Args:
tolerance (float, optional): The tolerance for eigenvalues to be considered zero. Defaults to 1e-3.
- Returns:
list(torch.tensor): The eigenpairs of the Laplacian matrices for the harmonic, gradient, and curl components.
- normalize_data(y_train: torch.tensor, y_test: torch.tensor, y: torch.tensor) tuple[source]
Normalize the target values.
- Args:
y_train (torch.tensor): The training target values. y_test (torch.tensor): The testing target values. y (torch.tensor): The target values.
- Returns:
torch.tensor: The normalized training target values. torch.tensor: The normalized testing target values. torch.tensor: The normalized target values.
- train_test_split(train_ratio: float = 0.8, data_normalization: bool = False, seed: int = 4) tuple[source]
Split the data into training and validation sets.
- Args:
train_ratio (float, optional): The ratio of the training data. Defaults to 0.8. data_normalization (bool, optional): Whether to normalize the target data. Defaults to False. seed (int, optional): The random seed. Defaults to 4.
- Returns:
torch.tensor: The training input data. torch.tensor: The training target data. torch.tensor: The testing input data. torch.tensor: The testing target data. torch.tensor: The input data. torch.tensor: The target data.
- train(model: gpytorch.models, likelihood: gpytorch.likelihoods, x_train: torch.tensor, y_train: torch.tensor, training_iters: int = 1000, learning_rate: float = 0.1, optimizer=torch.optim.Adam) None[source]
Train the model using the training data with the given parameters.
- Args:
model (gpytorch.models): The model to train. likelihood (gpytorch.likelihoods): The likelihood function. x_train (torch.tensor): The training data. y_train (torch.tensor): The training labels. training_iters (int, optional): The number of training iterations. Defaults to 1000. learning_rate (float, optional): The learning rate. Defaults to 0.1. optimizer (_type_, optional): The optimizer. Defaults to torch.optim.Adam.
- predict(model: gpytorch.models, likelihood: gpytorch.likelihoods, x_test: torch.tensor, y_test: torch.tensor) gpytorch.distributions[source]
Predict the target values using the model and likelihood functions. Also, calculate the metrics.
- Args:
model (gpytorch.models): The model to use for prediction. likelihood (gpytorch.likelihoods): The likelihood function. x_test (torch.tensor): The testing data. y_test (torch.tensor): The testing labels.
- Returns:
gpytorch.distributions (torch.tensor): The predictions.