gradient descent for custom function
Show older comments
I have four equations:
1) e = m - y
2) y = W_3 * h
3) h = z + W_2 * z + f
4) f = W_1 * x
I want to update W_1, W_2 and W_3 in order to minimize a cost function J = (e^T e ) by using gradient descent.
x is an input, y is the output and m is the desired value for each sample in the dataset
I would like to do W_1 = W_1 - eta* grad(J)_w_1
W_2 = W_2 - eta* grad(J)_w_2
W_3 = W_3 - eta* grad(J)_w_3
Going through documentation I found out that you can train standard neural networks. But notice that I have some custom functions, so I guess it would be more of an optimization built in function to use.
Any ideas?
Answers (2)
so I guess it would be more of an optimization built in function to use.
No, not necessarily. Your equations can be implemented with fullyConnectedLayers and additionLayers.
3 Comments
L
on 24 Apr 2024
e = m - y = m - W_3*h = m - W_3*(z + W_2 * z + W_1 * x )
Now if you formulate this as
e = W1*z + W2*x - m
with
W1 = W_3 + W_2*W_3 and W2 = W_1*W_3
your problem is
min: || [z.',x.']*[W1;W2] - m ||_2
and you can use "lsqlin" to solve.
10 Comments
L
on 24 Apr 2024
One other thing: shouldnt this W1 = W_3 + W_2*W_3 and W2 = W_1*W_3 be W1 = W_3 + W_3*W_2 and W2 = W_3*W_1 ?
Is W_2*W_3 different from W_3*W_2 and W_1*W_3 different from W_3*W_1 ?
I thought the W_i's are single numbers as usual for regression problems:
y = a*x + b
where a, b are scalars and x and y are vectors of a certain length.
L
on 24 Apr 2024
L
on 24 Apr 2024
Torsten
on 24 Apr 2024
But then you have much more free variables to be fitted than input data. Does that make sense ?
L
on 24 Apr 2024
Categories
Find more on Deep Learning Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!