error: value on right hand side of assignment is undefined

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

error: value on right hand side of assignment is undefined

andetroy
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


Reply | Threaded
Open this post in threaded view
|

Re: error: value on right hand side of assignment is undefined

Ian McCallion


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

Reply | Threaded
Open this post in threaded view
|

Re: error: value on right hand side of assignment is undefined

BGreen

On Fri, Aug 7, 2020, 4:45 AM Ian McCallion <[hidden email]> wrote:


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

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)


Reply | Threaded
Open this post in threaded view
|

Re: error: value on right hand side of assignment is undefined

andetroy
Reply | Threaded
Open this post in threaded view
|

Re: error: value on right hand side of assignment is undefined

andetroy
Thank you, this worked for me.



--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: error: value on right hand side of assignment is undefined

BGreen
On Fri, Aug 7, 2020, 5:42 AM andetroy <[hidden email]> wrote:
Thank you, this worked for me.



--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html



You're welcome.