The ga runs very well without the constraints
[x2, fval2,scores2] = ga(@(x) ann_y(eff_y,x),77,options_y);
My objective function is this
function objective=ann_y(eff_y,x)
> > x=x.';
> > objective=eff_y(x); (  because I want to maximize function)
> > eff_y :neural network
I passed eff_y into input variables because I was getting error of undefined eff_y variable(eff_y neural network: 77in, 1out). But as I said the ga runs ok. The problem is that except the maximization of the fitness function I am interested in the final population as they represent y coordinates that must obey to these linear constraints.
From what I understand the ga creates new populations that are
parent = [x1,1 x1,2 ... x1,77](x2 is of this type) and then judges them by my constraints and if they pass, they continue to produce generations.
Any ideas for the data type double error.
Thanks a lot, you 've been great help so far.
Alan Weiss <aweiss@mathworks.com> wrote in message
<gor7ta$mam$1@fred.mathworks.com>...
> Hi, I am not sure what is going on here. Can you get GA to run with no
> constraints? I suspect (but am not sure) that your fitness function
> might not be formulated properly. How do you pass 'objective' to ga? Do
> you call
> ga(@(x)objective(eff_y,x),77)
> or do you do something else? It appears (but again I am not sure) that
> you are using eff_y to represent both a parameter and a function (you
> call ann_y(eff_y,x), which has eff_y look like a parameter, but then you
> write objective = eff_y(x), which has eff_y look like a function).
>
> One more thing: it is bad practice to formulate linear inequalities in a
> nonlinear constraint function. You didn't include the nonlinear
> equalities, so the syntax was wrong, but even if you fix the syntax, it
> is much less efficient to use a nonlinear constraint function than to
> pass a linear constraint matrix A.
>
> Good luck,
>
> Alan Weiss
> MATLAB mathematical toolbox documentation
>
> kentavros babis wrote:
> > I have read the ga doc. And even tried to write a constraint function
> >
> > function [c]=constraint_y(Aineq,x)
> > x=x.';
> > c=Aineq*x;
> >
> > but again I receive the same error.
> >
> > Ga options are the default, double vector and so on.
> > I must mention that my fitness function is neural network with 77 inputs and one output.
> > fitness function
> > function objective=ann_y(eff_y,x)
> > x=x.';
> > objective=eff_y(x);
> > eff_y :neural network
> > I have to transpose matrix for neural network to take input data from ga.
> > Any ideas about the data type double.
> >
> > Alan Weiss <aweiss@mathworks.com> wrote in message <gopbrh$kq8$1@fred.mathworks.com>...
> >> Yes, if you want to use this type of constraint, you need to have your
> >> data type to be double. If you have a custom or bitstream data type,
> >> well, you'll have to do something else.
> >>
> >> Once again, I recommend you look in the manual:
> >> doc ga
> >> or
> >> http://www.mathworks.com/access/helpdesk/help/toolbox/gads/ga.html
> >>
> >> Alan Weiss
> >> MATLAB mathematical toolbox documentation
> >>
> >> kentavros babis wrote:
> >>> Alan Weiss <aweiss@mathworks.com> wrote in message <gop29g$se3$1@fred.mathworks.com>...
> >>>> doc ga
> >>>>
> >>>> Use the syntax
> >>>> [x,fval,exitflag] = ga(fitnessfcn,nvars,A,b)
> >>>>
> >>>> x = ga(fitnessfcn,nvars,A,b) finds a local minimum x to fitnessfcn,
> >>>> subject to the linear inequalities A*x <= b. fitnessfcn accepts input x
> >>>> and returns a scalar function value evaluated at x.
> >>>>
> >>>> If the problem has m linear inequality constraints and n variables, then
> >>>>
> >>>> A is a matrix of size mbyn.
> >>>>
> >>>> b is a vector of length m.
> >>>>
> >>>> The matrix A multiplies your 77variable vector x.
> >>>> Create A with rows of the form 0,...,0,1,0,...,0,1,0,...,0
> >>>> The +1 corresponds to an xn,21 variable
> >>>> The 1 corresponds to an xn,41 variable
> >>>> similarly for xn,22 and xn,42
> >>>> Your vector b should be all zeros.
> >>>>
> >>>> Alan Weiss
> >>>> MATLAB mathematical toolbox documentation
> >>>>
> >>>> kentavros babis wrote:
> >>>>> I have a initial population of 20 parents each of which has 77 variables.
> >>>>> parent1 = [x1,1 x1,2 ... x1,77]
> >>>>> parent2 = [x2,1 x2,2 ... x2,77]
> >>>>> . . . .
> >>>>> . . . .
> >>>>> . . . .
> >>>>> parent20= [x20,1 x20,2 ... x20,77]
> >>>>>
> >>>>>
> >>>>> How can i insert a constraint stating that xn,21<xn,41 n=1,2,...,20
> >>>>> xn,22<xn,42 n=1,2,...,20
> >>>>>
> >>>>> thanks in advance
> >>>
> >>> Thanks a lot, i managed to create the matrix A and vector b but now I get error ga only accepts inputs of data type double.
