SLM Lab
Search…
Algorithm

# ​🏗 Algorithm API

Algorithm is the main class which implements an RL algorithm. This includes declaring its networks and variables, acting, sampling from memory, and training. It initializes its networks and memory by simply calling the Memory and Net classes with their specs. The loss functions for the algorithms is also implemented here.
Each algorithm comes with a number of hyperparameters that can be specified through a agent spec file.

# Algorithm Spec

1
{
2
...
3
"agent": [{
4
"name": str,
5
"algorithm": {
6
"name": str,
7
"action_pdtype": str,
8
"action_policy": str,
9
"gamma": float,
10
...,
11
},
12
...
13
}],
14
...
15
}
Copied!
• name: name of an implemented algorithm class. This must be a class that conforms to the algorithm api and is saved in a .py file under slm_lab/agent/algorithm
• action_pdtype: specifies the probability distribution that actions are sampled from. For example, "Argmax" or "Categorical" for discrete action spaces, or "Normal", "MultivariateNormal", and "Gumbel" for continuous action spaces. These are declared in slm_lab/agent/algorithm/policy_util.py#L18-L24
• action_policy: specifies how the agent should act. e.g. "epsilon_greedy". These are declared in slm_lab/agent/algorithm/policy_util.py#L133
• gamma
$\in[0,1]$
how much to discount the future for the returns. 0 corresponds to complete myopia, the agent only cares about the current time step. 1 corresponds to no discounting. Each future state matters as much as the current state.
Other algorithm spec hyperparameters are specific to algorithm implementations. For those, refer to the class documentation of algorithms in slm_lab/agent/algorithm.
For more concrete examples of algorithm spec specific to algorithms, refer to the existing spec files.