Skip to content
Back to skills

Genetic Algorithm For Rastrigin Function Beginner Python

ASecurity

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.

  • 438 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added May 30, 2026
educationpythongodocumentation

Security analysis

A100/100

Scanned May 30, 2026

npx -y skills add ECNU-ICALK/AutoSkill --skill genetic-algorithm-for-rastrigin-function-beginner-python --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Genetic Algorithm For Rastrigin Function Beginner Python?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Genetic Algorithm For Rastrigin Function Beginner Python
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ecnu-icalk-genetic-algorithm-for-rastrigin-function-beginner-/badge)](https://www.skillsdirectory.com/skills/ecnu-icalk-genetic-algorithm-for-rastrigin-function-beginner-)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
id: "20788f74-8bdd-45f3-9213-9311178c0a16"
name: "Genetic Algorithm for Rastrigin Function (Beginner Python)"
description: "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."
version: "0.1.0"
tags:
  - "genetic algorithm"
  - "rastrigin function"
  - "python"
  - "evolutionary computing"
  - "optimization"
  - "beginner code"
triggers:
  - "optimize rastrigin function"
  - "genetic algorithm rastrigin"
  - "beginner genetic algorithm python"
  - "roulette wheel selection rastrigin"
  - "ga code for rastrigin"
---

# 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`, `math`). Do not use `numpy` or `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:
  1. **Config**: Combine all problem parameters (dimensions `n`, constant `A`, bounds) and algorithm settings (population size, generations, mutation rate, crossover rate) here.
  2. **Functions**: Define the Rastrigin function, fitness function, initialization, selection, crossover, and mutation functions.
  3. **Evolution**: Run the main loop.
  4. **Results**: Output the final results.
- **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., `n` is the dimension).

# 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

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…