Optimizing GRNN with Genetic Algorithm?

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, one for each variable.
Can you figure out if i am doing anything wrong. The dimensions of the matrix are according to 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

1 个评论

Hi there, I know it's an old question, but have you found the question for it?

请先登录,再进行评论。

回答(1 个)

Alan Weiss
Alan Weiss 2016-10-26
You are confusing the data and the control variables. Control variables are those variables that you want the solver to move in order to find a local optimum. You need to get all your control variables in one vector, usually called x. See Compute Objective Functions, and also see Passing Extra Parameters.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation

标签

Community Treasure Hunt

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

Start Hunting!

Translated by