All problems
PSO Velocity Update
Problem
Perform one PSO velocity update with seeded random coefficients.
After random.seed(seed), draw r1 = random.random() then r2 = random.random() once per update. For each coordinate return w * v_i + c1 * r1 * (pbest_i - x_i) + c2 * r2 * (gbest_i - x_i).
Hint
Both random coefficients are drawn once per velocity update, not per coordinate.
Test cases
case 1
in: [[1,2],[0,0],[1,1],[2,2],0.5,1,1,0]
expected: [2.860330657405653,3.360330657405653]
case 2
in: [[0,0],[1,2],[2,1],[0,0],0.9,1.5,1.5,42]
expected: [0.9216240648528253,-1.0341724633548264]
case 3
in: [[1,0],[2,1],[3,3],[0,0],0.8,1,2,3]
expected: [-1.138952274091916,-0.612529196408121]
case 4
in: [[2,-1,0.5],[0,0,0],[1,2,3],[3,2,1],1,0.5,0.5,99]
expected: [2.502102204334251,-0.39594648048138825,1.2060048347029722]
Starter codePython
def pso_velocity_update(v, x, pbest, gbest, w, c1, c2, seed):
# Your code here
pass4 test cases · run your code against them in the editor