Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
neural network as genetic algoritm fitness function

Subject: neural network as genetic algoritm fitness function

From: kentavros babis

Date: 26 Feb, 2009 16:14:01

Message: 1 of 4

I have created the following function
function objective=ann2(eff,x)
objective=eff(x);
where eff=@(x) sim(neural_network,x)
neural_network accepts 77 inputs and gives one output.

I' m trying to use
[x,fval,exitflag,output,final_pop] = ga(@ann2,77) and get in return

??? Input argument "x" is undefined.

Error in ==> ann2 at 2
objective=eff(x);
Error in ==> validate>@(x)fitness(x,FitnessFcnArgs{:}) at 135
    fitness = @(x) fitness(x,FitnessFcnArgs{:});

Error in ==> fcnvectorizer at 23
    y = fun(pop);

Error in ==> makeState at 48
            Score =
            fcnvectorizer(state.Population(initScoreProvided+1:end,:),FitnessFcn,1,options.SerialUserFcn);
            
Error in ==> gaunc at 41
state =
makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);

Error in ==> ga at 279
        [x,fval,exitFlag,output,population,scores] = gaunc(FitnessFcn,nvars,
        ...
Caused by:
    Failure in initial user-supplied fitness function evaluation. GA cannot
    continue.

Any ideas?

Subject: neural network as genetic algoritm fitness function

From: Steven Lord

Date: 26 Feb, 2009 16:56:24

Message: 2 of 4


"kentavros babis" <akentavros@yahoo.com> wrote in message
news:go6f49$ldu$1@fred.mathworks.com...
>I have created the following function
> function objective=ann2(eff,x)
> objective=eff(x);
> where eff=@(x) sim(neural_network,x)
> neural_network accepts 77 inputs and gives one output.
>
> I' m trying to use
> [x,fval,exitflag,output,final_pop] = ga(@ann2,77) and get in return

From:

http://www.mathworks.com/access/helpdesk/help/toolbox/gads/ga.html

" The objective function, fitnessfcn, accepts a vector x of size 1-by-nvars,
and returns a scalar evaluated at x."

GA calls ann2 with _one_ input argument while ann2 expects two input
arguments. If you want to be able to simulate your network inside the
objective function, you need to pass it into that objective function


neural_network = MyNeuralNetwork; % change this line to the appropriate code
[x, fval, exitflag, output, final_pop] = ga(@(x) ann2(neural_network, x),
77) % where aff2 is:


function objective = ann2(eff, x)
objective = sim(eff, x);


--
Steve Lord
slord@mathworks.com\

Subject: neural network as genetic algoritm fitness function

From: kentavros babis

Date: 27 Feb, 2009 19:51:01

Message: 3 of 4

"Steven Lord" <slord@mathworks.com> wrote in message <go6hjo$e30$1@fred.mathworks.com>...
>
> "kentavros babis" <akentavros@yahoo.com> wrote in message
> news:go6f49$ldu$1@fred.mathworks.com...
> >I have created the following function
> > function objective=ann2(eff,x)
> > objective=eff(x);
> > where eff=@(x) sim(neural_network,x)
> > neural_network accepts 77 inputs and gives one output.
> >
> > I' m trying to use
> > [x,fval,exitflag,output,final_pop] = ga(@ann2,77) and get in return
>
> From:
>
> http://www.mathworks.com/access/helpdesk/help/toolbox/gads/ga.html
>
> " The objective function, fitnessfcn, accepts a vector x of size 1-by-nvars,
> and returns a scalar evaluated at x."
>
> GA calls ann2 with _one_ input argument while ann2 expects two input
> arguments. If you want to be able to simulate your network inside the
> objective function, you need to pass it into that objective function
>
>
> neural_network = MyNeuralNetwork; % change this line to the appropriate code
> [x, fval, exitflag, output, final_pop] = ga(@(x) ann2(neural_network, x),
> 77) % where aff2 is:
>
>
> function objective = ann2(eff, x)
> objective = sim(eff, x);
>
>
> --
> Steve Lord
> slord@mathworks.com\
>
I did as you instructed above and the following error occured

[x, fval, exitflag, output, final_pop] = ga(@(x) ann2(eff, x),77)

??? Error using ==> network.sim at 178
Inputs are incorrectly sized for network.
Matrix must have 77 rows.

Error in ==> @(x)sim(eff_calculator_30,x)

Any ideas how to fix that and by the way is there anyway to set initial population as a matrix
 for example matrix=A (77x40)?

Subject: neural network as genetic algoritm fitness function

From: Ally

Date: 14 Jun, 2009 13:35:01

Message: 4 of 4

"kentavros babis" <akentavros@yahoo.com> wrote in message <go9g75$ce1$1@fred.mathworks.com>...
> "Steven Lord" <slord@mathworks.com> wrote in message <go6hjo$e30$1@fred.mathworks.com>...
> >
> > "kentavros babis" <akentavros@yahoo.com> wrote in message
> > news:go6f49$ldu$1@fred.mathworks.com...
> > >I have created the following function
> > > function objective=ann2(eff,x)
> > > objective=eff(x);
> > > where eff=@(x) sim(neural_network,x)
> > > neural_network accepts 77 inputs and gives one output.
> > >
> > > I' m trying to use
> > > [x,fval,exitflag,output,final_pop] = ga(@ann2,77) and get in return
> >
> > From:
> >
> > http://www.mathworks.com/access/helpdesk/help/toolbox/gads/ga.html
> >
> > " The objective function, fitnessfcn, accepts a vector x of size 1-by-nvars,
> > and returns a scalar evaluated at x."
> >
> > GA calls ann2 with _one_ input argument while ann2 expects two input
> > arguments. If you want to be able to simulate your network inside the
> > objective function, you need to pass it into that objective function
> >
> >
> > neural_network = MyNeuralNetwork; % change this line to the appropriate code
> > [x, fval, exitflag, output, final_pop] = ga(@(x) ann2(neural_network, x),
> > 77) % where aff2 is:
> >
> >
> > function objective = ann2(eff, x)
> > objective = sim(eff, x);
> >
> >
> > --
> > Steve Lord
> > slord@mathworks.com\
> >
> I did as you instructed above and the following error occured
>
> [x, fval, exitflag, output, final_pop] = ga(@(x) ann2(eff, x),77)
>
> ??? Error using ==> network.sim at 178
> Inputs are incorrectly sized for network.
> Matrix must have 77 rows.
>
> Error in ==> @(x)sim(eff_calculator_30,x)
>
> Any ideas how to fix that and by the way is there anyway to set initial population as a matrix
> for example matrix=A (77x40)?

Try to change networks's name all over the file.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us