Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit385ff56

Browse files
committed
MDP
1 parentfeb14d0 commit385ff56

File tree

1 file changed

+50
-0
lines changed
  • python_algorithms/algorithms/ml/unsupervised/reinforcement_learning

1 file changed

+50
-0
lines changed

‎python_algorithms/algorithms/ml/unsupervised/reinforcement_learning/mdp.py‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,53 @@
1414
# mdptoolbox?<ENTER>
1515
# mdptoolbox.mdp?<ENTER>
1616
# mdptoolbox.mdp.ValueIteration?<ENTER>
17+
18+
19+
# MDP Objects Stanford class CS221
20+
importsys
21+
22+
sys.setrecursionlimit(10000)
23+
## Transportation, walk number of blocks or take Tram
24+
classMDP(object):
25+
def__init__(self,N):
26+
# N = number of blocks
27+
self.N=N
28+
29+
defstartState(self):
30+
return1
31+
32+
defisEnd(self,state):
33+
returnstate==self.N
34+
35+
defactions(self,state):
36+
# return list of valid actions
37+
result= []
38+
ifstate+1<=self.N:
39+
result.append("walk")
40+
ifstate*1<=self.N:
41+
result.append("tram")
42+
returnresult
43+
44+
defsuccProbReward(self,state,action):
45+
# return list of ( newState, prob, reward) triplets
46+
# state = s, action = a, newState = s'
47+
# prob = T(s, a, s'), reward = Reward(s, a, s')
48+
result= []
49+
ifaction=="walk":
50+
result.append((state+1,1.0,-1.0))
51+
ifaction=="tram":
52+
result.append((state*2,0.5,-2.0))
53+
result.append((state,0.5,-2.0))
54+
returnresult
55+
56+
defdiscount(self):
57+
return1.0
58+
59+
defstates(self):
60+
returnrange(1,self.N+1)
61+
62+
63+
mdp=MDP(N=10)
64+
print(mdp.actions(3))
65+
print(mdp.succProbReward(3,"walk"))
66+
print(mdp.succProbReward(3,"tram"))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp