romcomma.gpr.models.MOGP§
- class MOGP(name, fold, is_read, is_covariant, is_isotropic, kernel_parameters=None, likelihood_variance=None)[source]§
Bases:
GPR
Implementation of a Gaussian Process.
- Parameters:
name (str) –
fold (Fold) –
is_read (bool | None) –
is_covariant (bool) –
is_isotropic (bool) –
kernel_parameters (Kernel.Data | None) –
likelihood_variance (NP.Matrix | None) –
- __init__(name, fold, is_read, is_covariant, is_isotropic, kernel_parameters=None, likelihood_variance=None)§
Set up data, and checks dimensions.
- Parameters:
name (str) – The name of this MOGP.
fold (Fold) – The Fold housing this MOGP.
is_read (bool | None) – If True, the MOGP.kernel.data and MOGP.data and are read from
fold.folder/name
, otherwise defaults are used.is_covariant (bool) – Whether the outputs will be treated as independent.
is_isotropic (bool) – Whether to restrict the kernel to be isotropic.
kernel_parameters (Data | None) – A Kernel.Data to use for MOGP.kernel.data. If not None, this replaces the kernel specified by file/defaults. If None, the kernel is read from file, or set to the default Kernel.Data(), according to read_from_file.
likelihood_variance (ndarray | None) – The likelihood variance to use instead of file or default.
- Raises:
IndexError – If a parameter is mis-shaped.
Methods
__init__
(name, fold, is_read, is_covariant, ...)Set up data, and checks dimensions.
broadcast_parameters
(is_covariant, is_isotropic)Broadcast the data of the MOGP (including kernels) to higher dimensions.
calibrate
([method])Optimize the MOGP hyper-data.
FOR TESTING PURPOSES ONLY.
predict
(X[, y_instead_of_f])Predicts the response to input X.
predict_df
(x[, y_instead_of_f, is_normalized])Predicts the response to input X.
predict_gradient
(x[, y_instead_of_f])Predicts the gradient GP dy/dx (or df/dx) where
self
is the GP for y(x).read_meta
()test
()Tests the MOGP on the test data in self._fold.test_data.
write_meta
(meta)Attributes
The Cholesky decomposition of the LNxLN noisy kernel(X, X) + likelihood.variance.
The LN-Vector, which pre-multiplied by the LoxLN kernel k(x, X) gives the Lo-Vector predictive mean f(x).
The output (Y) dimensionality.
The input (X) dimensionality.
The the number of training samples.
The implementation training inputs as an (N,M) design matrix.
The implementation training outputs as an (N,L) design matrix.
data
The parent fold.
folder
The implementation of this MOGP in GPFlow.
kernel
likelihood
test_csv
test_summary_csv
- class property META: Dict[str, Any]§
Hyper-parameter optimizer meta
- property implementation: Tuple[Any, ...]§
The implementation of this MOGP in GPFlow. If
noise_variance.shape == (1,L)
an L-tuple of kernels is returned. Ifnoise_variance.shape == (L,L)
a 1-tuple of multi-output kernels is returned.
- calibrate(method='L-BFGS-B', **kwargs)[source]§
Optimize the MOGP hyper-data.
- Parameters:
method (str) – The optimization algorithm (see https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html).
kwargs – A Dict of implementation-dependent optimizer meta, following the format of GPR.META. Options for the kernel should be passed as kernel={see kernel.META for format}. Options for the likelihood should be passed as likelihood={see likelihood.META for format}.
- Return type:
Dict[str, Any]
- predict(X, y_instead_of_f=True)[source]§
Predicts the response to input X.
- Parameters:
x – An (o, M) design Matrix of inputs.
y_instead_of_f (bool) – True to include noise in the variance of the result.
X (ndarray) –
- Return type:
Tuple[ndarray, ndarray]
Returns: The distribution of y or f, as a pair (mean (o, L) Matrix, std (o, L) Matrix).
- predict_gradient(x, y_instead_of_f=True)[source]§
Predicts the gradient GP dy/dx (or df/dx) where
self
is the GP for y(x).- Parameters:
x (ndarray) – An (o, M) design Matrix of inputs.
y_instead_of_f (bool) – True to include noise in the variance of the result.
- Return type:
- Returns: The distribution of dy/dx or df/dx, as a pair (mean (o, L, M), cov (o, L, M, O, l, m)) if
self.likelihood.is_covariant
, else (mean (o, L, M), cov (o, O, L, M)).
- property K_cho: Tensor§
The Cholesky decomposition of the LNxLN noisy kernel(X, X) + likelihood.variance. Shape is (LN, LN) if self.kernel.is_covariant, else (L,N,N).
- property K_inv_Y: Tensor§
The LN-Vector, which pre-multiplied by the LoxLN kernel k(x, X) gives the Lo-Vector predictive mean f(x). Shape is (L,1,N). Returns: ChoSolve(self.K_cho, self.Y)
- class Data(folder, **kwargs)§
Bases:
Data
The Data set of a MOGP.
- Parameters:
folder (Path | str) –
kwargs (Data.Matrix) –
- NamedTuple§
alias of
Values
- static copy(src_folder, dst_folder)§
Returns a copy of
src_folder
at dst_folder, deleting anything existing at the destination.- Parameters:
src_folder (Path | str) –
dst_folder (Path | str) –
- Return type:
Path
- static delete(folder)§
Returns a non-existent
folder
.- Parameters:
folder (Path | str) –
- Return type:
Path
- static empty(folder)§
Returns an empty
folder
.- Parameters:
folder (Path | str) –
- Return type:
Path
- move(dst_folder)§
Move
self
todst_folder
.- Parameters:
dst_folder (Path | str) – The folder to move to. If this exists, it will be emptied.
- Return type:
Returns:
self
for chaining calls.
- classmethod read(folder, **kwargs)§
Read
Data
fromfolder
.- Parameters:
- Return type:
Returns: The
Data
stored infolder
.
- KERNEL_FOLDER_NAME = 'kernel'§
- property L: int§
The output (Y) dimensionality.
- property M: int§
The input (X) dimensionality.
- property N: int§
The the number of training samples.
- broadcast_parameters(is_covariant, is_isotropic)§
Broadcast the data of the MOGP (including kernels) to higher dimensions. Shrinkage raises errors, unchanged dimensions silently do nothing.
- Parameters:
is_covariant (bool) – Whether the outputs will be treated as dependent.
is_isotropic (bool) – Whether to restrict the kernel to be isotropic.
- Return type:
Returns:
self
, for chaining calls.
- check_K_inv_Y(x)[source]§
FOR TESTING PURPOSES ONLY. Should return 0 Vector (to within numerical error tolerance).
- Parameters:
x (ndarray) – An (o, M) matrix of inputs.
- Return type:
ndarray
Returns: Should return zeros((Lo)) (to within numerical error tolerance).
- predict_df(x, y_instead_of_f=True, is_normalized=True)§
Predicts the response to input X.
- Parameters:
x (ndarray) – An (o, M) design Matrix of inputs.
y_instead_of_f (bool) – True to include noise in the variance of the result.
is_normalized (bool) – Whether the results are normalized or not.
- Return type:
DataFrame
Returns: The distribution of y or f, as a dataframe with M+L+L columns of the form (X, Mean, Predictive Std).
- test()§
Tests the MOGP on the test data in self._fold.test_data. Test results comprise three values for each output at each sample: The mean prediction, the std error of prediction and the Z score of prediction (i.e. error of prediction scaled by std error of prediction).
Returns: The test_data results as a Frame backed by MOGP.test_result_csv.
- Return type: