Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions examples/CartPole/DQN.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using Flux, Gym
using Flux.Optimise: Optimiser
using Flux.Tracker: data
using Statistics: mean
using DataStructures: CircularBuffer
using Distributions: sample
using Printf
#using CuArrays
using StatsBase

# Load game environment
env = make("CartPole-v0", :human_pane)
Expand Down Expand Up @@ -48,15 +47,15 @@ remember(state, action, reward, next_state, done) =
push!(memory, (data(state), action, reward, data(next_state), done))

function action(state, train=true)
train && rand() <= get_ϵ(e) && (return Gym.sample(env.action_space))
train && rand() <= get_ϵ(e) && (return Gym.sample(env._env.action_space))
act_values = model(state |> gpu)
return Flux.onecold(act_values)
end

function replay()
global ϵ
batch_size = min(BATCH_SIZE, length(memory))
minibatch = sample(memory, batch_size, replace = false)
minibatch = StatsBase.sample(memory, batch_size, replace = false)

x = []
y = []
Expand Down