Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Clonal Selection Algorithm | Artificial Immune Systems
Bio-Inspired Algorithms

bookClonal Selection Algorithm

Note
Definition

The clonal selection algorithm is inspired by the way biological immune systems respond to antigens.

When your immune system detects an invader, it selects immune cells with the highest affinity, clones them, and introduces mutations to create diversity. This process, called affinity maturation, enables adaptation and memory.

The clonal selection algorithm uses these ideas for optimization:

  • Evaluate candidate solutions for their affinity (solution quality);
  • Clone those with higher affinity more often;
  • Mutate clones to generate new variations.

This process explores the solution space and focuses on promising areas.

123456789101112131415161718192021222324252627282930313233
import numpy as np # Objective function: maximize f(x) = -x**2 + 5 def affinity(x): return -x**2 + 5 # Initial candidate solutions population = np.random.uniform(-5, 5, size=10) # --- Main Clonal Selection Loop --- for generation in range(5): # Evaluate affinities affinities = np.array([affinity(ind) for ind in population]) # Select top candidates num_selected = 4 selected_indices = affinities.argsort()[-num_selected:] selected = population[selected_indices] # Clone proportionally to affinity num_clones = [int(5 * (affinity(ind) - min(affinities)) / (max(affinities) - min(affinities) + 1e-6)) + 1 for ind in selected] clones = np.concatenate([[ind] * n for ind, n in zip(selected, num_clones)]) # Mutation: add small noise mutation_strength = 0.1 mutated_clones = clones + np.random.normal(0, mutation_strength, size=clones.shape) # Form new population population = np.concatenate([selected, mutated_clones]) # Keep population size fixed population = np.random.choice(population, size=10, replace=False) print("Best solution:", population[np.argmax([affinity(ind) for ind in population])])
copy

Diversity and Adaptation in Clonal Selection

The clonal selection algorithm maintains diversity by mutating clones, generating new candidate solutions and avoiding premature convergence. Through repeated selection, cloning, and mutationβ€”known as affinity maturationβ€”the population adapts over time. This process balances exploitation of high-quality solutions with exploration of new possibilities, making the algorithm effective for complex optimization tasks.

question mark

Which statements about the clonal selection algorithm are correct?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 4. ChapterΒ 3

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Suggested prompts:

Can you explain how the clonal selection algorithm differs from genetic algorithms?

What are some real-world applications of the clonal selection algorithm?

Can you walk me through the code and explain each step in detail?

Awesome!

Completion rate improved to 6.25

bookClonal Selection Algorithm

Swipe to show menu

Note
Definition

The clonal selection algorithm is inspired by the way biological immune systems respond to antigens.

When your immune system detects an invader, it selects immune cells with the highest affinity, clones them, and introduces mutations to create diversity. This process, called affinity maturation, enables adaptation and memory.

The clonal selection algorithm uses these ideas for optimization:

  • Evaluate candidate solutions for their affinity (solution quality);
  • Clone those with higher affinity more often;
  • Mutate clones to generate new variations.

This process explores the solution space and focuses on promising areas.

123456789101112131415161718192021222324252627282930313233
import numpy as np # Objective function: maximize f(x) = -x**2 + 5 def affinity(x): return -x**2 + 5 # Initial candidate solutions population = np.random.uniform(-5, 5, size=10) # --- Main Clonal Selection Loop --- for generation in range(5): # Evaluate affinities affinities = np.array([affinity(ind) for ind in population]) # Select top candidates num_selected = 4 selected_indices = affinities.argsort()[-num_selected:] selected = population[selected_indices] # Clone proportionally to affinity num_clones = [int(5 * (affinity(ind) - min(affinities)) / (max(affinities) - min(affinities) + 1e-6)) + 1 for ind in selected] clones = np.concatenate([[ind] * n for ind, n in zip(selected, num_clones)]) # Mutation: add small noise mutation_strength = 0.1 mutated_clones = clones + np.random.normal(0, mutation_strength, size=clones.shape) # Form new population population = np.concatenate([selected, mutated_clones]) # Keep population size fixed population = np.random.choice(population, size=10, replace=False) print("Best solution:", population[np.argmax([affinity(ind) for ind in population])])
copy

Diversity and Adaptation in Clonal Selection

The clonal selection algorithm maintains diversity by mutating clones, generating new candidate solutions and avoiding premature convergence. Through repeated selection, cloning, and mutationβ€”known as affinity maturationβ€”the population adapts over time. This process balances exploitation of high-quality solutions with exploration of new possibilities, making the algorithm effective for complex optimization tasks.

question mark

Which statements about the clonal selection algorithm are correct?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 4. ChapterΒ 3
some-alt