Příroda hledá řešení evolucí — a stejně může i počítač. Začneme s populací úplně náhodných vět (jako příklad 1) a necháme „přežít a množit se" ty nejlepší. Křížením a mutací se populace generaci po generaci přiblíží k cíli. Nature finds solutions by evolution — and so can a computer. We start with a population of completely random sentences (like example 1) and let the best ones "survive and reproduce". Through crossover and mutation the population edges toward the target generation by generation.
Co to jeWhat it is Genetický algoritmus: populace náhodných vět, která se „přežitím nejlepších" generaci po generaci přiblíží k cílové větě — aniž by ji opsala.A genetic algorithm: a population of random sentences that, by “survival of the best”, approaches a target sentence generation by generation — without copying it.
Co zkusitWhat to try Zadej cílovou větu a spusť. Začne se stovkami náhodných nesmyslů a v každé generaci nechá přežít a „rozmnožit" ty nejpodobnější (zeleně sedící písmena, pruh shody). Posuvníky mění velikost populace a míru mutace.Enter a target sentence and run it. It starts with hundreds of random gibberish strings, and each generation lets the most similar ones survive and “reproduce” (green = correct letters, bar = match). Sliders change the population size and the mutation rate.
Proč je to důležitéWhy it matters Ukazuje, jak hledat řešení, aniž ho známe — stačí umět ohodnotit, jak je dobré (fitness). Spojuje náhodu z příkladů 1–2 s evolucí směrem ke smyslu.It shows how to search for a solution without knowing it — you only need to score how good it is (fitness). It joins the randomness of examples 1–2 with evolution toward meaning.
Genetický algoritmus napodobuje přírodní výběr. Místo aby zkoušel kombinace popořadě (jako hrubá síla v příkladu 1), pracuje s celou populací řešení a v každé generaci nechá „rodit" lepší z lepších. Náhoda tu má směr — k cíli. A genetic algorithm mimics natural selection. Instead of trying combinations in order (like brute force in example 1), it works with a whole population of solutions and in each generation lets the better ones "give birth" to even better ones. Here randomness has a direction — toward the target.
Každé větě dáme známku — kolik písmen má správně. To je jediné, co algoritmus o cíli ví. Lepší známka = větší šance na potomky. We grade each sentence — how many letters it has right. That's the only thing the algorithm knows about the target. A better grade = a higher chance of offspring.
Vybereme dva zdatné „rodiče" a jejich věty zkřížíme — část písmen od jednoho, část od druhého. Vznikne potomek, který kombinuje to dobré z obou. We pick two fit "parents" and cross over their sentences — some letters from one, some from the other. The child combines the good bits of both.
Občas se náhodně změní písmeno. Drží to rozmanitost a pomáhá objevit, co v populaci ještě není. Moc mutace = chaos, málo = uváznutí. Now and then a letter changes at random. This keeps diversity and helps discover what isn't yet in the population. Too much mutation = chaos, too little = getting stuck.
Hodí se tam, kde neumíme spočítat řešení přímo: návrh tvarů, herní strategie, ladění parametrů. Vždy, když umíme jen ohodnotit, jak dobré řešení je. It's useful where we can't compute the solution directly: shape design, game strategies, parameter tuning. Whenever all we can do is score how good a solution is.