CreatingRhythms-1.8.0.7
Copyright(c) Eric Bailey 2025
LicenseMIT
Maintainereric@ericb.me
Stabilitystable
PortabilityPOSIX
Safe HaskellSafe-Inferred
LanguageGHC2021

Data.Rhythm.Markov

Description

Generating random numbers using a Markov chain.

Synopsis

Documentation

newtype TransitionMatrix (n :: Nat) Source #

An \(n \times n\) transition matrix.

For example, the following is a TransitionMatrix 3.

\[ \begin{bmatrix} 0.1 & 0.6 & 0.3 \\ 0.4 & 0.4 & 0.2 \\ 0.3 & 0.3 & 0.4 \end{bmatrix} \]

Instances

Instances details
Generic (TransitionMatrix n) Source # 
Instance details

Defined in Data.Rhythm.Markov

Associated Types

type Rep (TransitionMatrix n) :: Type -> Type #

Show (TransitionMatrix n) Source # 
Instance details

Defined in Data.Rhythm.Markov

Eq (TransitionMatrix n) Source # 
Instance details

Defined in Data.Rhythm.Markov

type Rep (TransitionMatrix n) Source # 
Instance details

Defined in Data.Rhythm.Markov

type Rep (TransitionMatrix n) = D1 ('MetaData "TransitionMatrix" "Data.Rhythm.Markov" "CreatingRhythms-1.8.0.7-DGB2JNDHfptLnJAgYi7IVp" 'True) (C1 ('MetaCons "TransitionMatrix" 'PrefixI 'True) (S1 ('MetaSel ('Just "unTransitionMatrix") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Vector n (Vector n Double)))))

markovGen :: (MonadIO m, MonadFail m) => SomeTransitionMatrix -> Integer -> Integer -> m [Integer] Source #

Generate random numbers using a Markov chain.

>>> let matrix = fromList [[0.1,0.6,0.3],[0.4,0.4,0.2],[0.3,0.3,0.4]]
>>> let numbers = markovGen matrix 1 10
>>> (== 10) . length <$> numbers
True
>>> all (inRange (0,2)) <$> numbers
True

See markovGen'.

markovGen' :: forall n steps m. (KnownNat n, KnownNat steps, MonadIO m, MonadFail m) => TransitionMatrix n -> Finite n -> m (Vector steps (Finite n)) Source #