Very new to genetic algorithms

46 views
Skip to first unread message

jameslau...@gmail.com

unread,
Nov 5, 2019, 1:46:16 PM11/5/19
to Inspyred
Hello,

I am very new to genetic algorithms and coding in general.  I am working on a research project for a university and needed a very simple Genetic Algorithm.  

I created a generator file for generating my population and an evaluator file for evaluating the fitness.  I'm working on the initializer file, and it runs for three generations, but then there is the following error from line 364 in the replacer.py file:


num_objectives = len(individuals[0]['individual'].fitness)

TypeError: object of type 'float' has no len()


If anyone could offer any help, it would be much appreciated.


Thanks,
Jamey Laughland

Aaron Garrett

unread,
Nov 5, 2019, 1:48:04 PM11/5/19
to Inspyred
It looks like you pulled your sample code from a multiobjective problem, but your problem appears to have only a single objective (i.e., your fitness is just a number, rather than a list of numbers). If that's true, then you don't even need to say the line that's giving you the problem.

--
Aaron Garrett



--
You received this message because you are subscribed to the Google Groups "Inspyred" group.
To unsubscribe from this group and stop receiving emails from it, send an email to inspyred+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/inspyred/88daba23-6ce7-4a33-bf39-6d81afe4bee6%40googlegroups.com.

Jamey Laughland

unread,
Nov 5, 2019, 1:56:50 PM11/5/19
to Inspyred
Hi Aaron,

Yes, you're correct.  I was able to fix it.  Thank you so much.

Best,
Jamey Laughland


On Tuesday, November 5, 2019 at 1:48:04 PM UTC-5, Aaron Garrett wrote:
It looks like you pulled your sample code from a multiobjective problem, but your problem appears to have only a single objective (i.e., your fitness is just a number, rather than a list of numbers). If that's true, then you don't even need to say the line that's giving you the problem.

--
Aaron Garrett



On Tue, Nov 5, 2019 at 1:46 PM <jameslau...@gmail.com> wrote:
Hello,

I am very new to genetic algorithms and coding in general.  I am working on a research project for a university and needed a very simple Genetic Algorithm.  

I created a generator file for generating my population and an evaluator file for evaluating the fitness.  I'm working on the initializer file, and it runs for three generations, but then there is the following error from line 364 in the replacer.py file:


num_objectives = len(individuals[0]['individual'].fitness)

TypeError: object of type 'float' has no len()


If anyone could offer any help, it would be much appreciated.


Thanks,
Jamey Laughland

--
You received this message because you are subscribed to the Google Groups "Inspyred" group.
To unsubscribe from this group and stop receiving emails from it, send an email to insp...@googlegroups.com.

Jamey Laughland

unread,
Nov 6, 2019, 4:28:38 PM11/6/19
to Inspyred
Hi Aaron,

I've got the GA working.  I want to create a plot with two of my fitness outputs from all the generations.  How do I store the fitness into a list or something similar?

Thanks,
Jamey

Aaron Garrett

unread,
Nov 6, 2019, 6:28:03 PM11/6/19
to Inspyred
You can use a file observer to save the information (both generational and individual) in files that you can look at or process after the run is finished: https://pythonhosted.org/inspyred/reference.html#inspyred.ec.observers.file_observer

An example of it being used is here: https://pythonhosted.org/inspyred/tutorial.html#id11

--
Aaron Garrett



To unsubscribe from this group and stop receiving emails from it, send an email to inspyred+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/inspyred/8ea24432-cf22-4f85-b413-ba3829735acb%40googlegroups.com.

Jamey Laughland

unread,
Nov 7, 2019, 2:23:19 PM11/7/19
to Inspyred
Awesome.  Thanks so much.

Best,
Jamey
Reply all
Reply to author
Forward
0 new messages