Sensitivity of output y with respect to input x?

Hi All,

I have developed a regression CNN model using Pytorch, and I am interested in finding the sensitivities of the output y with respect to the input x. Please note that I am interested in finding the sensitivity of the output with respect to the input rather than finding the sensitivity of the loss function with respect to the input. Is it possible to do that? If yes, any guidance would be much appreciated.

Thanks
Diab

Hi Diab,

Could you clarify what you mean by sensitivity? I’d love to help but am not sure exactly what you’re looking for.

Thanks!
Adam

Hi, so if by sensitivity you mean, how sensible is the output to changes in the input (e.g the gradients). Then something like this could work:

>>> inp = torch.randn(5)
>>> 

>>> inp.requires_grad_()
tensor([-0.1457,  0.1341,  0.6884, -1.9446, -0.2557], requires_grad=True)
>>> x = inp * 7 
>>> x = x/10
>>> out = torch.exp(x)
>>> out.sum().backward()
>>> inp.grad
tensor([0.6321, 0.7689, 1.1334, 0.1794, 0.5853])

Also, one clarification, you normally don’t compute the sensitivity of the loss function with respect to the input, but rather, to the model’s parameters. Hope, this helps :slight_smile:

1 Like

Hi Deigo,

Thanks for the reply. What does .sum() do here?
Thanks

I mean d_output/d_input. Sorry for not being clear.