Skip to content

Commit

Permalink
RL experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
a-mhamdi committed Jul 3, 2024
1 parent eb05e1a commit 7fefa0f
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions Codes/Julia/Part-3/reinforcement-learning.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
############################
#= REINFORCEMENT LEARNING =#
############################

using ReinforcementLearning
using Flux: Descent

## Define the environment
env = RandomWalk1D()

## Instantiate the agent
agent = Agent(
policy = QBasedPolicy(
learner = TDLearner(
approximator = TabularQApproximator(
n_state = 11,
n_action = 2,
init = 0.0,
opt = Descent(0.1) # Learning rate
),
method = :SARSA,
γ = 0.99
),
explorer = EpsilonGreedyExplorer(0.1),
),
trajectory = VectorSARTTrajectory(),
)

## Run the experiment
hook = TotalRewardPerEpisode()
run(agent, env, StopAfterEpisode(10_000), hook)

## Print rewards
println("Total reward per episode:")
println(hook.rewards)

## Print `Q-table``
q_table = agent.policy.learner.approximator.table
println("\nLearned Q-table:")
println(q_table)

0 comments on commit 7fefa0f

Please sign in to comment.