Intrinsic UQ Algorithms

Homoscedastic Gaussian Process Regression

class uq360.algorithms.homoscedastic_gaussian_process_regression.HomoscedasticGPRegression(kernel=ScaleKernel(   (base_kernel): RBFKernel(     (raw_lengthscale_constraint): Positive()   )   (raw_outputscale_constraint): Positive() ), likelihood=None, config=None)

A wrapper around Botorch SingleTask Gaussian Process Regression 1 with homoscedastic noise.

References

1

https://botorch.org/api/models.html#singletaskgp

Parameters
  • kernel – gpytorch kernel function with default set to RBFKernel with output scale.

  • likelihood – gpytorch likelihood function with default set to GaussianLikelihood.

  • config – dictionary containing the config parameters for the model.

fit(X, y, **kwargs)

Fit the GP Regression model.

Additional arguments relevant for SingleTaskGP fitting can be passed to this function.

Parameters
  • X – array-like of shape (n_samples, n_features). Features vectors of the training data.

  • y – array-like of shape (n_samples,) or (n_samples, n_targets) Target values

  • **kwargs – Additional arguments relevant for SingleTaskGP fitting.

Returns

self

predict(X, return_dists=False, return_epistemic=False, return_epistemic_dists=False)

Obtain predictions for the test points.

In addition to the mean and lower/upper bounds, also returns epistemic uncertainty (return_epistemic=True) and full predictive distribution (return_dists=True).

Parameters
  • X – array-like of shape (n_samples, n_features). Features vectors of the test points.

  • return_dists – If True, the predictive distribution for each instance using scipy distributions is returned.

  • return_epistemic – if True, the epistemic upper and lower bounds are returned.

  • return_epistemic_dists – If True, the epistemic distribution for each instance using scipy distributions is returned.

Returns

A namedtuple that holds

y_mean: ndarray of shape (n_samples, [n_output_dims])

Mean of predictive distribution of the test points.

y_lower: ndarray of shape (n_samples, [n_output_dims])

Lower quantile of predictive distribution of the test points.

y_upper: ndarray of shape (n_samples, [n_output_dims])

Upper quantile of predictive distribution of the test points.

y_lower_epistemic: ndarray of shape (n_samples, [n_output_dims])

Lower quantile of epistemic component of the predictive distribution of the test points. Only returned when return_epistemic is True.

y_upper_epistemic: ndarray of shape (n_samples, [n_output_dims])

Upper quantile of epistemic component of the predictive distribution of the test points. Only returned when return_epistemic is True.

dists: list of predictive distribution as scipy.stats objects with length n_samples.

Only returned when return_dists is True.

Return type

namedtuple

Heteroscedastic Regression

class uq360.algorithms.heteroscedastic_regression.HeteroscedasticRegression(model_type=None, model=None, config=None, device=None, verbose=True)

Wrapper for heteroscedastic regression. We learn to predict targets given features, assuming that the targets are noisy and that the amount of noise varies between data points. https://en.wikipedia.org/wiki/Heteroscedasticity

Parameters
  • model_type – The base model architecture. Currently supported values are [mlp]. mlp modeltype learns a multi-layer perceptron with a heteroscedastic Gaussian likelihood. Both the mean and variance of the Gaussian are functions of the data point ->git N(y_n | mlp_mu(x_n), mlp_var(x_n))

  • model – (optional) The prediction model. Currently support pytorch models that returns mean and log variance.

  • config – dictionary containing the config parameters for the model.

  • device – device used for pytorch models ignored otherwise.

  • verbose – if True, print statements with the progress are enabled.

fit(X, y)

Fit the Heteroscedastic Regression model.

Parameters
  • X – array-like of shape (n_samples, n_features). Features vectors of the training data.

  • y – array-like of shape (n_samples,) or (n_samples, n_targets) Target values

Returns

self

predict(X, return_dists=False)

Obtain predictions for the test points.

In addition to the mean and lower/upper bounds, also returns epistemic uncertainty (return_epistemic=True) and full predictive distribution (return_dists=True).

Parameters
  • X – array-like of shape (n_samples, n_features). Features vectors of the test points.

  • return_dists – If True, the predictive distribution for each instance using scipy distributions is returned.

Returns

A namedtupe that holds

y_mean: ndarray of shape (n_samples, [n_output_dims])

Mean of predictive distribution of the test points.

y_lower: ndarray of shape (n_samples, [n_output_dims])

Lower quantile of predictive distribution of the test points.

y_upper: ndarray of shape (n_samples, [n_output_dims])

Upper quantile of predictive distribution of the test points.

dists: list of predictive distribution as scipy.stats objects with length n_samples.

Only returned when return_dists is True.

Return type

namedtuple

Ensemble Heteroscedastic Regression

class uq360.algorithms.ensemble_heteroscedastic_regression.EnsembleHeteroscedasticRegression(model_type=None, config=None, device=None, verbose=True)

Ensemble Regression assumes an ensemble of models of Gaussian form for the predictive distribution and returns the mean and log variance of the ensemble of Gaussians.

Initializer for Ensemble of heteroscedastic regression. :param model_type: The base model used for predicting a quantile. Currently supported values are [heteroscedasticregression]. :param config: dictionary containing the config parameters for the model. :param device: device used for pytorch models ignored otherwise.

fit(X, y)

Fit the Ensemble of Heteroscedastic Regression models. :param X: array-like of shape (n_samples, n_features).

Features vectors of the training data.

Parameters

y – array-like of shape (n_samples,) or (n_samples, n_targets) Target values

Returns

self

predict(X, return_dists=False)

Obtain predictions for the test points. In addition to the mean and lower/upper bounds, also returns epistemic uncertainty (return_epistemic=True) and full predictive distribution (return_dists=True). :param X: array-like of shape (n_samples, n_features).

Features vectors of the test points.

Parameters

return_dists – If True, the predictive distribution for each instance using scipy distributions is returned.

Returns

A namedtupe that holds y_mean: ndarray of shape (n_samples, [n_output_dims])

Mean of predictive distribution of the test points.

y_lower: ndarray of shape (n_samples, [n_output_dims])

Lower quantile of predictive distribution of the test points.

y_upper: ndarray of shape (n_samples, [n_output_dims])

Upper quantile of predictive distribution of the test points.

dists: list of predictive distribution as scipy.stats objects with length n_samples.

Only returned when return_dists is True.

Return type

namedtuple

Actively Learned Model

class uq360.algorithms.actively_learned_model.ActivelyLearnedModel(config=None, device=None, verbose=True, online=True)

ActivelyLearnedModel assumes an existing BuiltinUQ model, and implements an active learning training of this model. This code is supporting Pestourie et al. “Active learning of deep surrogates for PDEs: application to metasurface design.” npj Computational Materials 6.1 (2020): 1-7.

Initializer for Actively learned model. :param config: dictionary containing the config parameters for the model. For active learning: num_init, T, K, M, sampling_function, querry_function, for the used model:

{“model_function”: BuilInUQ model to actively learn, “model_args”: same arguments as the BuilInUQ model used, “model_kwargs”: same keyword arguments as the BuilInUQ model used}

Parameters

device – device used for pytorch models ignored otherwise.

fit()

Fit the actively learned model, by increasing the dataset efficiently. NB: it does not take a dataset as argument, because it is building one during training. :returns: self

predict(X)

Obtain predictions for the test points. In addition to the mean and lower/upper bounds, also returns epistemic uncertainty (return_epistemic=True) and full predictive distribution (return_dists=True). :param X: array-like of shape (n_samples, n_features).

Features vectors of the test points.

Returns

A namedtupe that holds y_mean: ndarray of shape (n_samples, [n_output_dims])

Mean of predictive distribution of the test points.

y_lower: ndarray of shape (n_samples, [n_output_dims])

Lower quantile of predictive distribution of the test points.

y_upper: ndarray of shape (n_samples, [n_output_dims])

Upper quantile of predictive distribution of the test points.

Return type

namedtuple

Quantile Regression

class uq360.algorithms.quantile_regression.QuantileRegression(model_type='gbr', config=None)

Quantile Regression uses quantile loss and learns two separate models for the upper and lower quantile to obtain the prediction intervals.

Parameters
  • model_type – The base model used for predicting a quantile. Currently supported values are [gbr]. gbr is sklearn GradientBoostingRegressor.

  • config – dictionary containing the config parameters for the model.

fit(X, y)

Fit the Quantile Regression model.

Parameters
  • X – array-like of shape (n_samples, n_features). Features vectors of the training data.

  • y – array-like of shape (n_samples,) or (n_samples, n_targets) Target values

Returns

self

predict(X)

Obtain predictions for the test points.

In addition to the mean and lower/upper bounds, also returns epistemic uncertainty (return_epistemic=True) and full predictive distribution (return_dists=True).

Parameters

X – array-like of shape (n_samples, n_features). Features vectors of the test points.

Returns

A namedtupe that holds

y_mean: ndarray of shape (n_samples, [n_output_dims])

Mean of predictive distribution of the test points.

y_lower: ndarray of shape (n_samples, [n_output_dims])

Lower quantile of predictive distribution of the test points.

y_upper: ndarray of shape (n_samples, [n_output_dims])

Upper quantile of predictive distribution of the test points.

Return type

namedtuple

Bayesian Neural Network Regression

class uq360.algorithms.variational_bayesian_neural_networks.bnn.BnnRegression(config, prior='Gaussian')

Variationally trained BNNs with Gaussian and Horseshoe 6 priors for regression.

References

6(1,2)

Ghosh, Soumya, Jiayu Yao, and Finale Doshi-Velez. “Structured variational learning of Bayesian neural networks with horseshoe priors.” International Conference on Machine Learning. PMLR, 2018.

Parameters
  • config – a dictionary specifying network and learning hyperparameters.

  • prior – BNN priors specified as a string. Supported priors are Gaussian, Hshoe, RegHshoe

fit(X, y)

Fit the BNN regression model.

Parameters
  • X – array-like of shape (n_samples, n_features). Features vectors of the training data.

  • y – array-like of shape (n_samples,) or (n_samples, n_targets) Target values

Returns

self

predict(X, mc_samples=100, return_dists=False, return_epistemic=True, return_epistemic_dists=False)

Obtain predictions for the test points.

In addition to the mean and lower/upper bounds, also returns epistemic uncertainty (return_epistemic=True) and full predictive distribution (return_dists=True).

Parameters
  • X – array-like of shape (n_samples, n_features). Features vectors of the test points.

  • mc_samples – Number of Monte-Carlo samples.

  • return_dists – If True, the predictive distribution for each instance using scipy distributions is returned.

  • return_epistemic – if True, the epistemic upper and lower bounds are returned.

  • return_epistemic_dists – If True, the epistemic distribution for each instance using scipy distributions is returned.

Returns

A namedtupe that holds

y_mean: ndarray of shape (n_samples, [n_output_dims])

Mean of predictive distribution of the test points.

y_lower: ndarray of shape (n_samples, [n_output_dims])

Lower quantile of predictive distribution of the test points.

y_upper: ndarray of shape (n_samples, [n_output_dims])

Upper quantile of predictive distribution of the test points.

y_lower_epistemic: ndarray of shape (n_samples, [n_output_dims])

Lower quantile of epistemic component of the predictive distribution of the test points. Only returned when return_epistemic is True.

y_upper_epistemic: ndarray of shape (n_samples, [n_output_dims])

Upper quantile of epistemic component of the predictive distribution of the test points. Only returned when return_epistemic is True.

dists: list of predictive distribution as scipy.stats objects with length n_samples.

Only returned when return_dists is True.

Return type

namedtuple

Bayesian Neural Network Classification

class uq360.algorithms.variational_bayesian_neural_networks.bnn.BnnClassification(config, prior='Gaussian', device=None)

Variationally trained BNNs with Gaussian and Horseshoe 6 priors for classification.

Parameters
  • config – a dictionary specifying network and learning hyperparameters.

  • prior – BNN priors specified as a string. Supported priors are Gaussian, Hshoe, RegHshoe

fit(X=None, y=None, train_loader=None)

Fits BNN regression model.

Parameters
  • X – array-like of shape (n_samples, n_features) or (n_samples, n_classes). Features vectors of the training data or the probability scores from the base model. Ignored if train_loader is not None.

  • y – array-like of shape (n_samples,) or (n_samples, n_targets) Target values Ignored if train_loader is not None.

  • train_loader – pytorch train_loader object.

Returns

self

predict(X, mc_samples=100)

Obtain calibrated predictions for the test points.

Parameters
  • X – array-like of shape (n_samples, n_features) or (n_samples, n_classes). Features vectors of the training data or the probability scores from the base model.

  • mc_samples – Number of Monte-Carlo samples.

Returns

A namedtupe that holds

y_pred: ndarray of shape (n_samples,)

Predicted labels of the test points.

y_prob: ndarray of shape (n_samples, n_classes)

Predicted probability scores of the classes.

y_prob_var: ndarray of shape (n_samples,)

Variance of the prediction on the test points.

y_prob_samples: ndarray of shape (mc_samples, n_samples, n_classes)

Samples from the predictive distribution.

Return type

namedtuple