qumphy.uq module
File: qumphy/uq.py Project: 22HLT01 QUMPHY Contact: oskar.pfeffer@ptb.de Gitlab: https://gitlab.com/qumphy Description: Uncertainty quantification utilities.
- qumphy.uq.deep_ensemble(models, data, weights=None)[source]
Compute deep ensemble of the data using the given models.
- Return type:
np.ndarray
- Parameters:
models (list) – List of callable models. Expected to return type
np.ndarray.data (np.ndarray) – Input data.
weights (np.ndarray, optional) – Weights for each model.
- Returns:
Weighted model output predictions.
- Return type:
np.ndarray
Examples
Compute unweighted deep ensemble prediction of two models on given data.
>>> model0 = lambda x : np.dot(np.zeros((1, 2)), x.T).reshape(-1, 1) >>> model1 = lambda x : np.dot(np.ones((1, 2)), x.T).reshape(-1, 1) >>> data = np.array([[0.0, 0.0], [0.0, 1.0], [1.0, 0.0], [1.0, 1.0]]) >>> deep_ensemble([model0, model1], data) [[0. ] [0.5] [0.5] [1. ]]
Compute weighted deep ensemble prediction of two models on given data.
>>> model0 = lambda x : np.dot(np.zeros((1, 2)), x.T).reshape(-1, 1) >>> model1 = lambda x : np.dot(np.ones((1, 2)), x.T).reshape(-1, 1) >>> data = np.array([[0.0, 0.0], [0.0, 1.0], [1.0, 0.0], [1.0, 1.0]]) >>> weights=np.array([0.0, 1.0]) >>> deep_ensemble([model0, model1], data) [[0.] [1.] [1.] [2.]]
- qumphy.uq.deep_ensemble_gaussian(prediction_mean, prediction_var, weights=None)[source]
Compute deep ensemble using the given predictions.
- Return type:
typing.Tuple[np.ndarray, np.ndarray]
- Parameters:
prediction_mean (np.ndarray) – Mean of the predicted gaussian distribution.
prediction_std (np.ndarray) – Variance of the predicted gaussian distribution.
weights (np.ndarray, optional) – Weights for each model.
- Returns:
Weighted ensemble prediction mean and variance.
- Return type:
Tuple[np.ndarray, np.ndarray]
Examples
Compute deep ensemble using the given predictions. Shape of prediction_mean and prediction_var should be:
[#models, #samples, #outputs]
>>> prediction_mean_1 = np.array([[[0.0], [0.5]], [[0.5], [1.0]]]) >>> prediction_mean_2 = np.array([[[1.0], [0.5]], [[0.5], [1.0]]]) >>> prediction_var_1 = np.array([[[0.0], [1.0]], [[0.5], [1.0]]]) >>> prediction_var_2 = np.array([[[0.0], [0.0]], [[0.5], [1.0]]]) >>> prediction_mean = np.array([prediction_mean_1, prediction_mean_2]) >>> prediction_var = np.array([prediction_var_1, prediction_var_2]) >>> weights = np.array([0.25, 0.75]) >>> deep_ensemble_gaussian(prediction_mean, prediction_var, weights)