How to optimize newgrnn function for best sigma (spread) parameter using genetic algorithm?

2 views (last 30 days)
How to optimize newgrnn function for best sigma (spread) parameter using genetic algorithm? I have an input matrix (x) of size 10x1895 (1895 rows with 10 independent variables) and an output Matrix (y) of size 1x1895 (1895 rows with 1 dependent variable). I create the GRNN as follow:
spread=0.5 nvars=10 net = newgrnn(x,y,spread) % a function handle h = @(sigma)mse_grnn(net, sigma, x, y)
% The function looks like this: function mse_calc = mse_grnn(net, sigma, inputs, targets) net = setwb(net, [sigma ; inputs; targets]); y = net(inputs); mse_calc = sum((y-targets).^2)/length(y); end
% then i am using GA to optimize sigma (spread factor for GRNN) as below:
opts = gaoptimset('PopulationSize', 40, 'Generations', 20, 'EliteCount', 6, 'TolFun', 1e-8, 'PlotFcns', @gaplotbestf);
[xbest, fbest] = ga(h, nvars, opts);
I get an error in the function about the matrix size mismatch. If i change the nvars (number of variables) to 1895 instead of 10, it all works fine. But logically its wrong, because there only 10 variable, 1895 is the number of data points. GA should find a set of 10 spread values for each variable.
Can you figure out if i am doing anything wrong. The dimensions of the matrix are according the newgrnn structure as given in Matlab help. x is R-by-Q matrix of Q input vectors, i.e. 1895 and y is S-by-Q matrix of Q target class vectors.
Thanks Irfan

Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!