hyperparameter

MuyGPyS.gp.hyperparameters module reference.

class MuyGPyS.gp.hyperparameter.scalar.Parameter(val, bounds='fixed')[source]

A MuyGPs kernel or model Hyperparameter. Also called ScalarParam.

Hyperparameters are defined by a value and optimization bounds. Values must be scalar numeric types, and bounds are either a len == 2 iterable container whose elements are numeric scalars in increasing order, or the string fixed. If bounds == "fixed" (the default behavior), the hyperparameter value will remain fixed during optimization. val must remain within the range of the upper and lower bounds, if not fixed.

Parameters:
  • val (Union[str, float]) – A scalar within the range of the upper and lower bounds (if given). val can also be the strings "sample" or "log_sample", which will result in randomly sampling a value within the range given by the bounds.

  • bounds (Union[str, Tuple[float, float]]) – Iterable container of len 2 containing lower and upper bounds (in that order), or the string "fixed".

Raises:
  • ValueError – Any bounds string other than "fixed" will produce an error.

  • ValueError – A non-iterable non-string type for bounds will produce an error.

  • ValueError – A bounds iterable of len other than 2 will produce an error.

  • ValueError – Iterable bounds values of non-numeric types will produce an error.

  • ValueError – A lower bound that is not less than an upper bound will produce an error.

  • ValueErrorval == "sample" or val == "log_sample" will produce an error if self._bounds == "fixed".

  • ValueError – Any string other than "sample" or "log_sample" will produce an error.

  • ValueError – A val outside of the range specified by self._bounds will produce an error.

__call__()[source]

Value accessor.

Return type:

float

Returns:

The current value of the hyperparameter.

fixed()[source]

Report whether the parameter is fixed, and is to be ignored during optimization.

Return type:

bool

Returns:

True if fixed, False otherwise.

get_bounds()[source]

Bounds accessor.

Return type:

Tuple[float, float]

Returns:

The lower and upper bound tuple.

class MuyGPyS.gp.hyperparameter.tensor.TensorParam(val)[source]

A MuyGPs kernel or model Tensor Hyperparameter.

TensorParam are defined solely by a value, which must be numeric arrays. Currently only used for heteroscedastic noise.

Parameters:

val (ndarray) – A mm.ndarray containing the value of the tensor hyperparameter

__call__()[source]

Value accessor.

Return type:

ndarray

Returns:

The current value of the tensor hyperparameter.

fixed()[source]

Report whether the parameter is fixed, and is to be ignored during optimization. Always returns True for tensor hyperparameters.

Return type:

bool

Returns:

True.

class MuyGPyS.gp.hyperparameter.scale.ScaleFn(response_count=1, _backend_ones=<function fix_type.<locals>.typed_fn.<locals>.fn_wrapper>, _backend_ndarray=<class 'numpy.ndarray'>, _backend_ftype=<class 'numpy.float64'>, _backend_farray=<function fix_type.<locals>.typed_fn.<locals>.fn_wrapper>, _backend_outer=<function outer>, **kwargs)[source]

A \(\sigma^2\) covariance scale parameter base functor.

\(\sigma^2\) is a scaling parameter that one multiplies with the found diagonal variances of a MuyGPyS.gp.muygps.MuyGPS or MuyGPyS.gp.muygps.MultivariateMuyGPS regression in order to obtain the predicted posterior variance. Trained values assume a number of dimensions equal to the number of response dimensions, and correspond to scalar scaling parameters along the corresponding dimensions.

Parameters:

response_count (int) – The integer number of response dimensions.

__call__()[source]

Value accessor.

Return type:

ndarray

Returns:

The current value of the hyperparameter.

scale_fn(fn)[source]

Modify a function to outer product its output with scale.

Parameters:

fn (Callable) – A function.

Return type:

Callable

Returns:

A function that returns the outer product of the output of fn

property shape: Tuple[int, ...]

Report the shape of the scale parameter.

Returns:

The shape of the scale parameter.

property trained: bool

Report whether the value has been set.

Returns:

True if trained, False otherwise.

class MuyGPyS.gp.hyperparameter.scale.FixedScale(response_count=1, _backend_ones=<function fix_type.<locals>.typed_fn.<locals>.fn_wrapper>, _backend_ndarray=<class 'numpy.ndarray'>, _backend_ftype=<class 'numpy.float64'>, _backend_farray=<function fix_type.<locals>.typed_fn.<locals>.fn_wrapper>, _backend_outer=<function outer>, **kwargs)[source]

A \(\sigma^2\) covariance scale parameter.

A Scale parameter with a null optimization method. This parameter is therefore insensitive to optimization.

Parameters:

response_count (int) – The integer number of response dimensions.

get_opt_fn(muygps)[source]

Return a function that optimizes the value of the variance scale.

Parameters:

muygps – A model to be ignored.

Return type:

Callable

Returns:

A function that always returns the value of this scale parameter.

class MuyGPyS.gp.hyperparameter.scale.AnalyticScale(_backend_fn=<function _analytic_scale_optim>, **kwargs)[source]

An optimizable \(\sigma^2\) covariance scale parameter.

Identical to FixedScale, save that its get_opt_fn method performs an analytic optimization.

Parameters:

response_count – The integer number of response dimensions.

get_opt_fn(muygps)[source]

Get a function to optimize the value of the \(\sigma^2\) scale parameter for each response dimension.

We approximate a scalar \(\sigma^2\) by way of averaging over the analytic solution from each local kernel. Given observations \(X\) with responses \(Y\), noise model \(\varepsilon\), and kernel function \(K_\theta(\cdot, \cdot)\), computes:

\[\sigma^2 = \frac{1}{bk} * \sum_{i \in B} Y(X_{N_i})^T \left ( K_\theta(X_{N_i}, X_{N_i}) + \varepsilon_{N_i} \right )^{-1} Y(X_{N_i}).\]

Here \(N_i\) is the set of nearest neighbor indices of the \(i`th batch element, :math:`k\) is the number of nearest neighbors and \(b = |B|\) is the number of batch elements considered.

Parameters:

muygps – The model to used to create and perturb the kernel.

Return type:

Callable

Returns:

A function with signature (K, nn_targets, *args, **kwargs) -> mm.ndarray that perturbs the (batch_count, nn_count, nn_count) tensor K with muygps’s noise model before solving it against the (batch_count, nn_count, response_count) tensor nn_targets.