liveBook · Manning

Individual

As explained in Grokking AI Algorithms, Second Edition

An individual is one candidate solution represented as a member of an evolutionary algorithm's population.

An individual is one candidate solution in an evolutionary algorithm’s population. It is represented by a chromosome, a collection of genes that encodes a possible solution; in a knapsack problem, each binary gene indicates whether an item is included. section 5.22 section 4.6

A practical individual moves through the algorithm like this:

  • Create it with randomly chosen genes, while ensuring that the encoded solution is valid or repairing violations. section 4.6
  • Measure its fitness, which indicates how well the solution performs against the problem’s objective and constraints. section 4.7
  • Give fitter individuals a greater chance of becoming parents, while still allowing other individuals to contribute traits. section 4.8
  • Retain or replace it according to the population model: steady-state models replace part of the population, while generational models replace all of it. section 4.9

A knapsack individual

Suppose a chromosome contains one binary gene per item: 1 means “pack this item,” and 0 means “leave it out.” The algorithm adds the weights and values for every gene set to 1. If the total weight exceeds the limit, the individual receives a fitness score of 0; otherwise, its fitness is the total item value. A high-value, valid individual is therefore more likely to help produce the next generation. section 4.6 section 4.7 section 4.8

def calculate_individual_fitness(individual, maximum_weight):
    total_individual_weight = 0
    total_individual_value = 0
    for gene_index in range(len(individual)): #A
        gene_switch = individual[gene_index]
        if gene_switch == '1': #B
            total_individual_weight
            ➥+= knapsack_items[gene_index][KNAPSACK_ITEM_WEIGHT_INDEX] #C
            total_individual_value
            ➥+= knapsack_items[gene_index][KNAPSACK_ITEM_VALUE_INDEX] #C
    if total_individual_weight > maximum_weight: #D
        return 0
    return total_individual_value #E

Inspect the fitness calculation to see how an individual’s genes become weight, value, validity, and final score. section 4.7

How Grokking AI Algorithms, Second Edition covers it

How deep it goes
Defines individuals, creates them, scores them, and selects them as parents, while deferring detailed offspring reproduction.
Examples
Uses binary knapsack chromosomes, validity checks, repair functions, fitness scores, roulette-wheel selection, and population diagrams.
What you can do after
Build it from scratch by encoding candidate solutions, validating them, and calculating fitness for evolutionary selection.
How it connects
Connects individuals to chromosomes, genes, populations, fitness functions, objective functions, selection, and population models.

Also explained in

Compare how 3 books explain individual →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking AI Algorithms, Second Edition. The section links point to the parts of the book it draws on.