Particle swarm optimization: Difference between revisions

Content added Content deleted
(updated task description)
(→‎{{header|J}}: simplify defn of michalewicz)
Line 81: Line 81:
GlobalBestValue: _1.91322</lang>
GlobalBestValue: _1.91322</lang>
Apply to Michalewicz Function:
Apply to Michalewicz Function:
<lang J> michalewicz =: 3 : '- +/ (sin y) * 20 ^~ sin (>: i. #y) * (*:y) % pi'
<lang J>
m0 =: 4 : '(sin (x{y)) * 20 ^~ sin (>:x)* ((x{y)^2) %pi'
michalewicz =: [: -@(+/) sin * 20 ^~ sin@(pi %~ >:@i.@# * *:) NB. tacit equivalent
michalewicz =: 3 : '-(+/ (i. #y) m0 y)'
state =: pso_init 0 0 ; (pi,pi) ; 0.3 0.3 0.3; 1000
state =: pso_init 0 0 ; (pi,pi) ; 0.3 0.3 0.3; 1000
Line 90: Line 89:
omega, phip, phig: 0.3 0.3 0.3
omega, phip, phig: 0.3 0.3 0.3
nParticles: 1000
nParticles: 1000

state =: (michalewicz pso)^:30 state
state =: (michalewicz pso)^:30 state