Crafting Fitness Functions

Get to know about fitness functions in detail.

Objectives of fitness functions

In the previous few lessons, we explored the importance of evaluation through the context of a modified knapsack problem. While the problem shows the importance of crafting a good fitness function, we learned only one way to evaluate a specific type of problem. Countless problems exist, each requiring unique evaluation tools. Unfortunately, we can’t generalize one fitness function to all problems. We need to fully understand what fitness functions aim to accomplish.

Understanding fitness

Recall from the lesson Role of Exploration and Exploitation in Genetic Algorithms, the problem of being lost in the woods. Now imagine that some of the trees are marked, indicating how close we are to escaping the woods. The markings on the trees show the value of your current position; they tell you how to navigate the woods and where to go next. Without this information, we’d likely never escape.

Fitness is, in essence, the same as the markings on the trees. Specifically, fitness is the value assigned to a particular chromosome based on the criteria defined in the fitness function. Consider this: you’re lost in the woods again, only this time, the trees aren’t marked. Instead, you have a guide who tells you how close to civilization you are after every step. In this example, the guide acts as your fitness function, providing you with information based on your current position. This information is the fitness of your current position and tells you how close you are to making it back to civilization.

Get hands-on with 1200+ tech skills courses.