class Markov::TransitionTable(LinkType)
- Markov::TransitionTable(LinkType)
- Hash(LinkType, Markov::TransitionMatrix(LinkType))
- Reference
- Object
Overview
A TransitionTable
represents a mapping of keys to TransitionMatrix
's.
Defined in:
markov/TransitionTable.crConstructors
-
.new(pull : JSON::PullParser)
Makes it possible to use
#to_json
and#from_json
(see Crystal docs) -
.new
Creates a new empty
TransitionMatrix
.
Instance Method Summary
-
#add(key : LinkType)
Inserts
key
into last addedkey
'sTransitionMatrix
, if applicable, and creates newTransitionMatrix
forkey
if not already there. -
#fill(table_with sample : Array(LinkType))
Sequentially fills
TransitionTable
with values in givenArray
using#add
method. -
#probable(after key : LinkType) : LinkType
Returns probable transition from the
TransitionMatrix
associated with key provided. -
#probable?(after key : LinkType) : LinkType | Nil
Returns probable transition from the
TransitionMatrix
associated with key provided. -
#random_key : LinkType
Returns random key.
-
#random_matrix : TransitionMatrix(LinkType)
Returns random
TransitionMatrix
from table. -
#reset
Resets the
TransitionTable
's last added key between non-sequential sets of training data.
Constructor Detail
Makes it possible to use #to_json
and #from_json
(see Crystal docs)
Instance Method Detail
Inserts key
into last added key
's TransitionMatrix
, if applicable,
and creates new TransitionMatrix
for key
if not already there.
Sequentially fills TransitionTable
with values in given Array
using #add
method.
Just a shortcut for looping through array and #add
ing elements.
string_array = %w(some say the world will end in fire)
tt = Markov::TransitionTable(String).new
tt.fill table_with: string_array
Returns probable transition from the TransitionMatrix
associated with key provided.
Will raise EmptyTransitionMatrixException
if no probable transition is available.
string_array = %w(some say the world will end in fire)
tt = Markov::TransitionTable(String).new
tt.fill table_with: string_array
tt.probable? after: "world" #=> "will"
tt.probable? after: "fire" # raises `EmptyTransitionMatrixException`
Returns probable transition from the TransitionMatrix
associated with key provided.
Returns nil
if no probable transition is available.
string_array = %w(some say the world will end in fire)
tt = Markov::TransitionTable(String).new
tt.fill table_with: string_array
tt.probable? after: "world" #=> "will"
tt.probable? after: "fire" #=> nil
Returns random key.
Will raise EmptyTransitionTableException
if TransitionTable
is empty.
Resets the TransitionTable
's last added key between non-sequential sets of training data.
movie_one = %w(the great gatsby)
movie_two = %w(great expectations)
tt = Markov::TransitionTable(String).new
tt.fill table_with: movie_one
tt.reset()
tt.fill table_with: movie_two
tt.probable? after: "gatsby" #=> nil
tt.probable? after: "great" #=> "expectations" or "gatsby"