Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele Challenge: Implement Particle Swarm Optimization | Swarm-Based Algorithms
Bio-Inspired Algorithms

bookChallenge: Implement Particle Swarm Optimization

Tehtävä

Swipe to start coding

You are asked to implement the core update logic for a Particle Swarm Optimization (PSO) algorithm. The goal is to find the minimum of the function f(x) = x² + 5 * sin(x) on the interval [-10, 10].

All the parameters (like inertia w, cognitive c1, and social c2) and initial lists (positions, velocities, pbest_positions, pbest_values, gbest_position, gbest_value) are already set up for you.

Your task is to fill in the main iterative process:

  1. Inside the inner for loop (for each particle i), you must first update the particle's velocity. Use the full PSO velocity update equation: w * velocities[i] + c1 * r1 * (pbest_positions[i] - positions[i]) + c2 * r2 * (gbest_position - positions[i]).
  2. Update the particle's position by adding its new velocities[i] to positions[i].
  3. After calculating the new value at positions[i], check if this new value is better than the particle's personal best (pbest_values[i]). If it is, you must update both pbest_positions[i] and pbest_values[i].
  4. After the inner loop (which updates all particles), check if the new best personal value (which you find and store in min_value) is better than the current global best (gbest_value). If it is, update both gbest_value and gbest_position.

Ratkaisu

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 3. Luku 4
single

single

Kysy tekoälyä

expand

Kysy tekoälyä

ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

Suggested prompts:

Can you explain this in simpler terms?

What are some examples related to this topic?

How does this information apply to real-life situations?

close

Awesome!

Completion rate improved to 6.25

bookChallenge: Implement Particle Swarm Optimization

Pyyhkäise näyttääksesi valikon

Tehtävä

Swipe to start coding

You are asked to implement the core update logic for a Particle Swarm Optimization (PSO) algorithm. The goal is to find the minimum of the function f(x) = x² + 5 * sin(x) on the interval [-10, 10].

All the parameters (like inertia w, cognitive c1, and social c2) and initial lists (positions, velocities, pbest_positions, pbest_values, gbest_position, gbest_value) are already set up for you.

Your task is to fill in the main iterative process:

  1. Inside the inner for loop (for each particle i), you must first update the particle's velocity. Use the full PSO velocity update equation: w * velocities[i] + c1 * r1 * (pbest_positions[i] - positions[i]) + c2 * r2 * (gbest_position - positions[i]).
  2. Update the particle's position by adding its new velocities[i] to positions[i].
  3. After calculating the new value at positions[i], check if this new value is better than the particle's personal best (pbest_values[i]). If it is, you must update both pbest_positions[i] and pbest_values[i].
  4. After the inner loop (which updates all particles), check if the new best personal value (which you find and store in min_value) is better than the current global best (gbest_value). If it is, update both gbest_value and gbest_position.

Ratkaisu

Switch to desktopVaihda työpöytään todellista harjoitusta vartenJatka siitä, missä olet käyttämällä jotakin alla olevista vaihtoehdoista
Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 3. Luku 4
single

single

some-alt