SARSA¶

Figure: SARSA algorithm pseudocode 1
toyrl.sarsa.default_config
module-attribute
¶
default_config = SarsaConfig(env_name='CartPole-v1', render_mode=None, solved_threshold=475.0, max_training_steps=2000000, learning_rate=0.01, log_wandb=True)
toyrl.sarsa.SarsaConfig
dataclass
¶
SarsaConfig(env_name: str = 'CartPole-v1', render_mode: str | None = None, solved_threshold: float = 475.0, gamma: float = 0.999, max_training_steps: int = 500000, learning_rate: float = 0.00025, log_wandb: bool = False)
Configuration for SARSA algorithm.
max_training_steps
class-attribute
instance-attribute
¶
max_training_steps: int = 500000
The maximum number of environment steps to train for.
learning_rate
class-attribute
instance-attribute
¶
learning_rate: float = 0.00025
The learning rate for the optimizer.
log_wandb
class-attribute
instance-attribute
¶
log_wandb: bool = False
Whether to log the training process to Weights and Biases.
toyrl.sarsa.PolicyNet
¶
PolicyNet(env_dim: int, action_num: int)
Bases: Module
Source code in toyrl/sarsa.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |
forward
¶
forward(x: Tensor) -> Tensor
Source code in toyrl/sarsa.py
50 51 | |
toyrl.sarsa.Experience
dataclass
¶
Experience(terminated: bool, truncated: bool, observation: Any, action: Any, reward: float, next_observation: Any = None, next_action: Any = None)
toyrl.sarsa.ReplayBuffer
dataclass
¶
ReplayBuffer(buffer: list[Experience] = list())
__len__
¶
__len__() -> int
Source code in toyrl/sarsa.py
69 70 | |
add_experience
¶
add_experience(experience: Experience) -> None
Source code in toyrl/sarsa.py
72 73 | |
reset
¶
reset() -> None
Source code in toyrl/sarsa.py
75 76 | |
sample
¶
sample(with_next_sa: bool = True) -> list[Experience]
Source code in toyrl/sarsa.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |
toyrl.sarsa.Agent
¶
Agent(policy_net: PolicyNet, optimizer: Optimizer)
Source code in toyrl/sarsa.py
101 102 103 104 105 | |
onpolicy_reset
¶
onpolicy_reset() -> None
Source code in toyrl/sarsa.py
107 108 | |
add_experience
¶
add_experience(experience: Experience) -> None
Source code in toyrl/sarsa.py
110 111 | |
act
¶
act(observation: floating, epsilon: float) -> int
Source code in toyrl/sarsa.py
113 114 115 116 117 118 119 120 121 | |
policy_update
¶
policy_update(gamma: float) -> float
Source code in toyrl/sarsa.py
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 | |
toyrl.sarsa.SarsaTrainer
¶
SarsaTrainer(config: SarsaConfig)
Source code in toyrl/sarsa.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
train
¶
train() -> None
Source code in toyrl/sarsa.py
180 181 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 | |
-
L. Graesser and W. L. Keng, Foundations of deep reinforcement learning: Theory and practice in python. Addison-Wesley Professional, 2019. ↩