-
Notifications
You must be signed in to change notification settings - Fork 7
/
example.js
36 lines (30 loc) · 856 Bytes
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const Chain = require('markov-chains').default;
// our states (an array of arrays)
const states = [
// week 1
[
{ temp: 'hot', weather: 'sunny' },
{ temp: 'hot', weather: 'cloudy' },
{ temp: 'warm', weather: 'cloudy' },
{ temp: 'warm', weather: 'cloudy' },
{ temp: 'warm', weather: 'rainy' },
{ temp: 'cool', weather: 'cloudy' },
{ temp: 'warm', weather: 'sunny' },
],
// week 2
[
{ temp: 'warm', weather: 'sunny' },
{ temp: 'warm', weather: 'cloudy' },
{ temp: 'warm', weather: 'cloudy' },
{ temp: 'warm', weather: 'sunny' },
{ temp: 'hot', weather: 'sunny' },
{ temp: 'hot', weather: 'sunny' },
{ temp: 'warm', weather: 'sunny' },
],
// etc.
];
// build the chain
const chain = new Chain(states);
// generate a forecast
const forecast = chain.walk();
console.log(forecast);