GP Marshalling/Unmarshalling Problem

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

GP Marshalling/Unmarshalling Problem

Kido Kido

Hi,Klaus 
I think there are a lot of confusion about marshalling/Unmarshalling:
During each generation, I wrote the population and the best to the file:
config.getEventManager().addEventListener(GeneticEvent.GPGENOTYPE_EVOLVED_EVENT,           new GeneticEventListener() {     public void geneticEventFired(GeneticEvent a_firedEvent) {     GPGenotype genotype = (GPGenotype) a_firedEvent.getSource();     int evno = genotype.getGPConfiguration().getGenerationNr();     System.out.println("Evolved generation " + evno);         // saving population to HD    XStream xstream = new XStream();                 PrintWriter outFile = null;                 try {                     outFile = new PrintWriter(new                     FileOutputStream("population.xml", false));                 } catch (FileNotFoundException ex) {                 Logger.getLogger(GPProblem.class.getName()).log(Level.FATAL, null, ex);                 } 
                String xml = xstream.toXML(genotype.getGPPopulation());                 outFile.print(xml);                 outFile.close();                                // saving best    xstream = new XStream();                 outFile = null;                 try {                     outFile = new PrintWriter(new                     FileOutputStream("best.xml", false));                 } catch (FileNotFoundException ex) {                 Logger.getLogger(GPProblem.class.getName()).log(Level.FATAL, null, ex);                 } 
                genotype.outputSolution(genotype.getAllTimeBest());                                xml = xstream.toXML(genotype.getAllTimeBest());                 outFile.print(xml);                 outFile.close();                     }    });


Now I use the following to see the fitness of my best when each time I start my program:
/* ONLY TEST BEST INDIVIDUAL */ System.out.print ("Reading Best..."); XStream xstream = new XStream();  File f = new File("best.xml");  InputStream oi = new FileInputStream(f); IGPProgram best = (IGPProgram) xstream.fromXML(oi); System.out.println();
                        gp.outputSolution(best);                         System.out.println ("Best's fitness before evaluating = " + best.getFitnessValue());
                                                ((GPProgram)best).calcFitnessValue(); System.out.println ("Best's fitness after evaluating = " + best.getFitnessValue());


At above I use calcFitnessValue() to force the best to re-evaluate the fitness.....
And I am wondering why I get different results  before evaluating and after re-evaluating???? Any Ideas?
     
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
jgap-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jgap-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: GP Marshalling/Unmarshalling Problem

Klaus Meffert-5
Hi Kido,

is your fitness function stable or does it contain random elements?

To do a deeper evaluation it would be helpful having a compileable source
code that exposes the problem.

Best

Klaus
www.klaus-meffert.com

 

> -----Original Message-----
> From: Kido Kido [mailto:[hidden email]]
> Sent: Friday, May 11, 2012 5:09 PM
> To: [hidden email]
> Subject: [jgap-users] GP Marshalling/Unmarshalling Problem
>
>
> Hi,Klaus
> I think there are a lot of confusion about marshalling/Unmarshalling:
> During each generation, I wrote the population and the best
> to the file:
> config.getEventManager().addEventListener(GeneticEvent.GPGENOT
> YPE_EVOLVED_EVENT,           new
> GeneticEventListener() {     public void
> geneticEventFired(GeneticEvent a_firedEvent) {    
> GPGenotype genotype = (GPGenotype)
> a_firedEvent.getSource();     int evno =
> genotype.getGPConfiguration().getGenerationNr();    
> System.out.println("Evolved generation " + evno);
>          // saving population to
> HD    XStream xstream = new
> XStream();                 PrintWriter outFile = null;        
>          try {                     outFile = new
> PrintWriter(new                    
> FileOutputStream("population.xml", false));                 }
> catch (FileNotFoundException ex) {                
> Logger.getLogger(GPProblem.class.getName()).log(Level.FATAL,
> null, ex);                 } 
>                 String xml =
> xstream.toXML(genotype.getGPPopulation());                
> outFile.print(xml);                 outFile.close();         
>                       // saving best   
> xstream = new XStream();                 outFile = null;      
>            try {                     outFile = new
> PrintWriter(new                    
> FileOutputStream("best.xml", false));                 } catch
> (FileNotFoundException ex) {                
> Logger.getLogger(GPProblem.class.getName()).log(Level.FATAL,
> null, ex);                 } 
>                
> genotype.outputSolution(genotype.getAllTimeBest());           
>                      xml =
> xstream.toXML(genotype.getAllTimeBest());                
> outFile.print(xml);                 outFile.close();         
>            }    });
>
>
> Now I use the following to see the fitness of my best when
> each time I start my program:
> /* ONLY TEST BEST INDIVIDUAL */
> System.out.print ("Reading Best..."); XStream
> xstream = new XStream();  File f = new
> File("best.xml");  InputStream oi = new
> FileInputStream(f); IGPProgram best =
> (IGPProgram) xstream.fromXML(oi);
> System.out.println();
> gp.outputSolution(best);
>                         System.out.println ("Best's
> fitness before evaluating = " + best.getFitnessValue());
>
> ((GPProgram)best).calcFitnessValue();
> System.out.println ("Best's fitness after evaluating = " +
> best.getFitnessValue());
>
>
> At above I use calcFitnessValue() to force the best to
> re-evaluate the fitness.....
> And I am wondering why I get different results  before
> evaluating and after re-evaluating???? Any Ideas?
>      


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
jgap-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jgap-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: GP Marshalling/Unmarshalling Problem

Kido Kido
In reply to this post by Kido Kido





Yes, my fitness function is a stable function, the best should behave same. I will list out my fitness function to you shortly.




From: Klaus Meffert <jgap@kl...> - 2012-05-15 10:38

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
jgap-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jgap-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: GP Marshalling/Unmarshalling Problem

Kido Kido

My fitness function is a simple one, just trying to discover i*i + i - 20......

@Overrideprotected double evaluate(final IGPProgram a_subject) { Object[] noargs = new Object[0];
double error = 0.0d;  for (int i=0; i<100; i++) {
win_prob_i.set(new Double(i));//win_prob_j.set(new Double(0)); try {     double result = a_subject.execute_double(0, noargs);     double diff = result - (i*i + i - 20);     error += diff * diff;} catch (ArithmeticException ex) {     System.out.println ("err: ");     System.out.println (a_subject);     throw ex;}} // for
return error; }
________________________________

> From: [hidden email]
> To: [hidden email]
> Subject: Re: [jgap-users] GP Marshalling/Unmarshalling Problem
> Date: Tue, 15 May 2012 19:10:03 +0800
>  
>  
>  
>  
>  
>  
> Yes, my fitness function is a stable function, the best should behave  
> same. I will list out my fitness function to you shortly.
>  
>  
>  
>  
> Re: [jgap-users] GP Marshalling/Unmarshalling  
> Problem<http://sourceforge.net/mailarchive/message.php?msg_id=29265612>
> From: Klaus Meffert <jgap@kl...> - 2012-05-15 10:38
>  
>  
> Hi Kido,
>  
> is your fitness function stable or does it contain random elements?
>  
> To do a deeper evaluation it would be helpful having a compileable source
> code that exposes the problem.
>  
> Best
>  
> Klaus
>   http://www.klaus-meffert.com<http://www.klaus-meffert.com/>
>  
>  
>  
     
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
jgap-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jgap-users
Loading...