npm.io
1.0.2 • Published 4 years ago

state-markov

Licence
MIT
Version
1.0.2
Deps
0
Size
10 kB
Vulns
0
Weekly
0
Stars
1

Gif taken from Markov chains explained visually, by Victor Powell

state-markov

a simple state machine that transitions to a new state based on weights

example

import { StateMarkov } from "state-markov";

const spec = {
  one: {
    one: 0.1,
    two: 0.6,
    three: 0.3,
  },
  two: {
    one: 0.5,
    three: 0.5,
  },
  three: {
    one: 1,
  },
};

const sm = new StateMarkov(spec);

for (let i = 0; i < 10; i++) {
  console.log(sm.currentState.name); //=> one, three, one, two, three, one, one, three, one, two
  sm.transition();
}