ECJ-INTEREST-L Archives

January 2016

ECJ-INTEREST-L@LISTSERV.GMU.EDU

Options: Use Monospaced Font
Show HTML Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
bijoy patwal <[log in to unmask]>
Reply To:
ECJ Evolutionary Computation Toolkit <[log in to unmask]>
Date:
Fri, 22 Jan 2016 12:02:31 +0530
Content-Type:
multipart/alternative
Parts/Attachments:
text/plain (7 kB) , text/html (10 kB)
Thanks for the prompt reply Sean.I forgot to change the no of children in
the parameter file.
I am always getting the same fitness for every evolution though .

Can u please have a look at fitness function and give me any suggestions on
how I should approach the problem.
Currently i  increment  sum on each hit.

Generation: 0
Best Individual:
Subpopulation 0:
Evaluated: true
Fitness: Standardized=0.25 Adjusted=0.8 Hits=1
Tree 0:
 (! (! (&& (! (|| y x)) (&& (&& x x) (|| x
     y)))))

Generation: 1
Best Individual:
Subpopulation 0:
Evaluated: true
Fitness: Standardized=0.25 Adjusted=0.8 Hits=1
Tree 0:
 (&& (&& (|| (|| (&& x y) (! x)) (&& (&& y
     x) (&& x y))) (|| (|| (|| y y) (|| y x))
     (|| (&& x x) (&& y x)))) (|| (|| (! (&& x
     x)) (! (|| x x))) (! (! (|| y x)))))

Generation: 2
Best Individual:
Subpopulation 0:
Evaluated: true
Fitness: Standardized=0.25 Adjusted=0.8 Hits=1
Tree 0:
 (&& y x)



On Fri, Jan 22, 2016 at 11:48 AM, Sean Luke <[log in to unmask]> wrote:

> 1. Don't override checkConstraints.  Get rid of that.
>
> 2. Verify that your parameter file is using a NodeConstraints for your
> class ("&&" I presume) that has two children.
>
> Sean
>
> On Jan 22, 2016, at 12:57 AM, bijoy patwal <[log in to unmask]> wrote:
>
> > Hi,
> > I am new to java and genetic programming and trying to write a GA for
> xor gate using functions and,or,not.
> > I am getting an error :-
> > Incorrect number of children for node ! at pop.subpop.0.species.ind, was
> expecting 1 but got 2.
> >
> > i would be thankful for any help.
> >
> > the definitions of some functions and regression class are as follows-
> >
> > NOT.java-
> > public class Not extends GPNode
> > {
> >       public String toString() { return "!"; }
> >
> >     public int expectedChildren() { return 1; }
> >
> >     public void eval(final EvolutionState state,final int thread, final
> GPData input,final ADFStack stack,
> >             final GPIndividual individual, final Problem problem)
> >             {
> >                       boolean result;
> >                       //Boolean_Data rd = ((Boolean_Data)(input));
> >
> >                       Boolean_Data rd = ((Boolean_Data)(input));
> >
>  children[0].eval(state,thread,input,stack,individual,problem);
> >                       result  = !rd.x;
> >
> >
> >             }
> > }
> >
> > And.Java
> >
> > public class And extends GPNode
> > {
> >       public String toString() { return "&&"; }
> >
> >     public int expectedChildren() { return 2; }
> >
> >     public void checkConstraints(final EvolutionState state,final int
> tree,
> >             final GPIndividual typicalIndividual,
> >             final Parameter individualBase)
> >     {
> >
>  super.checkConstraints(state,tree,typicalIndividual,individualBase);
> >       if (children.length!=2)
> >               state.output.error("Incorrect number of children for node
> " +
> >                               toStringForError() + " at " +
> >                               individualBase);
> >     }
> >
> >     public void eval(final EvolutionState state,final int thread,
> >             final GPData input,final ADFStack stack,
> >             final GPIndividual individual, final Problem problem)
> >             {
> >                       boolean result;
> >
> >                       Boolean_Data rd = ((Boolean_Data)(input));
> >
>  children[0].eval(state,thread,input,stack,individual,problem);
> >                       result  = rd.x;
> >
> >
>  children[1].eval(state,thread,input,stack,individual,problem);
> >                   rd.x=result && rd.x;
> >
> >
> >             }
> > }
> >
> > REGRESSION.java
> > public class MultiValuedRegression extends GPProblem implements
> SimpleProblemForm
> > {
> >       public static final String P_DATA = "data";
> >
> >       public boolean currentX;
> >       public boolean currentY;
> >       public boolean expected_result;
> >       double sum = 0;
> >       int hits=0;
> >
> >        public Object clone()
> >      {
> >                MultiValuedRegression newobj = (MultiValuedRegression)
> (super.clone());
> >                newobj.input = (Boolean_Data)(input.clone());
> >                return newobj;
> >      }
> >
> >       public void setup(final EvolutionState state,
> >             final Parameter base)
> >       {
> >                       super.setup(state,base);
> >
> >                       if (!(input instanceof Boolean_Data))
> >                               state.output.fatal("GPData class must
> subclass from " + Boolean_Data.class,
> >                       base.push(P_DATA), null);
> >       }
> >        public void evaluate(final EvolutionState state,  final
> Individual ind, final int subpopulation, final int threadnum)
> >       {
> >                                       Boolean_Data  input =
> (Boolean_Data)(this.input);
> >                                        sum = 0;
> >                                        hits=0;
> >
> >                                       currentX=false;
> >                                       currentY=false;
> >                                       expected_result= true;
> >
>  ((GPIndividual)ind).trees[0].child.eval(
> >
>  state,threadnum,input,stack,((GPIndividual)ind),this);
> >
> >                                       if(expected_result == input.x)
> >                                       {
> >                                               sum++;
> >                                               hits++;
> >                                       }
> >
> >                                       currentX=true;
> >                                       currentY=false;
> >                                       expected_result = false;
> >
>  ((GPIndividual)ind).trees[0].child.eval(
> >
>  state,threadnum,input,stack,((GPIndividual)ind),this);
> >                                       if(expected_result == input.x)
> >                                       {
> >                                               sum++;
> >                                               hits++;
> >                                       }
> >
> >                                       currentX=false;
> >                                       currentY=true;
> >                                       expected_result = false;
> >
>  ((GPIndividual)ind).trees[0].child.eval(
> >
>  state,threadnum,input,stack,((GPIndividual)ind),this);
> >                                       if(expected_result == input.x)
> >                                       {
> >                                               sum++;
> >                                               hits++;
> >                                       }
> >                                       currentX=false;
> >                                       currentY=false;
> >                                       expected_result = true;
> >
>  ((GPIndividual)ind).trees[0].child.eval(
> >
>  state,threadnum,input,stack,((GPIndividual)ind),this);
> >                                       if(expected_result == input.x)
> >                                       {
> >                                               sum++;
> >                                               hits++;
> >                                       }
> >             KozaFitness f = ((KozaFitness)ind.fitness);
> >             f.setStandardizedFitness(state, sum/4);
> >             f.hits = hits;
> >             ind.evaluated = true;
> >       }
> >
> >
> >
> > }
> >
>


ATOM RSS1 RSS2