markov-chains: initial implementation.

master
John Benediktsson 2020-02-13 12:56:09 -08:00
parent 5cb26d546f
commit bcecb3b088
3 changed files with 23 additions and 0 deletions

View File

@ -0,0 +1 @@
John Benediktsson

View File

@ -0,0 +1,21 @@
! Copyright (C) 2020 John Benediktsson
! See http://factorcode.org/license.txt for BSD license
USING: assocs assocs.extras assocs.private fry grouping kernel
math.extras random sequences ;
IN: markov-chains
: transitions ( string -- clumps )
{ t } { f } surround 2 clump ;
: push-transitions ( table seq -- table )
transitions over [
[ drop H{ } clone ] cache inc-at
] with-assoc assoc-each ;
: transition-table ( seq -- table )
H{ } clone swap [ push-transitions ] each ;
: markov-chain ( table -- seq )
t swap '[ _ at weighted-random dup ] [ dup ] produce nip ;

View File

@ -0,0 +1 @@
Markov chain processes.