0
$\begingroup$

I have this following (toy) program:

import torch

x_  = 3.1
a_  = 4.7
k_  = 3.0

x = torch.tensor([ x_ ], dtype=torch.double, requires_grad = True)
a = torch.tensor([ a_ ], dtype=torch.double, requires_grad = True)
k = torch.tensor([ k_ ], dtype=torch.double, requires_grad = True)

y = a * x ** k

d = 0.001
g = y.grad_fn( torch.tensor([ d ], dtype=torch.double))

print( g[0].item() ) # 0.02979... =  d * x_ ** k_
print( g[1].item() ) # 0.0047     =  d * a_

With g[0].item() and g[1].item(), I can calculate the approximate change of y when adding d to a_ or x_. However, g[2], which I believed to calculate the change of y with respect to k, is undefined. Why is that and how can I calculate the desired value?

$\endgroup$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.