Talk:Evolutionary algorithm: Difference between revisions

no edit summary
No edit summary
Line 10:
# There is an end-point to the evolution (only really needed to make it into an algorithm rather than an ongoing process).
These issues can be technically resolved by making only the fitness function know what the target is and having the algorithm only terminate once perfect fitness is achieved (i.e., when no possible mutation will improve things). At that point, the ''scientific'' issues are moot, and the non-scientific ones dispute whether the algorithm should even exist, which is out of scope for this site anyway. As a plus side, it also makes the presentation of the algorithm more aesthetically pleasing as it removes the assumption that there is only one possible maxima (informal testing using a fitness function that uses the max of individual fitness functions as in this task, except with different target strings, indicates that this works quite well). —[[User:Dkf|Donal Fellows]] 10:12, 9 October 2009 (UTC)
 
== Tacit J solution ==
I was wanting to add a purely tacit (arguments not explicitly referenced) J solution. I came up with the following two options and am seeking opinions on which one is "better".<br>
'''VERSION ONE'''<br>
Uses a user-defined adverb and conjunction that help keep the rest of the code tidy.
<lang>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 =: adverb def '(m >: $ ?@$ 0:)`(,: create)}'
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</lang>
 
'''VERSION TWO'''<br>
Only uses verbs (functions) which are can be easier to understand/parse, especially to start with.
 
<lang>CHARSET=: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ '
NPROG=: 100 NB. number of progeny (C)
 
create =: (?@$&$ { ])&CHARSET NB. get random list from charset of same length as y
fitness =: +/@:~:"1
copy =: # ,:
mrate =: %@:# NB. mutation rate
mutate =: (0&{:: >: $@(1&{::) ?@$ 0:)`((,: create)@(1&{::))}@;
select =: ] {~ (i. <./)@:fitness NB. select fittest member of population
 
nextgen =: ] , [ select {:@] , mrate@[ mutate NPROG copy {:@]
notperfect =: (0 < fitness) {:
 
evolve=: nextgen ^: notperfect ^:_ ,:@create</lang>
--[[User:Tikkanz|Tikkanz]] 00:53, 4 November 2009 (UTC)
892

edits