-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpredGPind_lap.py
35 lines (27 loc) · 896 Bytes
/
predGPind_lap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# -*- coding: utf-8 -*-
"""
Created on Tue Dec 28 18:50:45 2021
@author: mahom
"""
import torch
import gpytorch
from to_torch import to_torch
def predGPind_lap(test_x,likelihoods,models):
test_x = to_torch(test_x)
n_test = test_x.size(0)
n_task = 24
means = torch.zeros(n_test,n_task)
scales = torch.zeros(n_test,n_task)
for task in range(0,n_task):
model_k = models['task{}'.format(task+1)]
likelihood_k = likelihoods['task{}'.format(task+1)]
# Make predictions
model_k.eval()
likelihood_k.eval()
with torch.no_grad(), gpytorch.settings.fast_pred_var():
predictions = likelihood_k(model_k(test_x))
mean_k = predictions.mean
scale_k = predictions.scale
means[:,task] = torch.mean(mean_k)
scales[:,task] = torch.mean(scale_k)
return means,scales