Paste: use combinators.random
Author: | jon |
Mode: | factor |
Date: | Fri, 7 Jan 2011 20:03:39 |
Plain Text |
diff --git a/hello-ga/hello-ga.factor b/hello-ga/hello-ga.factor
index 268b6ab..508d66b 100644
--- a/hello-ga/hello-ga.factor
+++ b/hello-ga/hello-ga.factor
@@ -2,7 +2,7 @@
USING: fry kernel make math math.order math.ranges random
-sequences ;
+sequences combinators.random ;
IN: hello-ga
@@ -22,9 +22,6 @@ CONSTANT: POPULATION 400
CONSTANT: CHILDREN-PROBABILITY 0.9
-: children? ( -- ? )
- 0.0 1.0 uniform-random-float CHILDREN-PROBABILITY < ;
-
: head/tail ( seq1 seq2 n -- head1 tail2 )
[ head ] [ tail ] bi-curry bi* ;
@@ -37,9 +34,6 @@ CONSTANT: CHILDREN-PROBABILITY 0.9
CONSTANT: MUTATION-PROBABILITY 0.2
-: mutation? ( -- ? )
- 0.0 1.0 uniform-random-float MUTATION-PROBABILITY < ;
-
: mutate ( chromosome -- chromosome' )
dup length random over [ -5 5 [a,b] random + ] change-nth ;
@@ -53,8 +47,8 @@ CONSTANT: MUTATION-PROBABILITY 0.2
dup [ tournament ] bi@ ;
: (1generation) ( seq -- child1 child2 )
- parents children? [ children ] when
- mutation? [ [ mutate ] bi@ ] when ;
+ parents CHILDREN-PROBABILITY [ children ] whenp
+ MUTATION-PROBABILITY [ [ mutate ] bi@ ] whenp ;
: 1generation ( seq -- seq' )
[ length 2 / ] keep
New Annotation