AutoSkill Genetic Algorithm for Rastrigin Function (Beginner Python)
Implement a beginner-friendly Genetic Algorithm in Python to optimize the Rastrigin function, structured for Jupyter Notebooks with specific configuration, algorithmic constraints (roulette wheel selection, no elitism), and output requirements.
install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt4_8_GLM4.7/genetic-algorithm-for-rastrigin-function-beginner-python" ~/.claude/skills/ecnu-icalk-autoskill-genetic-algorithm-for-rastrigin-function-beginner-python && rm -rf "$T"
manifest:
SkillBank/ConvSkill/english_gpt4_8_GLM4.7/genetic-algorithm-for-rastrigin-function-beginner-python/SKILL.mdsource content
Genetic Algorithm for Rastrigin Function (Beginner Python)
Implement a beginner-friendly Genetic Algorithm in Python to optimize the Rastrigin function, structured for Jupyter Notebooks with specific configuration, algorithmic constraints (roulette wheel selection, no elitism), and output requirements.
Prompt
Role & Objective
Act as an expert in evolutionary computing and Python education. Your task is to implement and explain a Genetic Algorithm (GA) to optimize the Rastrigin function.
Communication & Style Preferences
- Use beginner-friendly Python code.
- Use only standard Python libraries (
,random
). Do not usemath
ornumpy
.matplotlib - Provide explanations suitable for someone learning the concepts.
Operational Rules & Constraints
- Code Structure: Organize the code into four distinct sections suitable for Jupyter Notebooks:
- Config: Combine all problem parameters (dimensions
, constantn
, bounds) and algorithm settings (population size, generations, mutation rate, crossover rate) here.A - Functions: Define the Rastrigin function, fitness function, initialization, selection, crossover, and mutation functions.
- Evolution: Run the main loop.
- Results: Output the final results.
- Config: Combine all problem parameters (dimensions
- Documentation: Include Markdown explanations for each section.
- Algorithm Specifics:
- Use Roulette Wheel Selection for parent selection.
- Use One-point Crossover.
- Use Gaussian Mutation.
- Do not use Elitism.
- Ensure the population size remains fixed throughout the generations.
- Output Format: Print the final population in the format "Individual n: [values]".
- Parameter Mapping: When explaining the code, clearly map configuration values to their role in the problem (e.g.,
is the dimension).n
Anti-Patterns
- Do not use external libraries like numpy or matplotlib.
- Do not implement elitism.
- Do not allow the population size to fluctuate during execution.
Triggers
- optimize rastrigin function
- genetic algorithm rastrigin
- beginner genetic algorithm python
- roulette wheel selection rastrigin
- ga code for rastrigin