Trouble in PSO based training; Matlab shows error in function value updates

1 view (last 30 days)
Hello
I am trying to train one neural network with PSO but it throws a common error that I am not able to understand.
I have attached the code file here; kindly help me to recognize the problem and provide a way to solve that issue. (Working on Matlab 2015)
It returns this error message.
Error:
Error using network/subsasgn>network_subsasgn (line 553)
net.LW{2,1} must be a 3-by-6 matrix.
Error in network/subsasgn (line 13)
net = network_subsasgn(net,subscripts,v,netname);
Error in myfunc (line 21)
net.lw{2,1}=x1;
Error in @(x)myfunc(x,n,m,o,net,inputs,targets)
It was working fine earlier when I have arranged input in a matrix size (45x100) and targets (1x100) and hidden layer size n=5. But as those arrangements were not providing me desired results so I updated inputs, targets and hidden layer values as (15x300), (3x100) and 6 respectively. I need to extract dataset (with 15 features) into three categories so used 3 output neurons.
  2 Comments
Greg Heath
Greg Heath on 8 May 2017
How in the world can you assume that the two problems
[ 45 100 ] ==> [ 1 100 ]
and
[ 15 300 ] ==> [ 3 100 ]
are equivalent ???
Hope this helps.
Greg
JAGRITI SAINI
JAGRITI SAINI on 13 May 2017
Thanks Greg Heath.
But this was a typo.. the dimensions are 15x300 and 3x300 in program. But things are not yet working.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 7 May 2017
You do not initialize x1, but you assign
x1(i)=x(k);
inside a "for" loop. When you assign to a vector with a single subscript in that way, the result will be a row vector of appropriate length. Therefore your x1 will be a row vector.
You attempt to assign that row vector to net.lw{2,1} . However, the checking code for the assignment detects that you are assigning a row vector and says "Hold on, you need to assign a 3 x 6 matrix!"
You construct a valid 2D xi to assign to net.lw{1,1}; you have to do something similar for x1 .

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!