Let’s say that an Algorithm is like a pie recipe.
You really want to make someone you love a good pie,to match his or hers perfect taste right?
well let’s assume you don’t really know his or hers taste…
What do you do?
Well you could go here,Ā but let’s assume that you don’t š
So…
There are two (more) ways to make the pie perfect his or hers perfect taste.
The first is to make every possible pie in the world!
on one just a tad more sugar, on the other one cherry more. there are a lot of combinations, really.
sounds a bit crazy?
Well that’s what happens when you let a computer make a pie.
OK, not always, just when the programmer tells it to do it.
This ‘try everything until it’s perfect’ is called “Brute Force Search” and sometimes it even works in a reasonable amount of time.
that’s because computers, while not naturally good chefs, can “cook” very very fast.
The other option is cooking like most people (who don’t run 5 stars restaurants) do –
You try several recipes, and ask your loved one “did you love the Fresh Strawberry Pie more than theĀ Chocolate Bourbon Walnut Pie” ?
and then, and this is where the fun starts, your change the recipe!
For example, you conclude that Strawberry is the thing, so you do two strawberry pies, with slight differences, and ask “Did you love the Fresh Strawberry Pie more than the Strawberry-Rhubarb Pie ?”
and after several of this steps, you reach the perfect (or good enough) taste! (or can’t look at pies anymore, either way, after finite amount of steps, the process ends :))
Now this kind of process is usually faster then “Brute Force Search” as you usually don’t try every possibility, for example, if the taster preferred strawberry over Chocolate you won’t try every otherĀ Chocolate flavor right? just try strawberry, right?
(by the way, you could be wrong about this, and the taster may only like one specific Chocolate pie, much more than any other kind of pie, but prefers strawberry over other less desired types of chocolate pies, it’s a problem with this process, especially with people with odd tastes, so with them you’ll probably have to settle for ‘very good’ instead of ‘perfect’, or try many combinations… :))
That method of work, in which you try something, get a score about the quality of your answer, and than retry is well it’s Trail and Error, but it’s more than that, basically you had the following steps:
* choose pies. (Random phase), this is done only once at start.
The number of pies is called the “population” number.
* taster grades pies. (Grading phase)
* Throw away low graded pies.
* Keep some high graded pies (well at least their recipes) at the side.
* Mix high graded pies (if both cherry pie and apple pie got high grade, try a cherry+apple pie!). (Both previous steps are the “Breed phase” – high graded pies breed with each other, bringing little cherry+apple pie or some other breed, lower graded pies will have low chances to breed…)
(* Taste good graded pies, because they should taste good `))
* Change a bit the high graded pies (Mutation phase), maybe change some quantities or add someĀ Brazilian nuts!
* Repeat the process (from the second step) until score == 100 (for perfect) or until score is higher than (score enough to make taster happy, yet amount of tries less than needed to make the chef angry), every repeat is a “new generation” of pies.
Not every chef will do every step, maybe some chef will use just one cake and modify it on every
“generation”, that is have aĀ population of 1, and doing just the Grading, and Mutation phases (and well maybe “keeping good recipes” phase) others, life food companies and highly patient mothers, will do some more, but all of this is what is called in Computer Science a Genetic Algorithm.
Yes, there is an entire field on how to make good pies. (ignore the ‘computer’ part, really)
Well not just pies, or even pies recipes, but all kind of recipes. and even on recipes for how to make better recipes (here a recipe called Genetic Algorithm for making better pie recipes).
I hope to discuss it some more, but not until I get some pie! :).
PS you aren’t suppose to write about Computer Science and pies without mentioning Pi but I managed! No wait…