autodiff
autodiff copied to clipboard
Custom Matrix Ops
Hi! Is it possible to write custom operations for autodiff in the reverse mode?
Consider for instance the matrix inverse. Backpropagating through this operation explicitly would create a very long computational graph and be impractical. But you can write a "matrix operation" that does this easily(see below, hope python syntax is ok).
class Inverse:
def forward(self,X):
self.inp=X
self.out=np.linalg.inv(X)
return self.out
def backward(self,err):
return -np.dot(self.out.T,np.dot(err,self.out.T))