Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
14
Task/Evolutionary-algorithm/J/evolutionary-algorithm-1.j
Normal file
14
Task/Evolutionary-algorithm/J/evolutionary-algorithm-1.j
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
CHARSET=: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ '
|
||||
NPROG=: 100 NB. number of progeny (C)
|
||||
MRATE=: 0.05 NB. mutation rate
|
||||
|
||||
create =: (?@$&$ { ])&CHARSET NB. creates random list from charset of same shape as y
|
||||
fitness =: +/@:~:"1
|
||||
copy =: # ,:
|
||||
mutate =: &(>: $ ?@$ 0:)(`(,: create))} NB. adverb
|
||||
select =: ] {~ (i. <./)@:fitness NB. select fittest member of population
|
||||
|
||||
nextgen =: select ] , [: MRATE mutate NPROG copy ]
|
||||
while =: conjunction def '(] , (u {:))^:(v {:)^:_ ,:'
|
||||
|
||||
evolve=: nextgen while (0 < fitness) create
|
||||
Loading…
Add table
Add a link
Reference in a new issue