Live data from Hacker News

A Story to Explain Genetic Algorithms

jake.simvla.com

11–20 of 35 posts

Re: A Story to Explain Genetic Algorithms

#11

Neat little story, despite the grammar and capitalization. Is it common to use _ as an index variable? Edit: for _ in range(4):

I've seen it before, but it's a little jarring. Not sure what's wrong with just using i.

It says explicitly that you don't care about that value. If you used i, for example, you wouldn't know whether the loop depended on the iteration number.

Re: A Story to Explain Genetic Algorithms

#12

> Then our Charles simply had to figure out how Mrs Kipling scored the cakes and he could genetically evolve the best cake! "And then a miracle happens." Isn't the fitness function the "key ingredient?" (It's in the source code, but not in the text for a reason.) Still a good explanation of the rest.

One of the things that optimising algorithms are really good at doing is demonstrating that your fitness function is incompletely specified.

Re: A Story to Explain Genetic Algorithms

#13

Neat little story, despite the grammar and capitalization. Is it common to use _ as an index variable? Edit: for _ in range(4):

Common in Lua, Ruby, Python. In fact, ruby gives _ a minor amount of special meaning to make it more convenient as a throw-away variable, e.g. it can be specified multiple times in an argument list without an error and generates no warning if left unused.

Re: A Story to Explain Genetic Algorithms

#14

Neat little story, despite the grammar and capitalization. Is it common to use _ as an index variable? Edit: for _ in range(4):

It's better to use two underscores __ to represent throwaway variables, because _ has a meaning in Python: it returns the last output.

Re: A Story to Explain Genetic Algorithms

#18

> Then our Charles simply had to figure out how Mrs Kipling scored the cakes and he could genetically evolve the best cake! "And then a miracle happens." Isn't the fitness function the "key ingredient?" (It's in the source code, but not in the text for a reason.) Still a good explanation of the rest.

> "And then a miracle happens."

One of the favorite quotes of my graduate advisor, thanks for the chuckle :)

For those who are unfamiliar with the reference:

http://star.psy.ohio-state.edu/coglab/Miracle.html (mirror image: http://i.imgur.com/k7gm70t.jpg)

Re: A Story to Explain Genetic Algorithms

#19
post #11

Earlier quoted context omitted.

I've seen it before, but it's a little jarring. Not sure what's wrong with just using i.

It says explicitly that you don't care about that value. If you used i, for example, you wouldn't know whether the loop depended on the iteration number.

Yeah, I get it. And that's a useful thing to do, I guess. It just seems a little... unpythonic.

Re: A Story to Explain Genetic Algorithms

#20
post #14

Neat little story, despite the grammar and capitalization. Is it common to use _ as an index variable? Edit: for _ in range(4):

It's better to use two underscores __ to represent throwaway variables, because _ has a meaning in Python: it returns the last output.

True, but only in the REPL.

For example try to run the following script (not from the REPL):

  _ = 12
  print _
  42 * 42
  print _
Post reply on HN