Particle swarm optimization: Difference between revisions
→{{header|J}}: Use printf for status display
(→{{header|J}}: define pso as an adverb) |
(→{{header|J}}: Use printf for status display) |
||
Line 15:
</p>
=={{header|J}}==
<lang J>
pso_init =: verb define
'Min Max parameters nParticles' =. y
Range =. Max - Min
nDims =. #Min
Line 32 ⟶ 33:
NB. previous state
'iter gbpos gbval Min Max parameters pos vel bpos0 bval' =
NB. evaluate
Line 75 ⟶ 76:
state =: pso_init _1.5 _3 ; 4 4 ; 0 0.6 0.3; 100
Min: _1.5 _3
Max: 4 4
nParticles: 100
▲│omega, phip, phig│0 0.6 0.3│
state =: (mccormick pso)^:40 state
'Iteration: %j\nGlobalBestPosition: %j\nGlobalBestValue: %j\n' printf 3{. state
Iteration: 40
GlobalBestPosition: _0.547399 _1.54698
GlobalBestValue: _1.91322</lang>
=={{header|ooRexx}}==
|