Good afternoon,
I wanted to ask some advice about Automatic Differentiation in Julia. I am aware of the fact that in AD mutating arrays are not supported, but I find it difficult to write my code in a non mutating fashion, therefore I wanted to ask if somebody has any help/advice on how to do that. For example:
N = 10
Y = rand(N)
W = rand(N)
A = rand(N)
for i in 1:N
p = Y[i] * W[i]
if p < 0.3
A[i] = A[i] - p
else
A[i] = 0
end
end
my naive approach was to:
newA = zeros(N)
p = Y .* W
pIdx = findall(p .< 0.3)
newA[pIdx] = A[pIdx] - p[pIdx]
notIdx = findall(p .>= 0.3)
newA[notIdx] = 0
A = newA
which of course does not work. Does anybody have any suggestions/advice or resources on the matter?
One of the sources I encountered suggest defining your own pullback for the mutating parts. Would anybody know where to start in these regard?
Thank you in advance!