Utils
robot_nav.utils
Pretraining
Handles loading of offline experience data and pretraining of a reinforcement learning model.
Attributes:
Name | Type | Description |
---|---|---|
file_names |
List[str]
|
List of YAML files containing pre-recorded environment samples. |
model |
object
|
The model with |
replay_buffer |
object
|
The buffer used to store experiences for training. |
reward_function |
callable
|
Function to compute the reward from the environment state. |
Source code in robot_nav/utils.py
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
|
load_buffer()
Load samples from the specified files and populate the replay buffer.
Returns:
Name | Type | Description |
---|---|---|
object |
The populated replay buffer. |
Source code in robot_nav/utils.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
|
train(pretraining_iterations, replay_buffer, iterations, batch_size)
Run pretraining on the model using the replay buffer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretraining_iterations
|
int
|
Number of outer loop iterations for pretraining. |
required |
replay_buffer
|
object
|
Buffer to sample training batches from. |
required |
iterations
|
int
|
Number of training steps per pretraining iteration. |
required |
batch_size
|
int
|
Batch size used during training. |
required |
Source code in robot_nav/utils.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
|
get_buffer(model, sim, load_saved_buffer, pretrain, pretraining_iterations, training_iterations, batch_size, buffer_size=50000, random_seed=666, file_names=['robot_nav/assets/data.yml'], history_len=10)
Get or construct the replay buffer depending on model type and training configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
object
|
The RL model, can be PPO, RCPG, or other. |
required |
sim
|
object
|
Simulation environment with a |
required |
load_saved_buffer
|
bool
|
Whether to load experiences from file. |
required |
pretrain
|
bool
|
Whether to run pretraining using the buffer. |
required |
pretraining_iterations
|
int
|
Number of outer loop iterations for pretraining. |
required |
training_iterations
|
int
|
Number of iterations in each training loop. |
required |
batch_size
|
int
|
Size of the training batch. |
required |
buffer_size
|
int
|
Maximum size of the buffer. Defaults to 50000. |
50000
|
random_seed
|
int
|
Seed for reproducibility. Defaults to 666. |
666
|
file_names
|
List[str]
|
List of YAML data file paths. Defaults to ["robot_nav/assets/data.yml"]. |
['robot_nav/assets/data.yml']
|
history_len
|
int
|
Used for RCPG buffer configuration. Defaults to 10. |
10
|
Returns:
Name | Type | Description |
---|---|---|
object |
The initialized and optionally pre-populated replay buffer. |
Source code in robot_nav/utils.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
|
get_max_bound(next_state, discount, max_ang_vel, max_lin_vel, time_step, distance_norm, goal_reward, reward, done, device)
Estimate the maximum possible return (upper bound) from the next state onward.
This is used in constrained RL or safe policy optimization where a conservative estimate of return is useful for policy updates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
next_state
|
Tensor
|
Tensor of next state observations. |
required |
discount
|
float
|
Discount factor for future rewards. |
required |
max_ang_vel
|
float
|
Maximum angular velocity of the agent. |
required |
max_lin_vel
|
float
|
Maximum linear velocity of the agent. |
required |
time_step
|
float
|
Duration of one time step. |
required |
distance_norm
|
float
|
Normalization factor for distance. |
required |
goal_reward
|
float
|
Reward received upon reaching the goal. |
required |
reward
|
Tensor
|
Immediate reward from the environment. |
required |
done
|
Tensor
|
Binary tensor indicating episode termination. |
required |
device
|
device
|
PyTorch device for computation. |
required |
Returns:
Type | Description |
---|---|
torch.Tensor: Maximum return bound for each sample in the batch. |
Source code in robot_nav/utils.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
|