Numerical answer to Partial derivative of Hopfield-style Energy in symbolic expression
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Pseudoscientist
el 28 de Jul. de 2022
Comentada: Torsten
el 2 de Ag. de 2022
Hello,
I'm implementing a gradient descent optimizer that uses Hopfield-style energy as function,
the hopfield-style energy is a function of p:
The hopfield energy equation can also be expressed as:
The gradient vector is defined as:
I'm attempting to calculate the gradient vector using the Symbolic Toolbox as follows:
r_mat = sym('r',[4,4]);
r_mat = r_mat(:);
p_mat = sym('p',[4*4,1]);
c_mat = sym('c',[4*4,1]);
Energy = -0.5*p_mat'*r_mat*p_mat' - c_mat'*p_mat;
%the first partial derivative:
q1 = -1*diff(testi1,p_mat(1,1));
which yields as the first term:
conj(c1) + r1_1*conj(p1) + (r1_2*conj(p5))/2 + (r1_3*conj(p9))/2 + (r2_1*conj(p2))/2 + (r1_4*conj(p13))/2 + (r2_2*conj(p6))/2 + (r2_3*conj(p10))/2 + (r3_1*conj(p3))/2 + (r2_4*conj(p14))/2 + (r3_2*conj(p7))/2 + (r3_3*conj(p11))/2 + (r4_1*conj(p4))/2 + (r3_4*conj(p15))/2 + (r4_2*conj(p8))/2 + (r4_3*conj(p12))/2 + (r4_4*conj(p16))/2
How can I replace the symbols with numbers to yield the q vector? I need the q-vector for the gradient descent
the algorithm I'm implementing: https://doi.org/10.1117/1.JEI.23.1.013007 (relevant part starts at Equation 5)
0 comentarios
Respuesta aceptada
Torsten
el 28 de Jul. de 2022
Editada: Torsten
el 28 de Jul. de 2022
p is (4x1), not (16x1).
And keep r_mat as matrix, then
E = -0.5*p.'*r_mat*p - c.'*p
( r_mat can be assumed symmetric ).
By the way:
dE/dp = -r_mat*p - c
assuming r_mat is symmetric.
To replace symbols by numerical values, use "subs".
5 comentarios
Torsten
el 2 de Ag. de 2022
I used symbolic to calculate the partial derivative and then used that to think how to write the equation in vector form
That's the best you can do, I guess.
Más respuestas (0)
Ver también
Categorías
Más información sobre Calculus en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!