-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolicy.py
40 lines (35 loc) · 1.12 KB
/
policy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""
@Description: In This file we implement epsilon greedy policy
@Author : Erfan Fathi
@Date : 25 May 2023
"""
import numpy as np
class EpsilonGreedyPolicy:
"""
Description: This class implements the epsilon greedy policy.
Args:
epsilon : The exploration rate.
q_table : The q-table for the cartpole-v1 environment.
env : The cartpole-v1 environment.
"""
def __init__(self, epsilon, q_table, env):
self.epsilon = epsilon
self.q_table = q_table
self.env = env
def get_action(self, state):
"""
Description: This function returns an action based on the epsilon greedy policy.
Args:
state : The current state.
Returns:
action : The action.
"""
if np.random.rand() < self.epsilon:
action = self.env.action_space.sample()
else:
action = np.argmax(self.q_table[state[0], state[1], state[2], state[3]])
return action
class EpsilonDecayGreedyPolicy:
pass
class UCBPolicy:
pass