Live data from Hacker News

Introduction to genetic algorithms (example in Javascript)

burakkanber.com

11–20 of 22 posts

Re: Introduction to genetic algorithms (example in Javascript)

#11
post #8

I was happy to see that you actually were doing genetic algorithms (usually people incorrectly refer to simpler evolutionary algorithms as "genetic", which is a pet peeve of mine). A few points of feedback though: Typically, what you are calling "genes" are called "chromosomes". Calling them "genes" is confusing because genes typically refer to smaller hereditary units (generally an individual bit on the chromosome).…

> ...an algorithm with no crossover will do usually pretty well, but will be prone to getting stuck in local optima. This is because it is possible to arrive at a solution where no incremental change can improve the fitness. False. There is no theoretical or comprehensive empirical study I've ever seen to suggest this is the case. At best, in some scenarios (e.g., multiplex, ordered subset selection) crossover will h…

Bingo. So many genetic/evolutionary algorithms assume you need a large population with crossover to avoid these supposed 'local minima'.

Very often, the most efficient evolutionary search algorithm involves a population of one (or two, depending how you count them): generate a mutation, compare it to the current best. If it's worse, throw it away; if it's better or the same, keep it and throw the original away. Rinse and repeat.

Search for "neutral networks" for more information about research into determining the "shape" of the fitness landscape. (Unfortunately, Google throws in plenty of search results about neural networks and network neutrality).

Re: Introduction to genetic algorithms (example in Javascript)

#13
post #8

Earlier quoted context omitted.

> ...an algorithm with no crossover will do usually pretty well, but will be prone to getting stuck in local optima. This is because it is possible to arrive at a solution where no incremental change can improve the fitness. False. There is no theoretical or comprehensive empirical study I've ever seen to suggest this is the case. At best, in some scenarios (e.g., multiplex, ordered subset selection) crossover will h…

Bingo. So many genetic/evolutionary algorithms assume you need a large population with crossover to avoid these supposed 'local minima'. Very often, the most efficient evolutionary search algorithm involves a population of one (or two, depending how you count them): generate a mutation, compare it to the current best. If it's worse, throw it away; if it's better or the same, keep it and throw the original away. Rinse…

There's a bit of goofiness about crossover in this thread.

So far as I know, since its inception in the 1970s, crossover has never been thought of as a mechanism for "avoiding local minima". Indeed, the early trend of crossover without mutation was what resulted in studies in so-called "premature convergence," where the population would converge to a single genome and be permanently locked in a local optimum.

Rather, crossover is a procedure for spreading good subsolutions (so-called "building blocks") rapidly through the population. This is effectively projecting the search space into many smaller spaces, so has the potential of searching much faster if -- and this is a big if -- the problem in question has very low dependance among its parameters. In the GA world, this is known as parameter "linkage" or "epistasis". Other techniques do something similar: for example, EDAs or coevolution or ant colony optimization all perform a related projection and likewise make a related assumption of low dependance.

> Very often, the most efficient evolutionary search algorithm involves a population of one (or two, depending how you count them): generate a mutation, compare it to the current best.

Not really true. There are lots of EAs which are touted as "the most efficient". A few, like CMA-ES, are by and large mutation-only algorithms. But others, like cooperative coevolution or hBOA (and other EDAs), are essentially extremes in crossover-like mixing.

Re: Introduction to genetic algorithms (example in Javascript)

#14
post #9
post #2

I would love to solicit suggestions for other ML topics and languages to cover as part of this series (please don't suggest "SVMs in brainfuck"). Let me know what you think!

How about an implementation of Gene Expression Programming ( http://gene-expression-programming.com/ ) in javascript?

If you're going that route, I suggest instead looking at Grammatical Evolution, which is much more popular and does a very closely related thing. Or heck, stick with plain Genetic Programming (GP).

It'd only be a toy though. Because of the high number of evaluations used by these kinds of methods, and the cost of a single evaluation, most serious work is done in engines based on faster languages, notably Java, C, or, or C++.

Re: Introduction to genetic algorithms (example in Javascript)

#15
post #8

I was happy to see that you actually were doing genetic algorithms (usually people incorrectly refer to simpler evolutionary algorithms as "genetic", which is a pet peeve of mine). A few points of feedback though: Typically, what you are calling "genes" are called "chromosomes". Calling them "genes" is confusing because genes typically refer to smaller hereditary units (generally an individual bit on the chromosome).…

> ...an algorithm with no crossover will do usually pretty well, but will be prone to getting stuck in local optima. This is because it is possible to arrive at a solution where no incremental change can improve the fitness. False. There is no theoretical or comprehensive empirical study I've ever seen to suggest this is the case. At best, in some scenarios (e.g., multiplex, ordered subset selection) crossover will h…

>False. There is no theoretical or comprehensive empirical study I've ever seen to suggest this is the case.

It is absolutely the case. What is not established is whether or not crossover will actually help. My main point was that mutation is not there to escape local optima, although I should have been clearer about the efficacy of crossover for that purpose.

>Also false. I'll especially take note that this is not the case if you're using a less-than-naive EA.

Yes, for specific classes of problem, you can converge on a global optimum. In the general case, there is no way to ensure that you will get to a global optimum.

>You start with a bunch of random bit strings. IF you have 1s in all indexes somewhere in the population, it's possible (though unlikely) that the algorithm will find the optimal answer.

Yes that's why I said it basically won't optimize at all. Random guess and check might arrive at an optimum answer too, but that is only "optimizing" in a very pedantic sense.

Re: Introduction to genetic algorithms (example in Javascript)

#16
post #8

Earlier quoted context omitted.

> ...an algorithm with no crossover will do usually pretty well, but will be prone to getting stuck in local optima. This is because it is possible to arrive at a solution where no incremental change can improve the fitness. False. There is no theoretical or comprehensive empirical study I've ever seen to suggest this is the case. At best, in some scenarios (e.g., multiplex, ordered subset selection) crossover will h…

>False. There is no theoretical or comprehensive empirical study I've ever seen to suggest this is the case. It is absolutely the case. What is not established is whether or not crossover will actually help. My main point was that mutation is not there to escape local optima, although I should have been clearer about the efficacy of crossover for that purpose. >Also false. I'll especially take note that this is not t…

[deleted]

Re: Introduction to genetic algorithms (example in Javascript)

#17
post #8

Earlier quoted context omitted.

> ...an algorithm with no crossover will do usually pretty well, but will be prone to getting stuck in local optima. This is because it is possible to arrive at a solution where no incremental change can improve the fitness. False. There is no theoretical or comprehensive empirical study I've ever seen to suggest this is the case. At best, in some scenarios (e.g., multiplex, ordered subset selection) crossover will h…

>False. There is no theoretical or comprehensive empirical study I've ever seen to suggest this is the case. It is absolutely the case. What is not established is whether or not crossover will actually help. My main point was that mutation is not there to escape local optima, although I should have been clearer about the efficacy of crossover for that purpose. >Also false. I'll especially take note that this is not t…

> My main point was that mutation is not there to escape local optima, although I should have been clearer about the efficacy of crossover for that purpose.

Mutation is absolutely there for the primary purpose of escaping local optima. If mutation's job was only to climb the gradient, then you would just use a much more efficient gradient ascent method. By having random mutation, you are effectively saying you want to stay in the known-good region most of the time, but occasionally explore a new area even if it goes against the perceived gradient.

Re: Introduction to genetic algorithms (example in Javascript)

#18

Earlier quoted context omitted.

Bingo. So many genetic/evolutionary algorithms assume you need a large population with crossover to avoid these supposed 'local minima'. Very often, the most efficient evolutionary search algorithm involves a population of one (or two, depending how you count them): generate a mutation, compare it to the current best. If it's worse, throw it away; if it's better or the same, keep it and throw the original away. Rinse…

There's a bit of goofiness about crossover in this thread. So far as I know, since its inception in the 1970s, crossover has never been thought of as a mechanism for "avoiding local minima". Indeed, the early trend of crossover without mutation was what resulted in studies in so-called "premature convergence," where the population would converge to a single genome and be permanently locked in a local optimum. Rather,…

Just nitpicking here: how is cooperative coevolution a crossover-dependent approach? Are you referring to some specific algorithm?

Re: Introduction to genetic algorithms (example in Javascript)

#19
post #18

Earlier quoted context omitted.

There's a bit of goofiness about crossover in this thread. So far as I know, since its inception in the 1970s, crossover has never been thought of as a mechanism for "avoiding local minima". Indeed, the early trend of crossover without mutation was what resulted in studies in so-called "premature convergence," where the population would converge to a single genome and be permanently locked in a local optimum. Rather,…

Just nitpicking here: how is cooperative coevolution a crossover-dependent approach? Are you referring to some specific algorithm?

> how is cooperative coevolution a crossover-dependent approach?

It's not. What I meant was that CCEAs and univariate EDAs (and most forms of ACO) make the same basic linkage assumption inherent in crossover, indeed to even more of an extreme: that you can assemble individuals from bits and pieces scattered about the space without any dependence issues.

Re: Introduction to genetic algorithms (example in Javascript)

#20
This is wonderful! Exactly what I was looking for, a practical introduction to machine learning using real-world code. Thank you so much!

I only have one request: Instead of switching to PHP for the next GA exercise, can you please keep everything in Javascript? Just because JS is a more widely used and general-purpose language, which means those of us who don't use PHP can still enjoy it :) Thank you!

Post reply on HN