finite_mdp 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/finite_mdp/hash_model.rb +5 -5
- data/lib/finite_mdp/version.rb +2 -2
- data/test/finite_mdp/finite_mdp_test.rb +14 -18
- metadata +33 -38
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4dea8cd1de91ae04618cf3d04df9f84f9c3e1818
|
4
|
+
data.tar.gz: 09309d55f5d88bebf5d1a2c989f4ff403a7c5b75
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f4bbba688034130bc37f7192c4a4073b246886b9e43398fa2a5f3bd85407d271b67579babd9573fbe97fcd452912765405bce2fc3a7d26760d7b3e69154dace3
|
7
|
+
data.tar.gz: 2745aa18e046181cd8f45f1cb956007be71a6dc02f3aee7a977d3607d9ae977cc7d75cbb5177b0c2e1bb330edd519c6fd59f69278cbcb6f1a300c9ebfb7a4332
|
@@ -51,7 +51,7 @@ class FiniteMDP::HashModel
|
|
51
51
|
#
|
52
52
|
# Possible successor states after taking the given action in the given state;
|
53
53
|
# see {Model#next_states}.
|
54
|
-
#
|
54
|
+
#
|
55
55
|
# @param [state] state
|
56
56
|
#
|
57
57
|
# @param [action] action
|
@@ -60,7 +60,7 @@ class FiniteMDP::HashModel
|
|
60
60
|
#
|
61
61
|
def next_states state, action
|
62
62
|
hash[state][action].keys
|
63
|
-
end
|
63
|
+
end
|
64
64
|
|
65
65
|
#
|
66
66
|
# Probability of the given transition; see {Model#transition_probability}.
|
@@ -72,9 +72,9 @@ class FiniteMDP::HashModel
|
|
72
72
|
# @param [state] next_state
|
73
73
|
#
|
74
74
|
# @return [Float] in [0, 1]; zero if the transition is not in the hash
|
75
|
-
#
|
75
|
+
#
|
76
76
|
def transition_probability state, action, next_state
|
77
|
-
probability,
|
77
|
+
probability, _reward = hash[state][action][next_state]
|
78
78
|
probability || 0
|
79
79
|
end
|
80
80
|
|
@@ -90,7 +90,7 @@ class FiniteMDP::HashModel
|
|
90
90
|
# @return [Float, nil] nil if the transition is not in the hash
|
91
91
|
#
|
92
92
|
def reward state, action, next_state
|
93
|
-
|
93
|
+
_probability, reward = hash[state][action][next_state]
|
94
94
|
reward
|
95
95
|
end
|
96
96
|
|
data/lib/finite_mdp/version.rb
CHANGED
@@ -1,12 +1,8 @@
|
|
1
|
-
|
2
|
-
#require 'simplecov'
|
3
|
-
#SimpleCov.start
|
4
|
-
|
5
|
-
require 'test/unit'
|
1
|
+
require 'minitest/autorun'
|
6
2
|
require 'finite_mdp'
|
7
3
|
require 'set'
|
8
4
|
|
9
|
-
class TestFiniteMDP < Test
|
5
|
+
class TestFiniteMDP < MiniTest::Test
|
10
6
|
include FiniteMDP
|
11
7
|
|
12
8
|
def assert_close expected, actual, tol=1e-6
|
@@ -176,10 +172,10 @@ class TestFiniteMDP < Test::Unit::TestCase
|
|
176
172
|
|
177
173
|
# can move north, east, south or west on the grid
|
178
174
|
MOVES = {
|
179
|
-
'^' => [-1, 0],
|
180
|
-
'>' => [ 0, 1],
|
181
|
-
'v' => [ 1, 0],
|
182
|
-
'<' => [ 0, -1]}
|
175
|
+
'^' => [-1, 0],
|
176
|
+
'>' => [ 0, 1],
|
177
|
+
'v' => [ 1, 0],
|
178
|
+
'<' => [ 0, -1]}
|
183
179
|
|
184
180
|
# agent can move north, south, east or west (unless it's in the :stop
|
185
181
|
# state); if it tries to move off the grid or into an obstacle, it stays
|
@@ -277,7 +273,7 @@ class TestFiniteMDP < Test::Unit::TestCase
|
|
277
273
|
# check policy against Figure 17.2(a)
|
278
274
|
solver = check_grid_solutions model,
|
279
275
|
["> > > ",
|
280
|
-
"^ ^ ",
|
276
|
+
"^ ^ ",
|
281
277
|
"^ < < <"]
|
282
278
|
|
283
279
|
# check the actual (non-pretty) policy
|
@@ -305,9 +301,9 @@ class TestFiniteMDP < Test::Unit::TestCase
|
|
305
301
|
model.check_transition_probabilities_sum
|
306
302
|
assert_equal Set[], model.terminal_states # no actual terminals
|
307
303
|
|
308
|
-
check_grid_solutions model,
|
304
|
+
check_grid_solutions model,
|
309
305
|
["> > > ",
|
310
|
-
"^ > ",
|
306
|
+
"^ > ",
|
311
307
|
"> > > ^"]
|
312
308
|
end
|
313
309
|
|
@@ -322,9 +318,9 @@ class TestFiniteMDP < Test::Unit::TestCase
|
|
322
318
|
model.check_transition_probabilities_sum
|
323
319
|
assert_equal Set[], model.terminal_states # no actual terminals
|
324
320
|
|
325
|
-
check_grid_solutions model,
|
321
|
+
check_grid_solutions model,
|
326
322
|
["> > > ",
|
327
|
-
"^ ^ ",
|
323
|
+
"^ ^ ",
|
328
324
|
"^ > ^ <"]
|
329
325
|
end
|
330
326
|
|
@@ -339,13 +335,13 @@ class TestFiniteMDP < Test::Unit::TestCase
|
|
339
335
|
model.check_transition_probabilities_sum
|
340
336
|
assert_equal Set[], model.terminal_states # no actual terminals
|
341
337
|
|
342
|
-
check_grid_solutions model,
|
338
|
+
check_grid_solutions model,
|
343
339
|
["> > > ",
|
344
|
-
"^ < ",
|
340
|
+
"^ < ",
|
345
341
|
"^ < < v"]
|
346
342
|
end
|
347
343
|
|
348
|
-
class MyPoint
|
344
|
+
class MyPoint
|
349
345
|
include FiniteMDP::VectorValued
|
350
346
|
|
351
347
|
def initialize x, y
|
metadata
CHANGED
@@ -1,45 +1,48 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: finite_mdp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- John Lees-Miller
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2016-08-05 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: narray
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- - ~>
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.
|
19
|
+
version: '0.6'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.6'
|
25
27
|
- !ruby/object:Gem::Dependency
|
26
28
|
name: gemma
|
27
|
-
requirement:
|
28
|
-
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
|
-
- -
|
31
|
+
- - ">"
|
31
32
|
- !ruby/object:Gem::Version
|
32
|
-
version: 2
|
33
|
+
version: '2'
|
33
34
|
type: :development
|
34
35
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
-
|
37
|
-
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2'
|
41
|
+
description: |-
|
42
|
+
This library provides several ways of describing a
|
38
43
|
finite Markov Decision Process (MDP) model (see FiniteMDP::Model) and some
|
39
|
-
|
40
44
|
reasonably efficient implementations of policy iteration and value iteration to
|
41
|
-
|
42
|
-
solve it (see FiniteMDP::Solver).'
|
45
|
+
solve it (see FiniteMDP::Solver).
|
43
46
|
email:
|
44
47
|
- jdleesmiller@gmail.com
|
45
48
|
executables: []
|
@@ -47,49 +50,41 @@ extensions: []
|
|
47
50
|
extra_rdoc_files:
|
48
51
|
- README.rdoc
|
49
52
|
files:
|
53
|
+
- README.rdoc
|
50
54
|
- lib/finite_mdp.rb
|
51
|
-
- lib/finite_mdp/solver.rb
|
52
|
-
- lib/finite_mdp/version.rb
|
53
|
-
- lib/finite_mdp/table_model.rb
|
54
55
|
- lib/finite_mdp/hash_model.rb
|
55
56
|
- lib/finite_mdp/model.rb
|
57
|
+
- lib/finite_mdp/solver.rb
|
58
|
+
- lib/finite_mdp/table_model.rb
|
56
59
|
- lib/finite_mdp/vector_valued.rb
|
57
|
-
-
|
60
|
+
- lib/finite_mdp/version.rb
|
58
61
|
- test/finite_mdp/finite_mdp_test.rb
|
59
62
|
homepage: http://github.com/jdleesmiller/finite_mdp
|
60
63
|
licenses: []
|
64
|
+
metadata: {}
|
61
65
|
post_install_message:
|
62
66
|
rdoc_options:
|
63
|
-
- --main
|
67
|
+
- "--main"
|
64
68
|
- README.rdoc
|
65
|
-
- --title
|
66
|
-
- finite_mdp-0.
|
69
|
+
- "--title"
|
70
|
+
- finite_mdp-0.2.0 Documentation
|
67
71
|
require_paths:
|
68
72
|
- lib
|
69
73
|
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
-
none: false
|
71
74
|
requirements:
|
72
|
-
- -
|
75
|
+
- - ">="
|
73
76
|
- !ruby/object:Gem::Version
|
74
77
|
version: '0'
|
75
|
-
segments:
|
76
|
-
- 0
|
77
|
-
hash: -310962355
|
78
78
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
-
none: false
|
80
79
|
requirements:
|
81
|
-
- -
|
80
|
+
- - ">="
|
82
81
|
- !ruby/object:Gem::Version
|
83
82
|
version: '0'
|
84
|
-
segments:
|
85
|
-
- 0
|
86
|
-
hash: -310962355
|
87
83
|
requirements: []
|
88
84
|
rubyforge_project: finite_mdp
|
89
|
-
rubygems_version:
|
85
|
+
rubygems_version: 2.4.5.1
|
90
86
|
signing_key:
|
91
|
-
specification_version:
|
87
|
+
specification_version: 4
|
92
88
|
summary: Solve small, finite Markov Decision Process models.
|
93
89
|
test_files:
|
94
90
|
- test/finite_mdp/finite_mdp_test.rb
|
95
|
-
has_rdoc:
|