I have been attempting to run a script that calls a function but I keep
getting the following error: "value on right hand side of assignment is undefined". The script and function code are shown below respectively. input = [ 0 0 1;0 1 1;1 0 1;1 1 1]; correct_output = [0;0;1;1]; Weight = 2*rand(1,3) - 1; for epoch = 1:10000 Weight = SGD_method(Weight, input, correct_output) endfor save('Trained_Network.mat') the function function SGD_method(Weight, input, correct_output) alpha = 0.9; N = 4; for k = 1:N transposed_Input = input(k, :)'; d = correct_output(k); weighted_Sum = Weight*transposed_Input; output = sigmoid(weighted_Sum); error = d - output; delta = output*(1-output)*error; dWeight = alpha*delta*transposed_Input; Weight(1) = Weight(1) + dWeight(1); Weight(2) = Weight(2) + dWeight(2); Weight(3) = Weight(3) + dWeight(3); endfor endfunction Please provide assistance Thanks -- Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html |
On Friday, 7 August 2020, andetroy <[hidden email]> wrote: > I have been attempting to run a script that calls a function but I keep > getting the following error: "value on right hand side of assignment is > undefined". The script and function code are shown below respectively. > > input = [ 0 0 1;0 1 1;1 0 1;1 1 1]; > correct_output = [0;0;1;1]; > Weight = 2*rand(1,3) - 1; > for epoch = 1:10000 > Weight = SGD_method(Weight, input, correct_output) > endfor > > save('Trained_Network.mat') > > > the function > > function SGD_method(Weight, input, correct_output) > alpha = 0.9; > > N = 4; > for k = 1:N > transposed_Input = input(k, :)'; > d = correct_output(k); > weighted_Sum = Weight*transposed_Input; > output = sigmoid(weighted_Sum); > > error = d - output; > delta = output*(1-output)*error; > > dWeight = alpha*delta*transposed_Input; > > Weight(1) = Weight(1) + dWeight(1); > Weight(2) = Weight(2) + dWeight(2); > Weight(3) = Weight(3) + dWeight(3); > endfor > endfunction > > > Please provide assistance You do not say which line the error occurs on, but perhaps the problem is you have not defined the sigmoid function? Cheers... Ian |
On Fri, Aug 7, 2020, 4:45 AM Ian McCallion <[hidden email]> wrote:
SGD_method has no return value. The syntax is: function returnvalue = functionname(argument) It looks like in your case you want function Weight = SGD_method(Weight, input, correct_output) |
Hello Ian, thanks for the speedy reply. I have attached screenshots of the
scripts and the eroor message in the command window. As you can see, I have declared the sigmoid function. <https://octave.1599824.n4.nabble.com/file/t373848/command_window.png> <https://octave.1599824.n4.nabble.com/file/t373848/sigmoid.png> <https://octave.1599824.n4.nabble.com/file/t373848/function.png> <https://octave.1599824.n4.nabble.com/file/t373848/script.png> -- Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html |
Thank you, this worked for me.
-- Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html |
On Fri, Aug 7, 2020, 5:42 AM andetroy <[hidden email]> wrote: Thank you, this worked for me. You're welcome. |
Free forum by Nabble | Edit this page |