Skip to content

Commit fd66aff

Browse files
committed
Improve DQN
1 parent 2de7e87 commit fd66aff

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

js/view/dqn.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,18 @@ var dispDQN = function (elm, env) {
6565
return
6666
}
6767
const greedy_rate = +elm.select('[name=greedy_rate]').property('value')
68+
const min_greedy_rate = +elm.select('[name=min_greedy_rate]').property('value')
69+
const greedy_rate_update = +elm.select('[name=greedy_rate_update]').property('value')
6870
const learning_rate = +elm.select('[name=learning_rate]').property('value')
6971
const batch = +elm.select('[name=batch]').property('value')
70-
agent.get_action(env, cur_state, greedy_rate, action => {
72+
agent.get_action(env, cur_state, Math.max(min_greedy_rate, greedy_rate * greedy_rate_update), action => {
7173
let [next_state, reward, done] = env.step(action, agent)
7274
agent.update(action, cur_state, next_state, reward, done, learning_rate, batch, () => {
7375
const end_proc = () => {
7476
cur_state = next_state
77+
if (done || env.epoch % 1000 === 999) {
78+
elm.select('[name=greedy_rate]').property('value', greedy_rate * greedy_rate_update)
79+
}
7580
cb && cb(done)
7681
}
7782
if (render) {
@@ -113,6 +118,7 @@ var dispDQN = function (elm, env) {
113118
readyNet = true
114119
reset()
115120
})
121+
elm.select('[name=greedy_rate]').property('value', 1)
116122
})
117123
elm.append('input').attr('type', 'button').attr('value', 'Reset').on('click', reset)
118124
elm.append('select')
@@ -127,13 +133,31 @@ var dispDQN = function (elm, env) {
127133
.append('option')
128134
.property('value', d => d)
129135
.text(d => d)
136+
elm.append('span').text('greedy rate = max(')
137+
elm.append('input')
138+
.attr('type', 'number')
139+
.attr('name', 'min_greedy_rate')
140+
.attr('min', 0)
141+
.attr('max', 1)
142+
.attr('step', '0.01')
143+
.attr('value', 0.01)
144+
elm.append('span').text(', ')
130145
elm.append('input')
131146
.attr('type', 'number')
132147
.attr('name', 'greedy_rate')
133148
.attr('min', 0)
134149
.attr('max', 1)
135150
.attr('step', '0.01')
136-
.attr('value', 0.3)
151+
.attr('value', 1)
152+
elm.append('span').text(' * ')
153+
elm.append('input')
154+
.attr('type', 'number')
155+
.attr('name', 'greedy_rate_update')
156+
.attr('min', 0)
157+
.attr('max', 1)
158+
.attr('step', '0.01')
159+
.attr('value', 0.995)
160+
elm.append('span').text(') ')
137161
elm.append('span').text(' Learning rate ')
138162
elm.append('input')
139163
.attr('type', 'number')

lib/model/dqn.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class DQN {
2828

2929
this._memory = []
3030
this._max_memory_size = 100000
31-
this._batch_size = 10
31+
this._batch_size = 1000
3232
this._do_update_step = 10
3333
this._fix_param_update_step = 1000
3434
this._layers = [{ type: 'input' }]

0 commit comments

Comments
 (0)