Skip to content

Getting Started

These first steps are meant to serve as a brief introduction into the organization of DKRegression. The design of DKRegression is as modular as possible to allow for extensions and adaption to more problems. DKRegression requires the specification of three objects:

  • Kernel
  • Observation Likelihood
  • Cross-Validation Configuration

Each of these objects is a different submodule in the package which can be imported in the following way:

from dkregression.kernels import *
from dkregression.likelihoods import *
from dkregression.cross_validation import CrossValidation
In addition to these individual components, there is also the DKR object which takes instances from the aforementioned three categories of objects and provides the fit and predict methods.
from dkregression import DKR
The fit method optimizes the kernel (hyper) parameters (e.g., the scale length \(\ell\) of the RBF kernel). Kernels typically only have a small number of (hyper) parameters such that the use of gradient-free, global optimization techniques is preferred for this fitting process. Furthermore, to avoid overfitting, DKR uses a cross-validation strategy that balances fidelity and runtime. More information can be found in the cross-validation reference section. Below you can find an annotated standard example.
import torch    # needed to generate sample data

# input always needs to be of shape (n,d_input)
X = torch.rand((100,4))  

# output always needs to be of shape (n,d_output) even if d_output=1  
Y = torch.rand((100,1)) 

# inference input of shape (n_inference, d_input)
Xq = torch.rand((20,4))

# for initial guess of the kernel hyperparameters and bounds, 
# the input data X must be provided
kernel = RBF(X)

# Setting the observation likelihood as normal likelihood
likelihood = UnivariateGaussianLikelihood()

# Cross-validation configuration with default setting, see 
# `Reference` section for more details about settings
cv = CrossValidation()

# initialization of the DKR model with the kernel, likelihood and cross-validation configuration
model = DKR(kernel, likelihood, cv)

# fit the kernel (hyper) parameter(s)
model.fit(X,Y)

# inference
Yq = model.predict(Xq)