From: Jon Smith on 2 Apr 2010 17:58 I am trying to use the genetic algorithm (ga), but keep getting an error saying the inner matrix dimensions must agree. I know the objective function is correct because it passes through when using fminsearch or patternsearch, just not ga. Here is my code for all three... params_hat = fminsearch(@myfunction, params_in) params_hat = patternsearch(@myfunction, params_in) params_hat = ga(@myfunction, size(params_in,1)) Am I using ga incorrectly?
From: Alan Weiss on 4 Apr 2010 08:58 Jon Smith wrote: > I am trying to use the genetic algorithm (ga), but keep getting an error > saying the inner matrix dimensions must agree. I know the objective > function is correct because it passes through when using fminsearch or > patternsearch, just not ga. Here is my code for all three... > > params_hat = fminsearch(@myfunction, params_in) > params_hat = patternsearch(@myfunction, params_in) > params_hat = ga(@myfunction, size(params_in,1)) > > Am I using ga incorrectly? There is an inconsistency between ga syntax and some other solvers that might be the cause of your problem. Most Optimization Toolbox solvers accept input vectors of any size and orientation, but they prefer column vectors. ga insists on row vectors; if you pass a column vector, ga will misinterpret the vector as a population of 1-D elements rather than a single member of a population. Alan Weiss MATLAB mathematical toolbox documentation
From: Jon Smith on 4 Apr 2010 19:36 Thanks Alan, but I am not sure this is the problem. There is definitely a syntax inconsistency, but if you see my code below, the params_in is a 17x1 vector, so what I am passing into ga is just a scalar equal to 17. I still get an error with this scalar. Thanks! Alan Weiss <aweiss(a)mathworks.com> wrote in message <hpa2dm$8l7$1(a)fred.mathworks.com>... > Jon Smith wrote: > > I am trying to use the genetic algorithm (ga), but keep getting an error > > saying the inner matrix dimensions must agree. I know the objective > > function is correct because it passes through when using fminsearch or > > patternsearch, just not ga. Here is my code for all three... > > > > params_hat = fminsearch(@myfunction, params_in) > > params_hat = patternsearch(@myfunction, params_in) > > params_hat = ga(@myfunction, size(params_in,1)) > > > > Am I using ga incorrectly? > There is an inconsistency between ga syntax and some other solvers that > might be the cause of your problem. Most Optimization Toolbox solvers > accept input vectors of any size and orientation, but they prefer column > vectors. ga insists on row vectors; if you pass a column vector, ga will > misinterpret the vector as a population of 1-D elements rather than a > single member of a population. > > Alan Weiss > MATLAB mathematical toolbox documentation
|
Pages: 1 Prev: Multivariate polynomial multiplication Next: two function in one plot and only one legend |