On Friday, 7 August 2020, andetroy <andetroy@gmail.com> 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)