-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmarkov.js
More file actions
44 lines (37 loc) · 1.07 KB
/
Copy pathmarkov.js
File metadata and controls
44 lines (37 loc) · 1.07 KB
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
37
38
39
40
41
42
43
44
var Chain = require('markov-chains').default;
// our states (an array of arrays)
var 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: 'cloudy' },
{ temp: 'warm', weather: 'cloudy' },
],
// etc.
];
// build the chain
var chain = new Chain(states);
// generate a forecast
var forecast = chain.walk();
console.log(forecast);
// Example output:
//
// [ { temp: 'warm', weather: 'sunny' },
// { temp: 'warm', weather: 'cloudy' },
// { temp: 'warm', weather: 'rainy' },
// { temp: 'cool', weather: 'cloudy' },
// { temp: 'warm', weather: 'sunny' } ]