| Copyright | (c) Eric Bailey 2025 |
|---|---|
| License | MIT |
| Maintainer | eric@ericb.me |
| Stability | stable |
| Portability | POSIX |
| Safe Haskell | Safe-Inferred |
| Language | GHC2021 |
Data.Rhythm.Markov
Description
Generating random numbers using a Markov chain.
Synopsis
- newtype TransitionMatrix (n :: Nat) = TransitionMatrix {
- unTransitionMatrix :: Vector n (Vector n Double)
- data SomeTransitionMatrix where
- SomeTransitionMatrix :: KnownNat n => TransitionMatrix n -> SomeTransitionMatrix
- markovGen :: (MonadIO m, MonadFail m) => SomeTransitionMatrix -> Integer -> Integer -> m [Integer]
- markovGen' :: forall n steps m. (KnownNat n, KnownNat steps, MonadIO m, MonadFail m) => TransitionMatrix n -> Finite n -> m (Vector steps (Finite n))
- someTransitionMatrix :: Parser SomeTransitionMatrix
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} \]
Constructors
| TransitionMatrix | |
Fields
| |
Instances
data SomeTransitionMatrix where Source #
Existential wrapper around a square TransitionMatrix of unknown size.
Constructors
| SomeTransitionMatrix :: KnownNat n => TransitionMatrix n -> SomeTransitionMatrix |
Instances
| IsList SomeTransitionMatrix Source # | |
Defined in Data.Rhythm.Markov Associated Types type Item SomeTransitionMatrix # Methods fromList :: [Item SomeTransitionMatrix] -> SomeTransitionMatrix # fromListN :: Int -> [Item SomeTransitionMatrix] -> SomeTransitionMatrix # toList :: SomeTransitionMatrix -> [Item SomeTransitionMatrix] # | |
| Show SomeTransitionMatrix Source # | |
Defined in Data.Rhythm.Markov Methods showsPrec :: Int -> SomeTransitionMatrix -> ShowS # show :: SomeTransitionMatrix -> String # showList :: [SomeTransitionMatrix] -> ShowS # | |
| type Item SomeTransitionMatrix Source # | |
Defined in Data.Rhythm.Markov | |
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 <$> numbersTrue>>>all (inRange (0,2)) <$> numbersTrue
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 #
See markovGen.
someTransitionMatrix :: Parser SomeTransitionMatrix Source #
Parse a square TransitionMatrix of unknown size.