Re: [Tutor] Problems with a Class
> -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Carlos > Sent: 12 January 2007 16:09 > To: tutor@python.org > Subject: [Tutor] Problems with a Class > > This is the area of the algorith that I think holds the info > that I need: > > def evolve(self, generations = 100): > > self.halt_reached = 0 > > for gen in range(generations): > > #Changed. > print 'GEN:',gen, self.entities > > self.do_mutation() > self.do_crossover() > print "Average fitness generation " + str(gen) + ": " + > str(self.avg_fitness()) > if self.debug == 1: > self.echo_fitness() > if self.halt >= 0: > max_entity = self.get_max_fitness() > fit = self.calc_fitness(max_entity) > if fit >= halt: > self.halt_reached = 1 > return [max_entity] I think if you change this line to: return self.entities, [max_entity] And handle the return as a tuple of two lists, you should get what you want. It does mean changing the code that calls this function to handle the different return value, of course. dom ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutor Digest, Vol 35, Issue 38
Hello, > Unfortunately, no. I for one can't interpret "I need the info every > time that it gets updated by the loop" The GA is creating solutions for a given problem, that are contained in self.entities that looks like this: Generation_01: [[1, 0, 0, 1, 0, 1, 0, 0, 0, 0], [0, 0, 1, 1, 1, 1, 1, 0, 0, 0], [1, 1, 0, 0, 1, 1, 1, 1, 1, 1], [0, 1, 1, 1, 1, 0, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 1, 0, 1]] Generation_02, Generation_03, Generation_04... Generation_25:[[1, 1, 1, 1, 1, 1, 1, 0, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]] self.entities gets new values with each generation, because the solution to a given problem is evolving and getting closer to a correct result. The problem is that with: Phenotypes = ga_inst.evolve(Gen) I only get the last generation -or iteration- and I need to actualize some objects position before evaluating the generation, so what I need is to get the values of self.entity on each generation. Since this values are going to be evaluted, I need to actualize some gemetrical objects with every new self.entities before evaluating the solution. I tried this: def evolve(self, generations = 100): """ Process a number of generations Stop if: - number of generations = generations - halt variable has been set AND there is an entity with a fitness which has obtained or exceeded the halt value Return the list of entities, or the halt-entity if prematurely halted """ self.halt_reached = 0 for gen in range(generations): print 'TEST', self.entities ### THIS IS MY CHANGE self.do_mutation() self.do_crossover() print "Average fitness generation " + str(gen) + ": " + str(self.avg_fitness()) if self.debug == 1: self.echo_fitness() if self.halt >= 0: max_entity = self.get_max_fitness() fit = self.calc_fitness(max_entity) if fit >= halt: self.halt_reached = 1 return [max_entity] return self.entities I can actually print the self.entities list once for each iteration, before the evaluation takes place. What I dont know is how to actually do something with the list, like putting it in a variable or something to get access to it and actualize the geometry of my project. So basically if there are 100 iterations I would need a way to get this list 100 times, one for each iteration with its new data. And just in case that it helps, the address of the forum were I uploaded a piece of the code: http://python-forum.org/py/viewtopic.php?p=11063#11063 And the GA project page: Genetic Algorithm Python module http://www.alextreme.org/projects/python_ai/ If you can help me please do it, this is critical for my project :( Thanks for helping Carlos ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Problems with a Class
On Sat, 13 Jan 2007 01:08:53 +0100 Carlos <[EMAIL PROTECTED]> wrote: > Hello, > > I'm just about to finish my project, but something is causing me > trouble. I need to find out how to get some information out of the > genetic algorithm that Im using. This algorithm is generating some > coordinates for a collection of objects, until now I needed only the > final result of the process. But I discovered that the final > information is not enough, I need to get some intermediate data to > actualize the positions of the objects and then evaluate those > positions. > > This is the area of the algorith that I think holds the info that I > need: > > def evolve(self, generations = 100): > > self.halt_reached = 0 > > for gen in range(generations): > > #Changed. > print 'GEN:',gen, self.entities > > self.do_mutation() > self.do_crossover() > print "Average fitness generation " + str(gen) + ": " + > str(self.avg_fitness()) > if self.debug == 1: > self.echo_fitness() > if self.halt >= 0: > max_entity = self.get_max_fitness() > fit = self.calc_fitness(max_entity) > if fit >= halt: > self.halt_reached = 1 > return [max_entity] > > The line marked as #Changed is what I changed, with this I was able > to print the info, but I'm sorry to say that I have no clue at how to > apply something like return() that would give me this self.entities > list. As you can see there is a for loop and I need the info every > time that it gets updated by the loop. > > Hopefully I'm making myself clear and the info is enough. > > Thanks for your help in advance > Carlos > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor Hi, when you call return, you return from the function so when you have something like this: def loop(): for i in range(10): return i print loop() This will print just 0. when you want to get all the numbers, you can't use return in the loop you could save them in a list or something, and after the loop return the list. def loop(): x = [] for i in range(10): x.append(i) return x print loop() this will print a list with all the numbers. I hope this is what you mean. Thomas ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Problems with a Class
Hello Again, Looks like Im getting there now. I did this inside the GA module: def update(self): return self.entities now Im putting it in my code: def my_fitness(entity): x = ga.update() print 'X', x fitness = 0.0 for i in entity: if i == 1: fitness += 1.0 return fitness This fitness fuction sets the evaluation criteria. I does the job, but there is a small problem, it returns too much information! for example in generation 1 it gives: X [[0, 0, 1, 1, 0, 1, 1, 1, 1, 0], [1, 0, 1, 0, 0, 1, 1, 0, 1, 1], [0, 1, 0, 1, 1, 1, 1, 0, 1, 0], [0, 1, 0, 0, 1, 0, 0, 1, 1, 1], [1, 0, 0, 0, 1, 1, 0, 0, 0, 0]] X [[0, 0, 1, 1, 0, 1, 1, 1, 1, 0], [1, 0, 1, 0, 0, 1, 1, 0, 1, 1], [0, 1, 0, 1, 1, 1, 1, 0, 1, 0], [0, 1, 0, 0, 1, 0, 0, 1, 1, 1], [1, 0, 0, 0, 1, 1, 0, 0, 0, 0]] X [[0, 0, 1, 1, 0, 1, 1, 1, 1, 0], [1, 0, 1, 0, 0, 1, 1, 0, 1, 1], [0, 1, 0, 1, 1, 1, 1, 0, 1, 0], [0, 1, 0, 0, 1, 0, 0, 1, 1, 1], [1, 0, 0, 0, 1, 1, 0, 0, 0, 0]] X [[0, 0, 1, 1, 0, 1, 1, 1, 1, 0], [1, 0, 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 0, 1, 1, 0, 1, 1], [0, 1, 0, 1, 1, 1, 1, 0, 1, 0], [0, 1, 0, 0, 1, 0, 0, 1, 1, 1], [0, 0, 1, 1, 0, 1, 1, 0, 0, 0]] X [[1, 0, 0, 0, 1, 1, 0, 1, 1, 0], [1, 0, 1, 0, 0, 1, 1, 0, 1, 1], [0, 1, 0, 1, 1, 1, 1, 0, 1, 0], [0, 1, 0, 0, 1, 0, 0, 1, 1, 1], [0, 0, 1, 1, 0, 1, 1, 0, 0, 0]] X [[1, 0, 0, 0, 1, 1, 0, 1, 1, 0], [1, 0, 1, 0, 0, 1, 1, 0, 1, 1], [0, 1, 0, 1, 1, 1, 1, 0, 1, 0], [0, 1, 0, 0, 1, 0, 0, 1, 1, 1], [1, 0, 0, 0, 1, 1, 0, 1, 1, 0]] X [[1, 0, 0, 0, 1, 1, 0, 1, 1, 0], [1, 0, 1, 0, 0, 1, 1, 0, 1, 1], [0, 1, 0, 1, 1, 1, 1, 0, 1, 0], [0, 1, 0, 0, 1, 0, 0, 1, 1, 1], [1, 0, 0, 0, 1, 1, 0, 1, 1,
[Tutor] lighttpd for windows
hey folks! Could someone please show me where to get lighttpd for windows xp sp2? ive tried the lighttpd site but no success thanks "shortash" ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor