Hi Skip Cave,
are you still there and interested? :-)
After some more experimenting I think this will do the job:
fitness =:+/^:2 @:*:@(-/~)
mutO=: 3 :0
'a b'=. y
((j{b)i} a),:(a{~i=.?n) (j=.?n=.#a)}b
)
disO=: 4 :0
bc=. # y
o=. fitness ((,>:)<.av) #~(,~bc&-) bc * (-<.) x: av=.bc%~+/,y
ws=.x $ ,: b1=.y
while. 1 do.
if. o= fitness +/"1 b1 do. break. end.
ws=. ws mutO@:{`[`]}"2~ 2?bc
b1=. {. (/: fitness@:(+/"1)"2) ws,b1
ws=.x $ ,:b1
end.
b1
)
Remarks/questions
=================
- only use if 0 = buckets |&# weights
- for M it looks like it always converges to the desired distribution
- always mutate is the best way to do?
- use small population sizes?
- the following tests show executing time could very quite a bit
Many instances test to get an idea of the average execution time:
==================================================================
M=:?.200#1000
bc=: 10 NB. # buckets
Goal to achieve:
]o=. fitness ((,>:)<.av) #~(,~bc&-) bc * (-<.) x: av=.bc%~+/1+M
32
fitness@:(+/"1)"2 R [smoutput (6!:2) 'R=.10 disO"2 MM' [ MM=. 20$ ,:10 20
$1 + M
37.8633
32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32
fitness@:(+/"1)"2 R [smoutput (6!:2) 'R=.10 disO"2 MM' [ MM=. 20$ ,:10 20
$1 + M
45.5536
32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32
fitness@:(+/"1)"2 R [smoutput (6!:2) 'R=.10&disO"2 MM' [ MM=. 20$ ,:10 20
$1 + M
32.6474
32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32
--
Met vriendelijke groet,
=@@i
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm