class Markov::TransitionMatrix(LinkType)
- Markov::TransitionMatrix(LinkType)
- Hash(LinkType, Int32)
- Reference
- Object
Overview
A TransitionMatrix
is an object for storing and selecting transitions in a Markov::Chain
.
See https://en.wikipedia.org/wiki/Stochastic_matrix
Defined in:
markov/TransitionMatrix.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(link : LinkType)
Adds item to
TransitionMatrix
-
#probabilities : Hash(LinkType, Float32)
Returns decimal probability of each transition in the matrix
-
#probable_transition : LinkType
Chooses a random, probable transition from the transitions in the matrix.
-
#sum : Int32
Returns sum of all values (occurrences) in the matrix
Constructor Detail
def self.new(pull : JSON::PullParser)
#
Makes it possible to use #to_json
and #from_json
(see Crystal docs)
Instance Method Detail
def probabilities : Hash(LinkType, Float32)
#
Returns decimal probability of each transition in the matrix
def probable_transition : LinkType
#
Chooses a random, probable transition from the transitions in the matrix.
If matrix is empty, will throw Markov::Exceptions::EmptyTransitionMatrixException