-
Notifications
You must be signed in to change notification settings - Fork 457
Description
Hello,
Thanks for an awesome package! Been using it since the release.
Recently I've found applications where it would be interesting to do MOO where at least one objective is a function of the partial derivatives of a (GPyTorch) model with respect to some of the input parameters.
I guess I could just use the posterior mean of the model and do something like
x = torch.linspace(0,1,5).unsqueeze(-1).repeat(1,2).to(dtype=torch.float) # straight line across the unit square
x.requires_grad = True
y = model.posterior(x).mean
grad_f = torch.autograd.grad(y,x,torch.ones_like(y),retain_graph=True)[0]within a custom objective - and let the other objectives be handled in the usual BoTorch way with quasi MC-sampling.
But since I want to leverage quasi-MC sampling for the gradient objective as well, I wonder if there is any better way than doing
x2 = x.repeat([num_samples,1])
y2 = sampler(model.posterior(x2)).squeeze().T
z = torch.eye(num_samples).view(-1,1).repeat(1,x.size(0)).view(num_samples,num_samples*x.size(0)).T
gradient_samples = torch.autograd.grad(y2,x2,z,retain_graph=True)[0]and then reshape the gradient_samples. Note: here num_samples is the number of samples used by the (quasi) MC sampler sampler. Not even sure if this is correct though, but you get the idea: the inputs to autograd.grad needs to be repeated so that I get gradient samples - not the sum of the gradient samples as would be the case if I would have followed the above approach.
Any ideas?
Br,
Jimmy