SELAB3 Python Code
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
rl.deep_q_learning.DeepQLearner Class Reference

The Deep Q learner class. More...

Public Member Functions

None __init__ (self, str env_path, str urdf_path=None, str urdf=None, bool use_graphics=False, str network_path="")
 The DeepQLearner class initializer. More...
 
def handler (self, *_)
 Handler for saving the Deep Q-network upon interrupting the execution of the program.
 
None save (self, str path="./src/rl/networks/most_recently_saved_network.pkl")
 Save the trained network in a pickle file. More...
 
np.ndarray get_action_space (self, number_of_joints)
 Get all possible actions given the amount of joints. More...
 
Tuple[int, np.ndarray, Tuple] get_random_wall (self)
 Get one of the possible walls at random. More...
 
DQN make_dqn (self, network_path="")
 Create an instance of the DQN. More...
 
Tuple[int, np.ndarray] step (self, np.ndarray state)
 Move 1 step forward in the simulation. More...
 
float learn (self, int number_of_episodes=10000, int steps_per_episode=1000, bool logging=False)
 The training or testing loop (depending on variable 'training') of the deep q-learning. More...
 
int predict (self, np.ndarray state)
 Pick the best or a random action depending on epsilon value of the Deep-Q Network. More...
 

Public Attributes

 goal_ball_diameter
 
 use_walls
 
 env
 
 x_range
 
 y_range
 
 z_range
 
 actions
 
 dqn
 
 training
 
 logger
 
 walls
 
 wall_centers
 
 current_wall_index
 

Static Public Attributes

int STATE_SIZE = 6
 
int WALL_STATE_SIZE = 9
 

Detailed Description

The Deep Q learner class.

Defines the class that will learn based on a Deep-Q Network.

Constructor & Destructor Documentation

◆ __init__()

None rl.deep_q_learning.DeepQLearner.__init__ (   self,
str  env_path,
str   urdf_path = None,
str   urdf = None,
bool   use_graphics = False,
str   network_path = "" 
)

The DeepQLearner class initializer.

Parameters
env_pathPath of the environment executable.
urdf_pathPath to the robot urdf file.
urdfInstance that represents the robot urdf.
use_graphicsBoolean that turns graphics on or off.
network_pathPath to the Deep-Q network that should be used.
Returns
An instance of the DeepQLearner class.

Member Function Documentation

◆ get_action_space()

np.ndarray rl.deep_q_learning.DeepQLearner.get_action_space (   self,
  number_of_joints 
)

Get all possible actions given the amount of joints.

Parameters
number_of_jointsThe amount of joints the robot arm has. A complex module has 2 joints, rotating and tilting.
Returns
A list of the actions

◆ get_random_wall()

Tuple[int, np.ndarray, Tuple] rl.deep_q_learning.DeepQLearner.get_random_wall (   self)

Get one of the possible walls at random.

Returns
A wall.

◆ learn()

float rl.deep_q_learning.DeepQLearner.learn (   self,
int   number_of_episodes = 10000,
int   steps_per_episode = 1000,
bool   logging = False 
)

The training or testing loop (depending on variable 'training') of the deep q-learning.

Parameters
number_of_episodesMaximum amount of episodes.
steps_per_episodeMaximum amount of steps each episode.
loggingIf true there will be wandb logs
Returns
Success rate throughout training.

◆ make_dqn()

DQN rl.deep_q_learning.DeepQLearner.make_dqn (   self,
  network_path = "" 
)

Create an instance of the DQN.

Parameters
network_pathPath to network, if the goal is testing, not training.
Returns
A DQN instance.

◆ predict()

int rl.deep_q_learning.DeepQLearner.predict (   self,
np.ndarray  state 
)

Pick the best or a random action depending on epsilon value of the Deep-Q Network.

Parameters
stateCurrent state of the environment.
Returns
The chosen action.

◆ save()

None rl.deep_q_learning.DeepQLearner.save (   self,
str   path = "./src/rl/networks/most_recently_saved_network.pkl" 
)

Save the trained network in a pickle file.

Parameters
pathPath to file where the network will be saved.

◆ step()

Tuple[int, np.ndarray] rl.deep_q_learning.DeepQLearner.step (   self,
np.ndarray  state 
)

Move 1 step forward in the simulation.

Parameters
stateCurrent state of the environment.
Returns
The action that was taken and the observations that were made.

The documentation for this class was generated from the following file: