Clonal Selection Algorithm
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.
123456789101112131415161718192021222324252627282930313233import 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])])
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.
Thanks for your feedback!
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
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
Clonal Selection Algorithm
Swipe to show menu
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.
123456789101112131415161718192021222324252627282930313233import 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])])
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.
Thanks for your feedback!