Homoscedastic Uncertainty
- class softsensor.homoscedastic_model.HomoscedasticModel(model, homoscedastic_var)[source]
Wrapper class for point prediction models that uses a constant variance for all inputs
- Parameters:
model (uncertainty model) – model that is used for prediction
homoscedastic_var (tensor[float], shape=[model.pred_size]) – Homoscedastic variance
- Return type:
None.
Examples
Define Model
>>> import softsensor.autoreg_models >>> import softsensor.homoscedastic_model as hm >>> import torch >>> m = softsensor.autoreg_models.ARNN(2, 1, 10, 10, [16, 8]) >>> vars = torch.tensor([1]) >>> homosc_m = hm.HomoscedasticModel(m, vars) >>> input = torch.randn(32, 2, 10) >>> rec_input = torch.randn(32, 1, 10) >>> output = homosc_m(input, rec_input) >>> print(output[0].shape) torch.Size([32, 1, 1]) >>> print(output[1].shape) torch.Size([32, 1, 1])
Define Data
>>> import softsensor.meas_handling as ms >>> import numpy as np >>> import pandas as pd >>> t = np.linspace(0, 1.0, 101) >>> d = {'inp1': np.random.randn(101), 'inp2': np.random.randn(101), 'out': np.random.randn(101)} >>> handler = ms.Meas_handling([pd.DataFrame(d, index=t)], ['train'], ['inp1', 'inp2'], ['out'], fs=100)
Define Model with Uncertainty
>>> loader = handler.give_list(window_size=10, keyword='training', rnn_window=10, batch_size=1) >>> vars = torch.tensor([1]) >>> homosc_m = hm.HomoscedasticModel(m, vars) >>> mean, var = homosc_m.prediction(loader[0]) >>> print(mean.shape) torch.Size([1, 101]) >>> print(var.shape) torch.Size([1, 101])
- forward(*args)[source]
Forward function to propagate through the network
- Parameters:
*args (input arguments) – (need to be the same as the Point model in __init__() needs)
- Returns:
mean (torch.tensor dtype=torch.float()) – shape=[batch size, pred_size]
std (torch.tensor dtype=torch.float() in [0,1]) – shape=[batch size, pred_size]
- prediction(dataloader, device='cpu')[source]
Prediction of a whole Time Series
- Parameters:
dataloader (Dataloader) – Dataloader to predict output
device (str, optional) – device to compute on. The default is ‘cpu’.
- Returns:
if loss_ft=None –
- (torch.Tensor, list[torch.Tensor])
tuple of Torch Tensor of same length as input and var
if loss_ft=torch loss funciton –
- (torch.Tensor, list[torch.Tensor], loss)
tuple of Torch Tensor of same length as input, var and loss