Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pymdptoolbox
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Zahra Rajabi
pymdptoolbox
Commits
8757cec0
Commit
8757cec0
authored
Jan 21, 2013
by
Steven Cordwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added class RelativeValueIteration
parent
97b3a813
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
84 additions
and
4 deletions
+84
-4
mdp.py
mdp.py
+84
-4
No files found.
mdp.py
View file @
8757cec0
...
...
@@ -1014,11 +1014,91 @@ class QLearning(MDP):
self
.
iter
=
self
.
max_iter
class
RelativeValueIteration
(
MDP
):
"""Resolution of MDP with average reward with relative value iteration
algorithm.
"""Resolution of MDP with average reward with relative value iteration
algorithm
Arguments
---------
Let S = number of states, A = number of actions
P(SxSxA) = transition matrix
P could be an array with 3 dimensions or
a cell array (1xA), each cell containing a matrix (SxS) possibly sparse
R(SxSxA) or (SxA) = reward matrix
R could be an array with 3 dimensions (SxSxA) or
a cell array (1xA), each cell containing a sparse matrix (SxS) or
a 2D array(SxA) possibly sparse
epsilon = epsilon-optimal policy search, upper than 0,
optional (default: 0.01)
max_iter = maximum number of iteration to be done, upper than 0,
optional (default 1000)
Evaluation
----------
policy(S) = epsilon-optimal policy
average_reward = average reward of the optimal policy
cpu_time = used CPU time
Notes
-----
In verbose mode, at each iteration, displays the span of U variation
and the condition which stopped iterations : epsilon-optimum policy found
or maximum number of iterations reached.
Examples
--------
"""
pass
#raise NotImplementedError("This class has not been implemented yet.")
def
__init__
(
self
,
transitions
,
reward
,
epsilon
=
0.01
,
max_iter
=
1000
):
MDP
.
__init__
(
self
,
transitions
,
reward
,
None
,
max_iter
)
if
epsilon
<=
0
:
print
(
'MDP Toolbox ERROR: epsilon must be upper than 0'
)
if
iscell
(
P
):
S
=
size
(
P
[
1
],
1
)
else
:
S
=
size
(
P
,
1
)
self
.
U
=
zeros
(
S
,
1
)
self
.
gain
=
U
(
S
)
def
iterate
(
self
):
""""""
done
=
False
if
self
.
verbose
:
print
(
' Iteration U_variation'
)
self
.
time
=
time
()
while
not
done
:
self
.
iter
=
self
.
iter
+
1
;
Unext
,
policy
=
self
.
bellmanOperator
(
self
.
P
,
self
.
PR
,
1
,
self
.
U
)
Unext
=
Unext
-
self
.
gain
variation
=
self
.
getSpan
(
Unext
-
self
.
U
)
if
self
.
verbose
:
print
(
" %s %s"
%
(
self
.
iter
,
variation
))
if
variation
<
self
.
epsilon
:
done
=
True
average_reward
=
self
.
gain
+
min
(
Unext
-
self
.
U
)
if
self
.
verbose
:
print
(
'MDP Toolbox : iterations stopped, epsilon-optimal policy found'
)
elif
self
.
iter
==
self
.
max_iter
:
done
=
True
average_reward
=
self
.
gain
+
min
(
Unext
-
self
.
U
);
if
self
.
verbose
:
print
(
'MDP Toolbox : iterations stopped by maximum number of iteration condition'
)
self
.
U
=
Unext
self
.
gain
=
self
.
U
(
self
.
S
)
self
.
time
=
time
()
-
self
.
time
class
ValueIteration
(
MDP
):
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment