class Markov::TransitionMatrix(LinkType)

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.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(pull : JSON::PullParser) #

Makes it possible to use #to_json and #from_json (see Crystal docs)


[View source]
def self.new #

Creates a new empty TransitionMatrix.


[View source]

Instance Method Detail

def add(link : LinkType) #

Adds item to TransitionMatrix


[View source]
def probabilities : Hash(LinkType, Float32) #

Returns decimal probability of each transition in the matrix


[View source]
def probable_transition : LinkType #

Chooses a random, probable transition from the transitions in the matrix. If matrix is empty, will throw Markov::Exceptions::EmptyTransitionMatrixException


[View source]
def sum : Int32 #

Returns sum of all values (occurrences) in the matrix


[View source]