-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmarkov
92 lines (92 loc) · 1.54 KB
/
cmarkov
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
%%HP: T(1)A(R)F(.);
DIR
AID
"Utilities for continuous Markov Chains
Dih5
*****
Magnitudes:
Q: Infinitesimal matrix
J: Jump matrix
Jb: Modified jump matrix with 0 row in absorbing state.
Xj: j-th column of X
*****
Functions included:
X2Y: Function transforming X to Y
STATIO: Find a base of stationary distributions from Q
PROF: Find the profit given a Q matrix and a LIST of profit per time in a state
PROFV: Find the profit given a Q matrix and a LIST of profit per visit to a state
DIM1: Number of rows in a Matrix"
Q2J
« q
« q DUP DIM1 q
d
« 1 d
FOR k q ROW
LIST k GET DUP k GET
NEG DUP
IF 0 ==
THEN DROP
DIM1 1 SWAP
FOR k2 0
NEXT q
DIM1 ARRY k 1 PUT
ELSE / k 0
PUT
END
NEXT d ROW
»
»
»
STATIO
« TRAN KER 1
« DUP OBJ 1 GET
LIST …LIST EXPAND /
» DOLIST
»
PROFV
« q fi
« q DIM1 IDN q
Q2Jb - fi OBJ ARRY
» SWAP /
»
PROF
« q fi
« q DIM1 IDN q
Q2Jb - q DIAG OBJ 1
GET LIST fi 2
« DUP
IF 0 ==
THEN DROP
DROP 0
ELSE SWAP NEG
/
END
» DOLIST OBJ
ARRY SWAP /
»
»
Q2Jb
« q
« q DUP DIM1 q
d
« 1 d
FOR k q ROW
LIST k GET DUP k GET
NEG DUP
IF 0 ==
THEN DROP
DIM1 1 SWAP
FOR k2 0
NEXT q
DIM1 ARRY
ELSE / k 0
PUT
END
NEXT d ROW
»
»
»
DIM1
« SIZE 1 GET Q
»
END