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:

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)


def self.new #

Creates a new empty TransitionMatrix.


Instance Method Detail

def add(link : LinkType) #

Adds item to TransitionMatrix


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


def sum : Int32 #

Returns sum of all values (occurrences) in the matrix