Please I am working on a physical system, and after running simulations I have 2 arrays of variables like this:
D = [0.01, 0.02, …, 0.05]
m = [1, 2, …, 5]
Please how do I find the derivative (∂D/∂m) using Zygote, given only the above 2 arrays of values. I have checked the docs and I do not understand it. I do not have a function, so I am thinking Zygote could compute the derivative directly.
Hello @alegeaa and welcome!
If you don’t have a function, you cannot compute a derivative. Indeed, the arrays D and m might have been generated by an arbitrary process we know nothing about.
However, what I mean by “function” is quite fuzzy, and it could encompass physical simulators. Do you have access to one or not at all?
Hello @gdalle thank YOU FOR YOUR REPLY. I have access to all, i.e. both D and m arrays. I wrote a function to compute the derivative numerically by this formula, ∂D/∂m = [D(m1+delta/2) - D(m1-delta/2)]/ delta. However, I would like to use Zygote for this. Any directions please?
One reason is that without the function f, you really cannot say anything about the relation between x and y. For instance, consider x = 0 and y = 0:
This could be the result of f_1(x) = x, in which case f_1'(x) = 1
This could be the result of f_2(x) = -x, in which case f_2'(x) = -1
The same goes if you have several input-ouput pairs (x_i, y_i). You need to have access to the function to differentiate it, whether you use finite differences, symbolic differentiation or automatic differentiation (with Zygote or ForwardDiff)
So my message above tells you why your function calc_differentials is not correct. You need access to the function compute_D if you want to retrieve any useful derivative information.
Supposing you do, then you would compute the derivative at a point m using the following syntax:
i = 3
I suggested jacobian because I thought compute_D took a vector as input and returned another vector. If the output is a real number, gradient is the way to go.